Opel_Corsa
Member level 1
![Member level 1](/styles/images/ranks/dlevel1.gif)
predefined functions in p89v51rd2.h in c
Good day,
I am working on a project, a 'bot, that has 2 wheels, each connected to an encoder rotary.
- encoder 1 is connected to P0_0, P0_1, P0_2/encoder 2 to P1_1, P1_2, P1_3 (P0_1 and P1_2 are grounds).
- each motor is connected to an H-bridge, as expected. the corresponding bridge for motor 1 is connected to pins P3_2 and P3_4 while that of motor 2 is connected to pins P3_3 and P3_5.
- as you may imagine PWM (and a PI controller) is used to make the motors rotate at the same speed.
Now, here's the C code that I have so far: (implemented by taking pieces of code from different places)
UPDATED: THE NEW CODE IS IN THE NEXT MESSAGE!
I would appreciate any help that would get the 'bot moving straight. By the way I don't understand why I can't use interrupt 5 (i.e. Timer 2 overflow) eventhough I have set TR2 = 1 and ET2 = 1. the other 2 interrupts work (1 and 3, for Timers 0 and 1).
P.S> the main() funxn above is just to test the encoders (which, like I said doesn't work when interrupt 5 is used for any of them. so that's why SquareWave() is using it -or not using it!).
Good day,
I am working on a project, a 'bot, that has 2 wheels, each connected to an encoder rotary.
- encoder 1 is connected to P0_0, P0_1, P0_2/encoder 2 to P1_1, P1_2, P1_3 (P0_1 and P1_2 are grounds).
- each motor is connected to an H-bridge, as expected. the corresponding bridge for motor 1 is connected to pins P3_2 and P3_4 while that of motor 2 is connected to pins P3_3 and P3_5.
- as you may imagine PWM (and a PI controller) is used to make the motors rotate at the same speed.
Now, here's the C code that I have so far: (implemented by taking pieces of code from different places)
UPDATED: THE NEW CODE IS IN THE NEXT MESSAGE!
I would appreciate any help that would get the 'bot moving straight. By the way I don't understand why I can't use interrupt 5 (i.e. Timer 2 overflow) eventhough I have set TR2 = 1 and ET2 = 1. the other 2 interrupts work (1 and 3, for Timers 0 and 1).
P.S> the main() funxn above is just to test the encoders (which, like I said doesn't work when interrupt 5 is used for any of them. so that's why SquareWave() is using it -or not using it!).