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 support@ccsinfo.com

16f628a HPWM

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



Joined: 03 Mar 2008
Posts: 6

View user's profile Send private message MSN Messenger

16f628a HPWM
PostPosted: Tue Apr 20, 2010 5:43 am     Reply with quote

Hi all,

I cannot get pwm signal on pin_b3. Is this code wrong ??


#include <16f628a.h>
#use delay (clock=4000000)
#fuses intrc_io,Brownout,NOWDT,PROTECT,NOLVP,put,cpd,nomclr

void main()
{

setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_timer_2(T2_DIV_BY_4, 127, 1);

set_tris_b(0);

while(true)
{
set_pwm1_duty(127);
delay_ms(20);

}

}
Abdulla M.A.



Joined: 28 Mar 2010
Posts: 30
Location: Baghdad, Iraq

View user's profile Send private message Visit poster's website Yahoo Messenger

PostPosted: Tue Apr 20, 2010 6:55 am     Reply with quote

Hi,
this is the program with duty cycle=50%
if you have any question, you can ask.

#include <16f628a.h>
#use delay(clock=4000000)
#fuses xt,nowdt,nocpd,noprotect,nolvp

void main()
{
set_tris_b(0x00);
setup_ccp1(ccp_pwm);
set_pwm1_duty(500); //50% duty cycle
setup_timer_2(t2_div_by_4,249,1);

}

Abdulla
_________________
"A scientist can discover a new star, but he cannot make one. He would have to ask an engineer to do that."
"For an optimist the glass is half full, for a pessimist it's half empty, and for an engineer is twice bigger than necessary."
OzanGazi



Joined: 03 Mar 2008
Posts: 6

View user's profile Send private message MSN Messenger

PostPosted: Tue Apr 20, 2010 7:15 am     Reply with quote

Ok it works Thank you...

But still there is a problem..

while(true)
{

if(++MotorPower>1000)
{
MotorPower=0;
}

delay_ms(2);
set_pwm1_duty(MotorPower);

}

PWM output works with %50 fixed duty ratio..But when i put this code in program PWM signal stops and pin_B3 stay on "0"..What do you say for this condition ??
Abdulla M.A.



Joined: 28 Mar 2010
Posts: 30
Location: Baghdad, Iraq

View user's profile Send private message Visit poster's website Yahoo Messenger

PostPosted: Tue Apr 20, 2010 9:08 am     Reply with quote

welcome Wink
Code:

#include <16f628a.h>
#use delay(clock=4000000)
#fuses xt,nowdt,nocpd,noprotect,nolvp

int16 MotorPower;

void main()
{
   set_tris_b(0x00);
   setup_ccp1(ccp_pwm);
   setup_timer_2(t2_div_by_4,249,1);

   while(true)
   {

      if(++MotorPower>1000)
      {
         MotorPower=0;
      }

      
      set_pwm1_duty(MotorPower);
                                }
}

Your program work fine!!!! I tested it now, so what the errors if there is??

Abdulla
_________________
"A scientist can discover a new star, but he cannot make one. He would have to ask an engineer to do that."
"For an optimist the glass is half full, for a pessimist it's half empty, and for an engineer is twice bigger than necessary."
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