CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Driving DC w/ PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
o_wan
Guest







Driving DC w/ PWM
PostPosted: Tue Nov 22, 2005 2:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 22, 2005 3:53 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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