View previous topic :: View next topic |
Author |
Message |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
PIC33EP512MU810 PWM Module |
Posted: Tue Jul 16, 2013 2:19 am |
|
|
I have difficulty setting up the PWM module on this chip.
When I use PCD 5.009 and the #use pwm(....) the module works fine and have the correct freq and duty. However there are other bugs in the compiler regarding displaying on my LCD and don't have time to chase them down right now.
So I revert back to 4.141 where I know my display are working and now the compiler give me an error of "Invalid pin" in setup_compare when trying to compile code below.
Code: |
#include <33EP512MU810.h>
#fuses NOWRT //Program memory not write protected
#FUSES NOWDT //No Watch Dog Timer
#fuses NOPROTECT //Code not protected from reading
#FUSES NOGSSK //General Segment Key bits, use if using both NOWRT and NOPROTECT fuses
#fuses FRC //Internal Fast RC Oscillator
#FUSES NOIESO //Internal External Switch Over mode disabled
//#fuses NOPR //Pimary oscillaotr disabled
#fuses NOBROWNOUT //No brownout reset
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOJTAG //JTAG disabled
#fuses NOAWRT //Auxiliary program memory is not write-protected
#fuses NOAPROTECT //Auxiliary program memory is not code-protected
#fuses NOAPLK //Auxiliary Segment Key bits, use if using both NOAWRT and NOAPROTECT fuses
#fuses NOPLLWAIT //Clock switch will not wait for the PLL lock signal
#define icd=3
#fuses ICSP3
#use delay(internal=20MHz)
#include <stdint.h>
void main(void {
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 0xFFC0);
setup_compare(1, COMPARE_PWM_EDGE | COMPARE_TIMER2);
}
|
Regards
Alan |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Jul 16, 2013 4:04 am |
|
|
It won't accept the module, till the pin is selected for it.
Best Wishes |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Tue Jul 16, 2013 4:27 am |
|
|
Hi Ttelmah
The PWM3L are not selectable as a PPS it is always on PIN_E4, that is why I did not specify a pin_select.
However when I specify OC3 to PIN_E4, compile are OK and PWM working.
In the mean time I got 5.009 working. Somehow an int8 are treated as unsigned in V4.141 and signed in V5.009. So just changed everything to uint8_t.
Thank you
Alan |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Jul 16, 2013 4:46 am |
|
|
I think that 'generically', the setup_compare won't work till the pin_select is seen for the module, even if not needed....
I knew it was the reason for your error message.
V5, is getting a little closer to being ANSI as default. Generically, this type of problem is 'why' I prefer to use the 'explicit' sizes and types, like uint8_t, unless sign would not matter.
Best Wishes |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Thu Jul 18, 2013 1:57 am |
|
|
Using V5.009. I have difficulty understanding the working of the following 2 commands:
Code: |
pwm_set_duty(PWM_BST,DutyCycle);
pwm_set_duty_percent(PWM_BST,DutyCycle);
|
pwm_set_duty_percent can take a value between 0 & 1000 corresponding to 0% and 100% in 0.1% increments.
However pwm_set_duty increment the duty cycle with 1% increments.
So
Code: | pwm_set_duty(PWM_BST,45) | are the same as
Code: | pwm_set_duty_percent(PWM_BST,450) |
According to the helpfile pwm_set_duty are faster than percent and the LST file confirm this.
I use the following setup for PWM.
#use PWM(PWM3,OUTPUT=PIN_E4,FREQUENCY=100kHz,DUTY=20,STREAM=PWM_BST)
Iwould like a little more control in the setting of the duty cycle. So can anyone explain why this is happening. Probably I am missing something or misinterpret the functions.
Regards
Alan |
|
|
|