I presume you are using C? Which compiler? Which PIC chip?
ints are 16 bits, as you've discovered.
longs are 32 bits.
I've developed a mode driven controller for the Rotary Table on a Lathe and Mill.
In the GOTO-mode for now it only excepts whole degrees inputs.
But how to rotate 0,241or 359,385 degrees in chip code where the WORD value range is only from 1 to 65.535?
Lets say: GearRatio=120, StepSettings=200
So, when calculating the StepPulses during division and multiplying the value exceeds the WORD range and therefore the chip adjusts the value incorrect!?
Similar Threads:
Last edited by Driller2; 05-20-2015 at 07:27 AM.
I presume you are using C? Which compiler? Which PIC chip?
ints are 16 bits, as you've discovered.
longs are 32 bits.
I'm using MPLAB with PICkit 2 programmer where as the chip I can change to whatever works good.
So should I use the Longs or FloatingPoints in this case?
Try very hard to avoid floats - they don't necessarily represent numbers accurately. For example, 10.0 * ( 4.0 / 10.0 ) may not equal 4.0!
I would suggest working with longs with an implied 'decimal' point. For example, the first 16 bits would represent the whole number, the remaining 16 bits represent the fraction part. Start with how many steps per turn your mechanical system has, and work backwards from there. Have a look at Jones on reciprocal multiplication for some ideas on implementing fixed point routines.
And if your chip choice is flexible, look at the PIC24FV series. They work at 5 volts and are available in 20 and 28 pin DIP. I _think_ the PICkit2 can program them.
You can do it all in integer.if you could have a set resolution of 0.01 degrees or 36000 counts defined per turn. (360*100)
So each degree is 100 counts. Then its easy for you to decode decimal input knowing the 2 decimal places is 0-9 counts or 0-99 extra.
Then use bregenhams integer algorithm to scale the comanded (0-36000) counts to what the real machine counts per rev is.
Larry
Thanks for the replies, some ideas I have not thought of.
So, floats are no option!vegipete : Try very hard to avoid floats - they don't necessarily represent numbers accurately.
That part was already programmed for entering a decimal at a certain position, but couldn't decide how to proceed.vegipete : I would suggest working with longs with an implied 'decimal' point.
vegipete :...the remaining 16 bits represent the fraction part.To consider it as a seperate value, I have not came up with that idea! I think that should do the trick.Larken: Then its easy for you to decode decimal input knowing the 2 decimal places is 0-9 counts or 0-99 extra.