I'm having a hard time getting both PID feedback and positioning to run at the same time.
My thought to calculate the RPM is to:
- start a timer and count encoder pulses using an interrupt.
- use some simple math to convert to RPM.
- reset variables used and start over.
I can calculate RPM but then I can only call my PID controller after the calculation (however long I want to wait to get good resolution.) This results in very messy code. Is there a simpler method or something I'm missing?
Info about my application: I am programming to an Atmel ATmega328P with a DC motor/dual magnetic encoder with ~600 pulses per revolution (after gearhead). I want to call GoToTarget(#) and have the motor go to the position while updating the PID parameters. In addition,it must go both ways.