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

Changing PWM frequency

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







Changing PWM frequency
PostPosted: Mon Nov 08, 2004 5:32 pm     Reply with quote

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
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 08, 2004 6:09 pm     Reply with quote

Edit - nevermind, thought you wanted duty. Kid is calling, gotta go
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 09, 2004 7:39 am     Reply with quote

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
Code:

PR2 = pwm_period;


Of course you will need to define the PR2 register according to then chip that you are using.
swong
Guest







PostPosted: Tue Nov 09, 2004 1:23 pm     Reply with quote

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
Code:

PR2 = pwm_period;


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:

Code:

PR2 = 39;


Looking at the LST file the PR2 does get written in both cases. The only difference is:


    movf pwm_period, W

    and

    movlw 0x27
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 09, 2004 2:21 pm     Reply with quote

Post a small sample program and I'll test it for you.
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