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 CCS Technical Support

PWM Trouble - PIC24EP512GU810 with CCS

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
affonso.industra



Joined: 31 Jan 2013
Posts: 6

View user's profile Send private message

PWM Trouble - PIC24EP512GU810 with CCS
PostPosted: Thu Mar 21, 2013 12:04 pm     Reply with quote

Hello,

I'm facing some troubles to put PWM module of PIC24EP512GU810 to work: it works fine, but I can't change its frequency!!

Here is the code:
Code:

#include <24EP512GU810.h>
#fuses HS,NOPROTECT,NOWDT, NOALTI2C2
#use delay(clock = 140000000, crystal=20000000)
#pin_select OC1=PIN_G15
...
main()
{
...
setup_compare(1, COMPARE_PWM_EDGE | COMPARE_TIMER2);
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 0xFFC0);
set_pwm_duty(1,32736);
   
while(1);
}

With this code I have a PWM with frequency of 1.069 kHz and duty = 50%. In fact the frequency is correct: (140 MHz / 2) * (1) / (65473) = 1.069 kHz (as measured with an oscilloscope).
I can change the duty from 0 to 100% and it works fine!

The problem is when I change the frequency: there is no effect on frequency when I change the period parameter of function setup_timer2. For example:
Code:
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 0x3326);

I expected to change the frequency to: (140 MHz / 2) * (1) / (13095) = 5.346 kHz. But, in fact, I continue having a frequency of 1.069 kHz, like if this modification doesn't take any effect (the modification in the period from 0xFFC0 to 0x3326 doesn't take any effect).

I think that the period parameter of setup_timer2 is not working and timer2 is running like if period always was 0xFFFF.

I tried to change a lot of parameters, but it's been impossible to change the frequency of this PWM...

I'm using the version 4.136 of PCH/PCD CCS compiler.

Could anybody help me, please?

Best Regards,

Alex
jeremiah



Joined: 20 Jul 2010
Posts: 1346

View user's profile Send private message

PostPosted: Thu Mar 21, 2013 1:39 pm     Reply with quote

At a glance (since you didn't post any code that creates the issue), setting the new frequency like that won't work like you expect. Your duty setting is higher than your period setting. Another thing is that you are setting up the output compare to not have any sync events. Some modules won't update to changes until the next sync event. Mind you, I have never used your specific chip...just experience from other ones. Also note that just because the chip datasheet says a particular value is the default for a register, the compiler may choose a value of 0 for some fields if you don't explicit call them out in the setup function).

You should really take a look at the family manual for output compare (section 13). It isn't part of the main data sheet, but is downloadable from the chips page on the microchip website (in the documents section). There may be some other settings (or another configuration completely) you need to figure out if you are wanting to change things like frequency on the fly. Changing duty on the fly is much easier and only requires the set_pwm_duty() call (which changes OCxR). To change the frequency might require setting up a couple different registers (or the right parameters for setup_compare(). See the chip .h file for a list of those and compare to the datasheet).
affonso.industra



Joined: 31 Jan 2013
Posts: 6

View user's profile Send private message

PostPosted: Fri Mar 22, 2013 12:07 pm     Reply with quote

The problem was fixed using:
Code:
setup_compare(1, COMPARE_PWM_EDGE | COMPARE_TIMER2 | COMPARE_TRIG_SYNC_TIMER2);

The CCS support asked me to add COMPARE_TRIG_SYNC_TIMER2 and it works fine!

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