1 Attachment(s)
The 'ultimate rev counter' thread...
Ok, so I got bored at work writing a paper on why we don't need to spend another £100k on overpriced Sun disc arrays (don't go there OK, I dont want to discuss it further :twisted:) so I decided to draw up this...
Its a rev counter with bell n whistles.
In its most basic form it takes pulses from the rev sensor (on the left), and shows revs on the LCD display.
It will also take a PWM input (or a voltage input but I haven't shown that on the diagram) from MACH3 or EMC2 and output a PWM signal for a speed controller. It could also output a 0 - 10v as well but I've not shown that bit. So it can act in 3 modes:
1/ PWM type 1 in, PWM type 2 out
2/ Voltage in, PWM out
3/ PWM in, voltage out
The two preset resistors set the upper and lower bound of the output speed. A commanded speed below the lower bound results in no motion. I've assumed for the moment that MACH3/EMC would control the spindle power relay, but it woudnt be hard to add this here.
Since we know commanded speed and actual speed it would be possible to provide closed loop control, although that requires some interesting calculations. This chip only has 2k of program memory, so might need to go to its bigger brother for that.
Re: The 'ultimate rev counter' thread...
Excellent. are you proposing to build and sell them or will you be publishing the code? I like the idea of closed loop control.
I take one if your making them, don't think I've got time to build it, not finished the stepper drives yet :whistling:
Re: The 'ultimate rev counter' thread...
Quote:
Originally Posted by
irving2008
Ok, so I got bored at work writing a paper on why we don't need to spend another £100k on overpriced Sun disc arrays (don't go there OK, I dont want to discuss it further :twisted:) so I decided to draw up this...
Its a rev counter with bell n whistles.
In its most basic form it takes pulses from the rev sensor (on the left), and shows revs on the LCD display.
It will also take a PWM input (or a voltage input but I haven't shown that on the diagram) from MACH3 or EMC2 and output a PWM signal for a speed controller. It could also output a 0 - 10v as well but I've not shown that bit. So it can act in 3 modes:
1/ PWM type 1 in, PWM type 2 out
2/ Voltage in, PWM out
3/ PWM in, voltage out
The two preset resistors set the upper and lower bound of the output speed. A commanded speed below the lower bound results in no motion. I've assumed for the moment that MACH3/EMC would control the spindle power relay, but it woudnt be hard to add this here.
Since we know commanded speed and actual speed it would be possible to provide closed loop control, although that requires some interesting calculations. This chip only has 2k of program memory, so might need to go to its bigger brother for that.
:clap:Sometimes the less you say, the louder it sounds!!:wink::cool:
Re: The 'ultimate rev counter' thread...
Neat :)
Are you intending to break out the ICP pins? Generally the first thing I do :) Also a resistor on MCLR?
Once upon a time I found this paper...
http://www.semifluid.com/classes/PHY...Controller.pdf
the source contains code for a simple integer based PID loop, though it only controls one way it makes for a good start if you need it :)
I modified the code to control both ways and tweaked a few things while playing with it, I have no idea what state I left the code in but it's yours if you want it :)
Code:
// Variables and constants for P.I.D.
// -----------------------------------------------------------------------------
BYTE thePower;
short Tcurrent, Tlast, Tsetpoint;
short iState;
BYTE iStateInc;
//#define iMax 254 // ctd was 1000.00 // Maximum iState
short iMax;
BYTE pGain, iGain, dGain;
short temp;
#define ResolutionScale 16
#define iMin 1.00 // Minimum iState
#define tempMax (60 * ResolutionScale) // Maximum temperature ctd temp * sensor resolution. Not a problem if to large a value ?
#define OPScaleFactor 128 // shift friendly
#define MaxOP 99
void InitPid( void )
{
Tcurrent = 0;
Tlast = 0;
iState = 0;
pGain = 200; //3; // for 12 bit resolution keep <= 16 for extra safety
iGain = 10; // was 5, see iStateInc too
dGain = 1000; //1; // for 12 bit resolution keep <= 16 for extra safety
iMax = (OPScaleFactor * MaxOP) / iGain; // 10000 yields max 100% op, no need for more ?
iStateInc = 4; // new var, was const 4.0
}
void PID( void )
{
//void calculatePID(){
/* The calculatePID() function calculates the error by subtracting the
desired temperature (Tsetpoint) from the current temperature (Tcurrent).
It then uses the calculated error to determine the proportional term,
which is dependent solely upon the error, the integral term, which is an
accumulation of the error and is used to clean up the final output, and
the derivative term, which is dependent upon the change in the system.
The function then adds the proportional and integral terms then subtracts
the derivative term to come to a power estimate.
*/
/* // ctd
* Derived from PHYS 315 - Cholewiak, Steven - PIC18F252 P.I.D. Heater Controller.pdf
* Error increment is capped by the use of iStateInc so immune to bad readings
* One way control only. Changed to 2 way
* Easy to protect from overflow
* Nasty jump at pv = sp, ok if tuned for max output ?
* Slow wind down due to 'iState = iState - 1.00;', changed to be symmetrical
*/
short tempPower;
short pTerm, iTerm, dTerm, theError;
Tsetpoint = 0x136;
Tcurrent = temp;
theError = Tcurrent - Tsetpoint; // ctd swapped these over
pTerm = pGain * theError;
dTerm = dGain * (Tcurrent-Tlast); // one blip per change, hardly worth it for slow systems imho
if( theError > 0 ) { // ctd was >=0
iState = iState + iStateInc;
}
else {
iState = iState - iStateInc; // ctd was 1.00;
}
if( iState > iMax ) iState = iMax;
if( iState < iMin ) iState = iMin;
iTerm = iState * iGain;
tempPower = pTerm + iTerm - dTerm;
tempPower = tempPower / OPScaleFactor;
if( tempPower >= 0 ) {
thePower = (BYTE) tempPower;
if( thePower < 30 )
thePower = 30;
}
else
thePower = 30;
// if( Tcurrent < Tsetpoint )
// thePower = 30;
if( thePower > MaxOP ) thePower = MaxOP;
// if( Tcurrent > tempMax ) thePower=0;
Tlast = Tcurrent;
// serial_print_hex8( thePower );
INTCONbits.GIE = 0;
PWMDuty1Reset = thePower;
INTCONbits.GIE = 1;
//130: printf("%f,%f,%lu,%f\n\r", Tcurrent, Tsetpoint, thePower, tempPower);
// }
}
I suspect the problem with an integer control loop may be the limited resolution, still, worth a try.
Re: The 'ultimate rev counter' thread...
Quote:
Originally Posted by
ecat
Neat :)
Are you intending to break out the ICP pins? Generally the first thing I do :) Also a resistor on MCLR?
Yes, just haven't done so yet... there's a few other mods...
Thanks for the code sample... I have one or two others... no need to keep to integers, there's a full FP library if i need it and enough performance in the chip to use it for this application....
Re: The 'ultimate rev counter' thread...
Full FP in 2k, could be fun ;-)
Re: The 'ultimate rev counter' thread...
Quote:
Originally Posted by
ecat
Full FP in 2k, could be fun ;-)
Efficient linkr only loads whats actually needed.... its pretty good... I use it elsewhere and it loads <300 instructions for basic floating point math....
Re: The 'ultimate rev counter' thread...
Quote:
Originally Posted by
Ricardoco
:clap:Sometimes the less you say, the louder it sounds!!:wink::cool:
You mean a TALKING rev counter, now that's cool !!
.
Re: The 'ultimate rev counter' thread...
Wow,almost identicle to this one belowthat I was having a look at two nights ago?
http://www.jeffree.co.uk/pages/revmaster.htm
Is there not a way to knock one up without the use of a PIC? itmeans I have to buy a programmer or look for someone selling a chip prorammed using their design
Re: The 'ultimate rev counter' thread...
Quote:
Originally Posted by
GeorgeD
Wow,almost identicle to this one belowthat I was having a look at two nights ago?
http://www.jeffree.co.uk/pages/revmaster.htm
Is there not a way to knock one up without the use of a PIC? itmeans I have to buy a programmer or look for someone selling a chip prorammed using their design
Hey george, I got one of these the other day, im very pleased with it and for what is costs Im amazed..
fleabay item number:-250641581270
Rick