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

PIC24F PWM

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







PIC24F PWM
PostPosted: Wed Mar 25, 2009 3:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 5:51 pm     Reply with quote

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







PostPosted: Thu Mar 26, 2009 2:10 am     Reply with quote

Thanks!!!
jordanPSI
Guest







Re: PIC24F PWM
PostPosted: Thu Aug 20, 2009 9:47 am     Reply with quote

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".
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