$60 off LOAD-n-GO Handheld Programmer
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


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

Joined: 09 Dec 2008
Posts: 2

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 7:10 am     Reply with quote

I am currently working on a project to control a Buck Converter. To do this I am trying to generate a PWM signal at a fixed frequency of 50 KHz and I require at least ten bits of resolution (1024 steps). I have attempted using the standard PWM Output Capture Module on the DSPIC30F2011 without much success. I have calculated the period register value using the following formula obtained from the DSPIC30F Reference Manual: PWM Period = [(PRy) + 1] _ TCY _ (TMRy Prescale Value). To clock the device I am using a 15MHz external crystal in the HS/2 w/PLL 16x mode. This should give me a frequency of 120Mhz. (30MIPS), yes? The timer 2 Prescale value is set to 1.

1 / 50 KHz = (PR2 + 1) * Tcy * (Timer 2 Prescale Value) 

20uSecs = (PR2 + 1) * 4 / 120MHz * (1) Solving this gives a PR2 value of 599

To obtain the resolution I have used the following formula:
1 / 50 KHz = PWM Resolution * 1/120MHz * 1

Working this through gives a resolution of 2400 steps or 11.23Bits So by my reasoning if I set the period register to 599 and the duty cycle to 2400 I should get a 50KHz square wave with a hundred percent duty cycle. However, I get nothing of the sort. In fact I cannot even get a square wave to oscillate at any frequency with any duty cycle. I am worried that the problem may be “oscillator related” as the CCS PCD compiler seems to prevent me from setting certain oscillator fuses on the DSPIC30F2011 (for example HS and XT). When I use #fuses it does not seem to set the correct configuration bits. Is this a known problem?

I am using the CCS C Compiler and the code is below. Are there any problems with the code below?

#include <30F3012.h>
#use delay(clock=120000000)

 while (1)
    setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);

    setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1,599);  // SHOULD GIVE 50KHz assuming 120MHz Oscillator

    set_pwm_duty(1, 2400);  // Setup for 100% duty cycle


Any help or advice would be much appreciated.
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