|
|
View previous topic :: View next topic |
Author |
Message |
o_wan Guest
|
Driving DC w/ PWM |
Posted: Tue Nov 22, 2005 2:52 pm |
|
|
hi all,
Since my PIC16F877A got 2 PWM only, is that possible to drive DC w/o PWM, can I use generate pulse on & off code to replace PWM like below and w/ h-bridge circuit?
Anyone did that b4?
#include <16f877A.h> /*include standard functions of our PIC chip*/
#fuses XT,NOLVP,NOWDT
#use delay(clock=4000000)
void MOVE(int on, int off)
{
{output_bit(PIN_A2,1); output_bit(PIN_A3,0);}
{output_bit(PIN_A1,1); output_bit(PIN_A0,0);}
delay_ms(on);
{output_bit(PIN_A2,0); output_bit(PIN_A3,0);}
{output_bit(PIN_A1,0); output_bit(PIN_A0,0);}
delay_ms(off);
}
main(){
int t;
while(1){
for(t=0;t<100;t++) MOVE(3,10);
for(t=0;t<30;t++) MOVE(10,10);
}
} |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Nov 22, 2005 3:53 pm |
|
|
That should work, but I would just set up an XOR mask for port A so I could change all four outputs with a single instruction. You can load the port with a word that shuts off all the switches to let the motor freewheel. You can have another word that grounds both ends of the motor for braking. To run you load a word to start the bridge, and then just XOR that word to run the bridge. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|