|
|
View previous topic :: View next topic |
Author |
Message |
soonc
Joined: 03 Dec 2013 Posts: 215
|
PIC24 and set_pwm_duty() |
Posted: Mon Sep 14, 2015 7:55 pm |
|
|
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
|
Problem Solved |
Posted: Sun Oct 04, 2015 10:52 am |
|
|
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. |
|
|
|
|
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
|