|
|
View previous topic :: View next topic |
Author |
Message |
Abdulla M.A.
Joined: 28 Mar 2010 Posts: 30 Location: Baghdad, Iraq
|
Problem with PWM |
Posted: Sun Sep 19, 2010 9:50 am |
|
|
Hi guys,
If would like to remove the marks in the signal below, so what I have to
do???
my code:
Code: |
#include <18f4550.h>
#use delay(clock=4000000)
#fuses xt,nowdt,nocpd,nolvp,noprotect
#byte portb=0x06
void send_1();
void send_0();
void send_code();
void main()
{
set_tris_b(0x00);
while(1)
{
send_code();
}
}
void send_1()
{
setup_ccp1(CCP_PWM_l_l);
setup_timer_2(t2_div_by_1,26,1);
set_pwm1_duty(12);
delay_ms(1);
setup_ccp1(ccp_off);
delay_ms(2);
}
void send_0()
{
setup_ccp1(ccp_pwm_l_l);
setup_timer_2(t2_div_by_1,26,1);
set_pwm1_duty(12);
delay_ms(1);
setup_ccp1(ccp_off);
delay_ms(1);
}
void send_code()
{
send_1();
send_0();
send_0();
send_0();
} |
thankx, 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." |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Sun Sep 19, 2010 11:43 am |
|
|
How about instead of the line
Code: |
setup_ccp1(ccp_off);
|
you set the duty cycle to 0? That has the effect of making the PWM output always low. |
|
|
Abdulla M.A.
Joined: 28 Mar 2010 Posts: 30 Location: Baghdad, Iraq
|
|
Posted: Mon Sep 20, 2010 4:51 am |
|
|
Yes, it became low after I made the duty cycle=0, and remove L_L
from the setup_ccp1(ccp_pwm1_l_l); but it's not pure low, it's about 0.7v. Thank you.
Can you tell me, why setup_pwm1(ccp_off); did not work???
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." |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Tue Sep 21, 2010 6:34 am |
|
|
My guess is that the setup_pwm1(ccp_off) command just stops the counter at whatever value the output has at that instant, and it might end up high or low. You could check this by looking at the LST file to see what assembly language instructions are used, and then going to the chip manual to see what should be happening--not always totally easy to understand, though! I'd be somewhat disappointed that this instruction leaves a random result, but as you see, there is a workaround. |
|
|
Abdulla M.A.
Joined: 28 Mar 2010 Posts: 30 Location: Baghdad, Iraq
|
|
Posted: Thu Sep 23, 2010 1:28 pm |
|
|
Thank you alot John for your help.
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
|