-
12-08-2010 #1
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.
-
12-08-2010 #2
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:
-
12-08-2010 #3
-
12-08-2010 #4
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.
-
12-08-2010 #5
-
12-08-2010 #6
Full FP in 2k, could be fun ;-)
-
12-08-2010 #7
-
13-08-2010 #8
-
13-08-2010 #9
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
-
13-08-2010 #10
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Trying to make an ultimate sanding drum!
By fatguyslim in forum Tool & Tooling TechnologyReplies: 26Last Post: 16-05-2014, 01:32 AM -
Can't reply to a thread
By Washout in forum General DiscussionReplies: 9Last Post: 24-10-2012, 06:56 PM -
Thread Tapping?
By Tenson in forum Tool & Tooling TechnologyReplies: 6Last Post: 04-05-2012, 04:51 PM -
Not Just another Boxford tcl 125 thread....
By cooliced in forum Boxford LathesReplies: 135Last Post: 18-08-2011, 10:15 PM -
Pipe thread in 22 tpi???
By Robin Hewitt in forum Machine DiscussionReplies: 3Last Post: 21-09-2010, 11:19 AM
Bookmarks