[Pikloops-svn] SF.net SVN: pikloops: [146] prog/trunk/src
Brought to you by:
dionysos-sf
|
From: <dio...@us...> - 2007-10-15 17:24:28
|
Revision: 146
http://pikloops.svn.sourceforge.net/pikloops/?rev=146&view=rev
Author: dionysos-sf
Date: 2007-10-15 10:24:26 -0700 (Mon, 15 Oct 2007)
Log Message:
-----------
- Fix bug in calculation
- Remove CounterD
- New delay management
- Update copyright
Modified Paths:
--------------
prog/trunk/src/mainwidgetpl.cpp
prog/trunk/src/pikdelay.cpp
prog/trunk/src/pikdelay.h
Modified: prog/trunk/src/mainwidgetpl.cpp
===================================================================
--- prog/trunk/src/mainwidgetpl.cpp 2007-10-15 08:16:59 UTC (rev 145)
+++ prog/trunk/src/mainwidgetpl.cpp 2007-10-15 17:24:26 UTC (rev 146)
@@ -1,6 +1,6 @@
/**
- * Copyright (C) 2004 by JAVIER FERNANDO VARGAS G
- * fer...@ca...
+ * Copyright (C) 2004 by JAVIER FERNANDO VARGAS G <fer...@ca...>
+ * 2007 - Alain Portal <aportal AT univ-montp2 DOT fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -102,67 +102,110 @@
routineName += delay->text() ;
routineName += i18n("_sec") ;
QString loopName = routineName + i18n("_loop") ;
+ QString subRoutineName = i18n("sub_delay_") ;
+ subRoutineName += delay->text() ;
+ subRoutineName += i18n("_sec") ;
+ QString loopSubRoutineName = subRoutineName + i18n("_loop") ;
// generate comments
- QString tmpCode(i18n("; Delay code generated by PikLoops (")) ;
+ QString tmpCode = "; " ;
+ tmpCode += i18n("Delay code generated by PikLoops") ;
+ tmpCode += " (" ;
tmpCode += QDateTime::currentDateTime().toString(i18n("ddd yyyy-MMM-dd hh:mm:ss")) ;
- tmpCode += ")\n" ;
+ tmpCode += ")\n; " ;
- tmpCode += QString(i18n("; Time Delay = %1s with Osc = %2MHz\n\n")).
+ tmpCode += QString(i18n("Time Delay = %1s with Osc = %2MHz\n\n")).
arg(loopValues->getTimeDelay(),0,'f',8).arg(loopValues->getClockFrequency(),0,'f',8);
tmpCode += routineName ;
tmpCode += "\n" ;
- if ( loopValues->getCounterD() != -1 ) {
- tmpCode += QString("\tmovlw\tD'%1'\n").arg(loopValues->getCounterD(),0,10);
- tmpCode += QString("\tmovwf\t");
- tmpCode += QString(i18n("CounterD"));
- tmpCode += "\n";
+ if ( loopValues->getCounterC() == -1 &&
+ loopValues->getCounterB() == -1 &&
+ loopValues->getCounterA() == -1 ) {
+ tmpCode += "\n; ";
+ tmpCode += i18n("PikLoops was unable to calculate the delay you requested.\n");
+ if ( loopValues->isOverflow() == 1 ) {
+ double maxDelay = ( 4.0 * MACHINE_CYCLE_MAX ) / ( loopValues->getClockFrequency() * 1000000.0 ) ;
+ tmpCode += "; ";
+ tmpCode += QString(i18n("The greatest delay you can get don't have to exceed %1s").arg(maxDelay,0,'f',8)) ;
+ }
+ else {
+ double minDelay = ( 4.0 * MACHINE_CYCLE_MIN ) / ( loopValues->getClockFrequency() * 1000000.0 ) ;
+ tmpCode += "; ";
+ tmpCode += QString(i18n("The lowest delay you can get have to be greater than %1s").arg(minDelay,0,'f',8)) ;
+ }
}
+ else {
+
+
if ( loopValues->getCounterC() != -1 ) {
tmpCode += QString("\tmovlw\tD'%1'\n").arg(loopValues->getCounterC(),0,10);
tmpCode += QString("\tmovwf\t");
tmpCode += QString(i18n("CounterC"));
tmpCode += "\n";
+ tmpCode += loopName ;
+ tmpCode += "\n" ;
+ tmpCode += QString("\tcall\t");
+ tmpCode += subRoutineName ;
+ tmpCode += "\n" ;
+ tmpCode += QString("\tdecfsz\t");
+ tmpCode += QString(i18n("CounterC"));
+ tmpCode += QString(",1\n\tgoto\t%1\n").arg(loopName);
+ tmpCode += QString("\treturn\n");
+ tmpCode += "\n" ;
+ tmpCode += subRoutineName ;
+ tmpCode += "\n" ;
+ tmpCode += QString("\tmovlw\tD'%1'\n").arg(loopValues->getCounterB(),0,10);
+ tmpCode += QString("\tmovwf\t");
+ tmpCode += QString(i18n("CounterB"));
+ tmpCode += "\n";
+ tmpCode += QString("\tmovlw\tD'%1'\n").arg(loopValues->getCounterA(),0,10);
+ tmpCode += QString("\tmovwf\t");
+ tmpCode += QString(i18n("CounterA"));
+ tmpCode += "\n";
+ tmpCode += loopSubRoutineName ;
+ tmpCode += "\n" ;
+ tmpCode += QString("\tdecfsz\t");
+ tmpCode += QString(i18n("CounterA"));
+ tmpCode += QString(",1\n\tgoto\t%1\n").arg(loopSubRoutineName);
+ tmpCode += QString("\tdecfsz\t");
+ tmpCode += QString(i18n("CounterB"));
+ tmpCode += QString(",1\n\tgoto\t%1\n").arg(loopSubRoutineName);
+ tmpCode += QString("\treturn\n");
}
- if ( loopValues->getCounterB() !=-1 ) {
+ else if ( loopValues->getCounterB() !=-1 ) {
tmpCode += QString("\tmovlw\tD'%1'\n").arg(loopValues->getCounterB(),0,10);
tmpCode += QString("\tmovwf\t");
tmpCode += QString(i18n("CounterB"));
tmpCode += "\n";
- }
-
- if ( loopValues->getCounterA() !=-1 ) {
tmpCode += QString("\tmovlw\tD'%1'\n").arg(loopValues->getCounterA(),0,10);
tmpCode += QString("\tmovwf\t");
tmpCode += QString(i18n("CounterA"));
- tmpCode += "\n\n";
+ tmpCode += "\n";
tmpCode += loopName ;
tmpCode += "\n" ;
tmpCode += QString("\tdecfsz\t");
tmpCode += QString(i18n("CounterA"));
tmpCode += QString(",1\n\tgoto\t%1\n").arg(loopName);
- }
-
- if ( loopValues->getCounterB() != -1 ) {
tmpCode += QString("\tdecfsz\t");
tmpCode += QString(i18n("CounterB"));
tmpCode += QString(",1\n\tgoto\t%1\n").arg(loopName);
+ tmpCode += QString("\treturn\n");
}
- if ( loopValues->getCounterC() !=-1 ) {
+ else if ( loopValues->getCounterA() !=-1 ) {
+ tmpCode += QString("\tmovlw\tD'%1'\n").arg(loopValues->getCounterA(),0,10);
+ tmpCode += QString("\tmovwf\t");
+ tmpCode += QString(i18n("CounterA"));
+ tmpCode += "\n";
+ tmpCode += loopName ;
+ tmpCode += "\n" ;
tmpCode += QString("\tdecfsz\t");
- tmpCode += QString(i18n("CounterC"));
+ tmpCode += QString(i18n("CounterA"));
tmpCode += QString(",1\n\tgoto\t%1\n").arg(loopName);
+ tmpCode += QString("\treturn\n");
}
- if ( loopValues->getCounterD() !=-1 ) {
- tmpCode += QString("\tdecfsz\t");
- tmpCode += QString(i18n("CounterD"));
- tmpCode += QString(",1\n\tgoto\t%1\n").arg(loopName);
}
-
- tmpCode += QString("\treturn\n");
-
// update status line
cycles->setText(statusMessage.arg(loopValues->getTimeDelay(),0,'f',8)
.arg((loopValues->getMachineCycles()),0,'f',0) ) ;
Modified: prog/trunk/src/pikdelay.cpp
===================================================================
--- prog/trunk/src/pikdelay.cpp 2007-10-15 08:16:59 UTC (rev 145)
+++ prog/trunk/src/pikdelay.cpp 2007-10-15 17:24:26 UTC (rev 146)
@@ -1,6 +1,6 @@
/**
- * Copyright (C) 2004 by JAVIER FERNANDO VARGAS G
- * fer...@ca...
+ * Copyright (C) 2004 by JAVIER FERNANDO VARGAS G <fer...@ca...>
+ * 2007 - Alain Portal <aportal AT univ-montp2 DOT fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
#include "pikdelay.h"
#include <math.h>
+
PiKDelay::PiKDelay(double ClkF, double TmDly)
{
setClockFrequency(ClkF);
@@ -35,63 +36,50 @@
{
}
-
/*!
\fn PiKDelay::Refresh()
*/
void PiKDelay::Refresh()
{
- CounterA = CounterB = CounterC = CounterD = -1;
+ CounterA = CounterB = CounterC = -1;
+ Overflow = 0 ;
MachineCycleTime = 4.0/(ClockFrequency*1000000.0);
MachineCycles = floor(TimeDelay/MachineCycleTime);
- if ( MachineCycles <= 766.0 ) {
- CounterA = static_cast<int> ((MachineCycles-1.0)/3.0);
- MachineCycles = 1 + (3*CounterA);
-
- if ( CounterA == 256 ) {
- CounterA = 0;
- }
+ if ( MachineCycles < MACHINE_CYCLE_MIN ) {
}
- if ( MachineCycles > 766.0 && MachineCycles <= 196350.0 ) {
- CounterB = static_cast<int>((MachineCycles + 765.0)/770.0);
- CounterA = static_cast<int>((MachineCycles + 765.0 - (770.0 * CounterB))/3.0);
- MachineCycles = (3.0 * CounterA) + (770.0 * CounterB) - 765.0;
+ else if ( MachineCycles <= 771.0 ) {
+ CounterA = static_cast<int> ( ( MachineCycles / 3.0 ) - 1.0 );
+ MachineCycles = 3 * ( CounterA + 1 );
+ /* To make gpasm happy */
if ( CounterA == 256 ) {
CounterA = 0;
}
- if ( CounterB == 256 ) {
- CounterB = 0;
- }
}
- if ( MachineCycles > 196350.0 && MachineCycles <= 50070524.0 ) {
- CounterC = static_cast<int>((MachineCycles + 197116.0)/196355.0);
- CounterB = static_cast<int>((MachineCycles + 197116.0 - (196355.0 * CounterC))/770.0);
- CounterA = static_cast<int>((MachineCycles + 197116.0 - (196355.0 * CounterC) - (770.0 * CounterB))/3.0);
- MachineCycles = (3.0 * CounterA) + (770.0 * CounterB) + (196355.0 * CounterC) - 197116.0;
+ else if ( MachineCycles <= 197125.0 ) {
+ CounterB = static_cast<int> ( ( MachineCycles + 763.0 ) / 770.0 );
+ CounterA = static_cast<int> ( ( MachineCycles + 763.0 - ( 770.0 * CounterB ) ) / 3.0 );
+ MachineCycles = ( 3.0 * CounterA ) + ( 770.0 * CounterB ) - 763.0;
+ /* To make gpasm happy */
if ( CounterA == 256 ) {
CounterA = 0;
}
if ( CounterB == 256 ) {
CounterB = 0;
}
- if ( CounterC == 256 ) {
- CounterC = 0;
- }
}
- if ( MachineCycles > 50070524.0 && MachineCycles <= 12767985148.0 ) {
- CounterD = static_cast<int>((MachineCycles + 50267642.0)/50070530.0);
- CounterC = static_cast<int>((MachineCycles + 50267642.0 - (50070530.0 * CounterD))/196355.0);
- CounterB = static_cast<int>((MachineCycles + 50267642.0 - (50070530.0 * CounterD) - (196355.0 * CounterC))/770.0);
- CounterA = static_cast<int>((MachineCycles + 50267642.0 - (50070530.0 * CounterD) - (196355.0 * CounterC) - (CounterB * 770.0))/3.0);
+ else if ( MachineCycles <= MACHINE_CYCLE_MAX ) {
+ CounterC = static_cast<int> ( ( MachineCycles - 3.0 ) / 197125.0 + 1.0 );
+ CounterB = static_cast<int> ( ( ( MachineCycles - 3.0 ) / CounterC + 758.0 ) / 770.0 );
+ CounterA = static_cast<int> ( ( ( MachineCycles - 3.0 ) / CounterC + 758.0 - 770.0 * CounterB ) / 3.0 );
+ MachineCycles = ( 3.0 * CounterA + 770.0 * CounterB - 758.0 ) * CounterC + 3.0;
- MachineCycles = (3.0 * CounterA) + (770.0 * CounterB) + (196355.0 * CounterC) + (50070530.0 * CounterD) - 50267642.0;
-
+ /* To make gpasm happy */
if ( CounterA == 256 ) {
CounterA = 0;
}
@@ -101,14 +89,10 @@
if ( CounterC == 256 ) {
CounterC = 0;
}
- if ( CounterD == 256 ) {
- CounterD = 0;
- }
}
- /*Waitting for correction*/
- if ( MachineCycles > 12767985148.0 ) {
-
+ else {
+ Overflow = 1;
}
TimeDelay = MachineCycles * MachineCycleTime;
@@ -121,10 +105,10 @@
void PiKDelay::setClockFrequency(double CF)
{
if ( CF > 0 ) {
- ClockFrequency = CF;
+ ClockFrequency = CF;
}
else {
- ClockFrequency = 4.00;
+ ClockFrequency = 4.00;
}
}
@@ -135,10 +119,10 @@
void PiKDelay::setTimeDelay(double TD)
{
if (TD >= 0) {
- TimeDelay = TD;
+ TimeDelay = TD;
}
else {
- TimeDelay = 1.00;
+ TimeDelay = 1.00;
}
}
@@ -198,10 +182,9 @@
/*!
- \fn PiKDelay::getCounterD()
+ \fn PiKDelay::isOverflow()
*/
-int PiKDelay::getCounterD()
+int PiKDelay::isOverflow()
{
- return CounterD;
+ return Overflow;
}
-
Modified: prog/trunk/src/pikdelay.h
===================================================================
--- prog/trunk/src/pikdelay.h 2007-10-15 08:16:59 UTC (rev 145)
+++ prog/trunk/src/pikdelay.h 2007-10-15 17:24:26 UTC (rev 146)
@@ -1,6 +1,6 @@
/**
- * Copyright (C) 2004 by JAVIER FERNANDO VARGAS G
- * fer...@ca...
+ * Copyright (C) 2004 by JAVIER FERNANDO VARGAS G <fer...@ca...>
+ * 2007 - Alain Portal <aportal AT univ-montp2 DOT fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +22,9 @@
#ifndef PIKDELAY_H
#define PIKDELAY_H
+#define MACHINE_CYCLE_MIN 6.0
+#define MACHINE_CYCLE_MAX 50464002.0
+
/**
* @author JAVIER FERNANDO VARGAS GONZALEZ
*
@@ -40,18 +43,19 @@
int getCounterA();
int getCounterB();
int getCounterC();
- int getCounterD();
+ int isOverflow();
void Refresh();
+
private:
double ClockFrequency;
double TimeDelay;
double MachineCycles;
+ double MachineCycleTime;
int CounterA;
int CounterB;
int CounterC;
- int CounterD;
- double MachineCycleTime;
+ int Overflow;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|