I'm using PIC16F877A to control two motors using an H-Bridge (L293D). Its a robot project for my engineering thesis design project. The ocsillator im using is 20Mhz. The following is my picbasic pro code. If i define my osc as 20Mhz, my motors run at FULL power and DO NOT change direction as per the code below. They just keep going forward. But if i have it as below, they run at a very good speed, and go thro each subroutine perfectly (ie: forward>stop>reverse>stop>main). One problem with this is when the motors are turning forward and revers, i get this high pitch sound. How can i fix this? Also if i wanna change the speed do i change dutcycle (150) or frequency (400)? And what about my DEFINE OSC value?? 4 or 20? Because my serial code (SERIN with T9600) seems to work well with DEFINE OSC 4. Should i sjust change my actualy osc to 4Mhz?!
Any help will be gratly appreciated!!
Thanks so much!
Samuel.
DEFINE OSC 4
TRISC = %00000000
HPWM 1, 150, 400
HPWM 2, 150, 400
TRISB = %00000000
main:
gosub fwd
pause 5000
gosub halt
pause 5000
gosub rever
pause 5000
gosub halt
pause 5000
goto main
end
Bookmarks