|
|
View previous topic :: View next topic |
Author |
Message |
Andrew76 Guest
|
PIC24F PWM |
Posted: Wed Mar 25, 2009 3:45 pm |
|
|
I everyone,
I'm trying to work with PIC24F and PWM module.
What I would like to do is to control the frequency and the duty cycle of the PWM.
My code is the following:
Code: |
#pin_select OC1 = PIN_B6
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1);
set_compare_time(1, 0x1FFFF);
set_pwm_duty(1, 200);
setup_compare(1, COMPARE_PWM | COMPARE_TIMER2 |
Something works but not as I intend.
The frequency and the duty cycle still remain always the same.
I've checked PR1 register and it's always on 0xFFFF
Even changing manually, it returns to this value.
So, if I want to change frequency, I'm not able.
About the duty cycle, the register OC1R still remain at the same value and doesn't change even if programmed.
Manually same strange thing: the system doesn't change that value.
How can I do?
What's wrong with his PWM? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Mar 25, 2009 5:51 pm |
|
|
You should be aware of possible bugs with PCD built-in functions, there have been already quite a lot. Unfortunately I didn't use PWM and only basic timer functions with PIC24 up to now |
|
|
Andrew76 Guest
|
|
Posted: Thu Mar 26, 2009 2:10 am |
|
|
Thanks!!! |
|
|
jordanPSI Guest
|
Re: PIC24F PWM |
Posted: Thu Aug 20, 2009 9:47 am |
|
|
Andrew76 wrote: |
My code is the following:
Code: |
#pin_select OC1 = PIN_B6
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1);
set_compare_time(1, 0x1FFFF);
set_pwm_duty(1, 200);
setup_compare(1, COMPARE_PWM | COMPARE_TIMER2 |
Something works but not as I intend.
The frequency and the duty cycle still remain always the same.
|
I had the same issue with the PIC24FJ256GA106.
Try something like this:
Code: | setup_timer2(TMR_INTERNAL | TMR_DIV_BY1);
set_pwm_duty(1,200);
setup_compare(1, COMPARE_PWM_EDGE | COMPARE_TIMER2 | COMPARE_TRIG_SYNC_TIMER2); |
The part I was missing was the "COMPARE_TRIG_SYNC_TIMER2". |
|
|
|
|
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
|