|
|
View previous topic :: View next topic |
Author |
Message |
OzanGazi
Joined: 03 Mar 2008 Posts: 6
|
16f628a HPWM |
Posted: Tue Apr 20, 2010 5:43 am |
|
|
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
|
|
Posted: Tue Apr 20, 2010 6:55 am |
|
|
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
|
|
Posted: Tue Apr 20, 2010 7:15 am |
|
|
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
|
|
Posted: Tue Apr 20, 2010 9:08 am |
|
|
welcome
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." |
|
|
|
|
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
|