View previous topic :: View next topic |
Author |
Message |
swong Guest
|
Changing PWM frequency |
Posted: Mon Nov 08, 2004 5:32 pm |
|
|
Hi,
Try to change PWM frequency on the fly.
int pwm_period;
setup_timer_2(T2_DIV_BY_1, 39, 1); //this works
pwm_period = 39;
setup_timer_2(T2_DIV_BY_1, pwm_period, 1); //this doesn't
Am I doing something that can't be done?
Any help would be appreciated.
Using PCH version 3.174
Thanks in advance,
swong |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Nov 08, 2004 6:09 pm |
|
|
Edit - nevermind, thought you wanted duty. Kid is calling, gotta go |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Nov 09, 2004 7:39 am |
|
|
Didn't test using a variable for the setup_timer_2() function but I'll believe that it can't be done. The pwm_period as you call it is nothing more than the value in the PR2 register. So you could do this
Of course you will need to define the PR2 register according to then chip that you are using. |
|
![](templates/subSilver/images/spacer.gif) |
swong Guest
|
|
Posted: Tue Nov 09, 2004 1:23 pm |
|
|
Mark wrote: | Didn't test using a variable for the setup_timer_2() function but I'll believe that it can't be done. The pwm_period as you call it is nothing more than the value in the PR2 register. So you could do this
Of course you will need to define the PR2 register according to then chip that you are using. |
Try that and is doesn't work. And yes I have defined the PR2 register for the 18F252. And the following code does work:
Looking at the LST file the PR2 does get written in both cases. The only difference is:
movf pwm_period, W
and
movlw 0x27
|
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Nov 09, 2004 2:21 pm |
|
|
Post a small sample program and I'll test it for you. |
|
![](templates/subSilver/images/spacer.gif) |
|