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

Need help in pwm generation using CCS C

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



Joined: 13 Feb 2012
Posts: 1

View user's profile Send private message

Need help in pwm generation using CCS C
PostPosted: Mon Feb 13, 2012 5:54 am     Reply with quote

I am trying to generate 2 pwm using ccp1 & ccp2 in pic16f877a. I am using the following instructions.
Code:

setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 5);
set_pwm1_duty(31);

Q1. I am getting pwm in both ccp1 & ccp2. in the 2nd instruction,i.e.,
setup_timer_2(T2_DIV_BY_1, 255, 5);
i.e., setup_timer_2(T2_DIV_BY_a, offset, postscaler);
T2_DIV is prescaler, 255 is offset, 5 is postscaler.
prescaler & offset have role in calculating period (i.e., pwm freq). But I found that postscaler has got no role. I have simulated this in Proteus. There if I change the value of postscaler in 1-16 (this range is given in ccs c manual), the freq of pwm did not change. Why?

Q2. Duty cycle is 10bit (found in datasheet). That means in the 3rd instruction i.e., set_pwm1_duty(x); x can be varied from 0 to 1023, where 1023 means almost 100% duty cycle, and x=(duty cycle in %) x 1023. But in some documents it is written x=0 to offset in instruction 2. Which one is right? While simulating in Proteus, I have seen x=(duty cycle in %) x 1023. This formula does not work. x=(duty cycle in %) x offset works. That means I can not have 10bit resolution if I use ccs c.

Can anybody please help me to solve this?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 6:20 am     Reply with quote

The postscaler has nothing whatsoever to do with the frequency generated. Hence does not affect the PWM. _READ THE CHIP DATA SHEET_.
It affects how often the timer generates an interrupt _only_.

The pwm on both outputs, is a Proteus bug.

Then, _search the forum, and read the manual_.
A Search on 'PWM 10bit', with 'search for all terms', will find the hundreds of threads explaining what you are seeing. Ore read the set_pwmx_duty section in the manual, and read the paragraph 'function'. Note what happens if an 8bit value is used with the function....


Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 1:40 pm     Reply with quote

This thread has all the links on PWM that you need, including for the
postscaler, etc.
http://www.ccsinfo.com/forum/viewtopic.php?t=45968
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