PDA

View Full Version : PID help



Macgman2000
- 4th November 2011, 05:21
Hello,

I found this snippet of code for a PID written in picbasic. I need some help understanding a few things....

1). What size are the variables? byte, word..?
2). I don't want to use the X2 board. I have a PWM port set up for PWM driving an H-bridge using portb.0 and portb.1 for forward/reverse directions using 16F877A. How would I change the code to reflect the internal PWM and portb direction bits?
3). What is going on with the LOOKUP bit of code? What is it trying to do?

I am running a small electronic motor off of AA batteries, I am creating a servo.

Best Regards,
Nick


6110

Jerson
- 4th November 2011, 06:32
Nick,

Let me try to answer your questions

1 - Word
2 - Very simply, if Drive is a positive value, you move forwards, and vice versa
The pwm magnitude can be set by the ABS(Drive) value
3 - The LOOKUP command is checking if the value in Drive is positive or negative and filling Direction with either f or r.
Understandably, the board wants the direction input to it as either 'f' or 'r' for forward or reverse

Regards