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

PWM period incorrect, pulse width correct

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



Joined: 13 Jul 2005
Posts: 25
Location: Maryland

View user's profile Send private message

PWM period incorrect, pulse width correct
PostPosted: Tue Mar 23, 2010 1:32 am     Reply with quote

Hi all,

I am using a PIC24F04KA200 with 4.104. I successfully generate a PWM with pulse width (duty cycle) and period as programmed. However this only works until a period of ~16.4ms. Faster than that, and the pulse width is correct, but the period is way off... I have an FRC PLLed, and I'm doing this:
Code:

#fuses FRC_PLL, NOWDT, NOPROTECT
#use delay(internal=8M)
#byte PR2 = 0x010C // This is the timer period  out of the datasheet
...
// Set up PWM
PR2 = 306;
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1);
setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);

// Enter main software infinite loop
while(TRUE)

   set_pwm_duty(1, 150);
}

This is the same example as in the datasheet for this chip, ex. 14-1, pg. 115. Quote datasheet:
Quote:

Find the Timer Period register value for a desired PWM frequency of 52.08 kHz, where FOSC = 8 MHz with PLL
(32 MHz device clock rate) and a Timer2 prescaler setting of 1:1.
TCY = 2 * TOSC = 62.5 ns
PWM Period = 1/PWM Frequency = 1/52.08 kHz = 19.2 μs
PWM Period = (PR2 + 1) • TCY • (Timer 2 Prescale Value)
19.2 μs = (PR2 + 1) • 62.5 ns • 1
PR2 = 306

Doesn't this mean that I should expect to see PWM pulses stay up for ~9.6μs every 19.2μs? Or am I mistaken somewhere?
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