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

PIC24 and set_pwm_duty()

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PIC24 and set_pwm_duty()
PostPosted: Mon Sep 14, 2015 7:55 pm     Reply with quote

The code below produces approximate 4kHz with 50:50 duty cycle.

Adjusting duty with: set_pwm_duty(1, n); does change the duty cycle.

It is possible to adjust 50 to 1 but never 50 to 99 if that makes sense!

What do I need to do to get full 1 to 99 duty cycle change ?

Thanks for any feedback.

Code:

// compiler V5.049
#include <24FJ128GA306.h>
#use delay(clock=29491200, crystal=7372800)

#pin_select OC1 = PIN_D0

void SetUpPWM1()
{
   setup_timer3(TMR_INTERNAL | TMR_DIV_BY_1, 3674);
   setup_compare(1, COMPARE_PWM_CENTER | COMPARE_TIMER3 | COMPARE_SYNCHRONIZE | COMPARE_TRIG_SYNC_TIMER3);
   set_compare_time(1, 1819, 1855);
   set_pwm_duty(1,900); // set 50% duty
}
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Problem Solved
PostPosted: Sun Oct 04, 2015 10:52 am     Reply with quote

I found the #use PWM after upgrading to Compiler V 5.050

#use PWM ( PWM1, OUTPUT=PIN_D0, TIMER=3, FREQUENCY=4000, PWM_ON)

Then use:

set_pwm_duty(1, value);

For my setup the duty cycle can now be fully adjusted.
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