PDA

View Full Version : The 'ultimate rev counter' thread...



irving2008
12-08-2010, 06:58 PM
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.

Ross77
12-08-2010, 09:14 PM
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:

Ricardoco
12-08-2010, 09:39 PM
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:

ecat
12-08-2010, 10:44 PM
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/PHYS%20315%20-%20Cholewiak,%20Steven%20-%20PIC18F252%20P.I.D.%20Heater%20Controller.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 :)



// 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.

irving2008
12-08-2010, 10:53 PM
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....

ecat
12-08-2010, 11:18 PM
Full FP in 2k, could be fun ;-)

irving2008
12-08-2010, 11:57 PM
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....

John S
13-08-2010, 12:40 AM
:clap:Sometimes the less you say, the louder it sounds!!:wink::cool:

You mean a TALKING rev counter, now that's cool !!

.

GeorgeD
13-08-2010, 10:33 AM
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

Ricardoco
13-08-2010, 10:52 AM
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

ecat
13-08-2010, 11:45 AM
...
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

The PIC is the brain, the heart, the very soul of the project :(

If you must buy a programmer this is the one I recommend http://www.rapidonline.com/Electronic-Components/Integrated-Circuits/PIC-Microcontrollers/PICkit-2-Starter-Kit/77048/kw/PICkit+2+Starter+Kit . You will also find a vast selection of ready made and DIY PIC programmers that mostly cost less, don't even think about them!

After much pondering over the requirements of an 'internet project' I'm still convinced the all in one, ready made, USB friendly, no need for a dedicated programmer, cost over £25 but save hours of frustration (1), units are the best options :)
http://robosavvy.com/store/product_info.php/cPath/41_1002_1009/products_id/726
http://robosavvy.com/store/product_info.php/cPath/41_1002_1009/products_id/543

Saves hours of frustration? This is fact under XP at least, best to check comparability of the USB driver with Vista/Win7 if required.

Mad Professor
13-08-2010, 12:51 PM
I have never used raw pic chips myself, I have made a few little projects using PicAxe (http://www.rev-ed.co.uk/picaxe/) pic chips.

I don't know if the PicAxe (http://www.rev-ed.co.uk/picaxe/) would be also suitable for this project.

Ricardoco
13-08-2010, 01:03 PM
You will also find a vast selection of ready made and DIY PIC programmers that mostly cost less, don't even think about them!..

What makes you say that?? ive tried many, both designed by me and Pre-assembled and likewise DIY and although they all have thair querks, they have all done the job once i got used to them, i do find that many companies try to do too much on the board but that is because they have got "programmers & project boards a bit mixed up" if i want a programmer then thats exactly what i want and if i want a project board i get one or build one of those also.

But the fact remains ive tried a few of both encarnations and all once i got used to them were ok,

Rick

irving2008
13-08-2010, 01:23 PM
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
Of course there is, if you want a dumb design.... is there a way of using a word processor without a computer???

ecat
13-08-2010, 01:31 PM
What makes you say that??


I've looked at many DIY kits, I own a Velleman/Maplin programmer (http://www.velleman.eu/distributor/products/view/?id=351982), we have a couple of old school Microchip PicStart programmers at work. What can I say about the PicKit2, and possibly 3?

They are small, they are neat, price is good, made by Microchip, supported by Microchip, supported by Microchip software, Microchip software supplied in the kit, have a large user base, work out the box, can program a PIC without a PC connection, they work when the target board is powered, they work when the target board is not powered (they supply the power from USB), they can be used with almost all PIC models and variations... The list goes on, they are a seriously hard act to follow.

heh, have a chat with Dave:
http://www.eevblog.com/2009/10/21/eevblog-39-pickit-3-programmerdebugger-review/
http://www.eevblog.com/2010/02/22/eevblog-63-microchip-pic-vs-atmel-avr/

irving2008
13-08-2010, 01:32 PM
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
On the subject of programmers the short answer is 'it all depends'

If you want to burn code that somebody else has developed then a simple one like this is fine....

If you want to write code for simple solutions that are not demanding and you can debug with simple tools - multimeter, logic probe, then its OK

If you want to do the job properly, debug on the fly, validate complex performance relationships, and not waste hours on goose chases then you need a proper in-circuit debugger/programmer.. for PICs I use the PicKit2 which was £30, thats less than £1 per project so far and I reckon its saved me that in time alone (even my own time has an opportunity cost value), plus I have had no issues with each update of the development environment (not true of many 3rd party options) and the range of PICs it works with is huge.

Ricardoco
13-08-2010, 02:55 PM
My first programmer was from matrix multimedia and i still use it, but i have used many since then, more from curiosity, i dont doubt that the PicKit2 is good in fact i know it is, the programmer/development board i put the link to is going to be completely embeded it will be programmed and tested, and entombed forever (hopefully) and this would seem to be fine, if as in this case someone such as yourself has worked out the circuit. It saves on fabricating a board. If you want to develop several projects over time then by all means a reputable and proven programmer/development board such as Pickit2 would be the way you would go, George was showing some aversion to to using pics and having to buy a programmer for a project, this is an inexpensive way to dip your toes in the water of microcontrolers and if its not for him he's lost pennys instead of pounds..

This board has through the hole plating and good clear screen printing and all the components you need apart from the pic itself, so is within reach of even the complete beginer.

Rick


Rick

Ricardoco
13-08-2010, 03:02 PM
Incidently, i posted the wrong link there.. lol fleabay item number:-250576566482

It would easily be usable for most small projects and for this price, well what more can i say..


Rick

ecat
14-08-2010, 09:33 AM
Incidently, i posted the wrong link there.. lol fleabay item number:-250576566482

It would easily be usable for most small projects and for this price, well what more can i say..


Rick

Certainly a lot more professional and easy to use than my 1st pic board :whistling:

2628

Ricardoco
14-08-2010, 09:45 AM
Certainly a lot more professional and easy to use than my 1st pic board :whistling:

2628

This is cool, you had a concept and went off and completed it, and Hey if it worked what more could you ask??, I think i would have enjoyed making that as much as i enjoyed making some of mine, this is what irving does,without even realising it, he encourages you to get building, because he and others on this forum are here to help you out when you get stuck..

Rick

irving2008
14-08-2010, 10:04 AM
Certainly a lot more professional and easy to use than my 1st pic board :whistling:

2628
lol don't knock stripboard, it has its place... I use plugboards now for prototyping (pic is my basic setup) but for some things where you want a copper ground plane, stripboard still works bette as a prototyping medium...

2629

ecat
14-08-2010, 12:24 PM
Heh, general dev board looks a little different these days

26302631

and prototyping a little more advanced

2632

That's a few Dallas temperature sensors, 80MHz cpu board, 32K external RAM, 4MB external flash and a 1GB micro SD card. Add a little test software (http://forum.sparkfun.com/viewtopic.php?f=19&t=17217) and things have come a long way :)

irving2008
14-08-2010, 12:29 PM
Now you're just showing off lol

ecat
14-08-2010, 12:48 PM
<chuckle>
I know feck all about mechanics so I've got to find some way to justify my membership here ;-)

Wobblybootie
14-08-2010, 02:36 PM
<chuckle>
I know feck all about mechanics so I've got to find some way to justify my membership here ;-)


Ruddy Hell ... I know sod all about anything useful to this Forum, I just soak up stuff, except anything mathematical :confused: [sorry Irving] ... so I shall beat a hasty retreat (aka Tactical Withdraw) to my little Sanger and keep a listening watch!!:whistling:

GeorgeD
14-08-2010, 03:14 PM
Tsk! it was one of these when I wus a lad...
http://www.tvfilmprops.co.uk/userdata/PRODPIC-914.jpg

z3t4
14-08-2010, 03:56 PM
I hadn't used stripboard for ages until I made Les's Tacho x2. Much more used to the joys of UV boxes, FeCl3 etc. I have now resolved never to use stripboard again. It's just too much hassle checking for shorts between the strips :sad:

ecat's Eagle .brd looks good. Must investigate ...

Just a thought about the design spec. Three features of Les's design that I really liked were


the use of the Allegro gear sensor (it's as good as gold; no messing with slotted discs/foil/Tipp-Ex etc, very reliable, very robust -- just needs to be mounted tangentially 1-2mm from teeth)
the capacity to accommodate a non-standard number of pulses per rev (65 in the case of the ml7 bullwheel)
a one pulse per rev output (useful for my Shumatech DRO's).

HTH

John

irving2008
14-08-2010, 05:51 PM
I hadn't used stripboard for ages until I made Les's Tacho x2. Much more used to the joys of UV boxes, FeCl3 etc. I have now resolved never to use stripboard again. It's just too much hassle checking for shorts between the strips :sad:

ecat's Eagle .brd looks good. Must investigate ...

Just a thought about the design spec. Three features of Les's design that I really liked were


the use of the Allegro gear sensor (it's as good as gold; no messing with slotted discs/foil/Tipp-Ex etc, very reliable, very robust -- just needs to be mounted tangentially 1-2mm from teeth)
the capacity to accommodate a non-standard number of pulses per rev (65 in the case of the ml7 bullwheel)
a one pulse per rev output (useful for my Shumatech DRO's).
HTH

John
All of which are on my list... I started looking at how to fit to my minilathe and quickly decided a slotted disc wasnt going to fly (or should that be 'rotate'?) Since we have some fixed gears, clearly a reluctance sensor is the way to go, so started looking for something suitable..

The software design already accommodates a 'divide by N' feature as Rick needs /50 for his, and I will need something for the minilathe and if I do one for the mill too Im sure that'll have a different value. I haven't yet decided how to set this.. probably a jumper and a push button... at power up if jumper present go into setup mode and each press of the button increments the 'divide by count' from 1 to 100, hold it down 5sec is increment by 10... release button for 10sec, store in eeprom

One pulse per rev is easy...

GeorgeD
14-08-2010, 06:03 PM
Irving,there is a way to mount a disc on the lathe...

One disc with a hole in it and mount it on the back of the spindle just behind the two locknuts,you'll have to make a short arm piece of metal for the slotted sensor to fit over the disc.
This way its covered up and out of sight.

irving2008
14-08-2010, 06:12 PM
yes, but I want more than one pulse/rev... for closed loop speed control you can't have too much information... and a sensor (http://uk.farnell.com/allegro-microsystems/ats642lshtn-i2-t/gear-tooth-sensor-2-wire-sh-module/dp/1521699)on the fixed gears may well be easier...

Note: if anyone reading this has a minilathe with built in rev counter... how is it done? Are there any useful parts that could be acquired as spares? I had a quicl browse for a parts list online but all of the ones I found don't detail the rev counter...

GeorgeD
14-08-2010, 06:20 PM
Here's a stripdown of machine and points to where the sensor is located,theres obviously a wheel in the stock castin housin inside.

http://www.arceurotrade.co.uk/projects/prepguides/C3%20Mini-Lathe%20Preparation%20Guide.pdf

http://www.arceurotrade.co.uk/projects/C3_BC/pages/C3_BC5.html

Tom
14-08-2010, 06:25 PM
Hi Irving, the stock minilathe sensor is hidden in the spindle housing.

I don't like the idea of a retro-fitted slotted disk twirling around - most mounting locations make them vulnerable to clonks. Hall-effect on a gear is the most robust choice in my opinion.

GeorgeD
14-08-2010, 06:32 PM
here's idea I posted earlier...

z3t4
14-08-2010, 06:46 PM
... and a sensor (http://uk.farnell.com/allegro-microsystems/ats642lshtn-i2-t/gear-tooth-sensor-2-wire-sh-module/dp/1521699)on the fixed gears may well be easier...

'tis the very sensor. Mounting it is a bit of a pain, currently in epoxy. Hopefully somebody who knows how it should be done will chip* in.


*:smile:

irving2008
14-08-2010, 11:51 PM
Hi Irving, the stock minilathe sensor is hidden in the spindle housing.

I don't like the idea of a retro-fitted slotted disk twirling around - most mounting locations make them vulnerable to clonks. Hall-effect on a gear is the most robust choice in my opinion.

hmmm, wouldnt be hard to strip headstock down and mill out a section...

Tom
15-08-2010, 09:38 AM
hmmm, wouldnt be hard to strip headstock down and mill out a section...

Eeek - not hard if you have a mill! :nope:

How about epoxy gluing the allegro sensor onto the end of a modified M10 screw, and passing the wiring up the centre thro a ~5mm dia hole. Then it's just a drill and tap needed to fit, and you can make the screw on the lathe you're modifying. Might need to check clearance to the speed control PCB (locknut if there's room, loctite if there isn't).

I'm desperately trying to avoid buying a mill! You lot are not helping! :smile::naughty:

GeorgeD
15-08-2010, 10:18 AM
hmmm, wouldnt be hard to strip headstock down and mill out a section...

Well if you're willing to go that far?....there's a complete opening at the bottom of the casting where it was milled out to begin with,giving you access to the gears...only takes a drilled hole then to pass the wires through to the board.