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

Problem with PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
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

Problem with PWM
PostPosted: Sun Sep 19, 2010 9:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 19, 2010 11:43 am     Reply with quote

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

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

PostPosted: Mon Sep 20, 2010 4:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 21, 2010 6:34 am     Reply with quote

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

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

PostPosted: Thu Sep 23, 2010 1:28 pm     Reply with quote

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."
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