View previous topic :: View next topic |
Author |
Message |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
SOLVED: Strange PWM behaviour |
Posted: Sat Feb 08, 2014 6:38 am |
|
|
Hi All
dsPIC33EP64GP506
5.017
I set up the PWM to run 50kHz 10% dutycycle, all work OK. PWM 50kHz with 10% duty.
However it only run for 7.5ms then output are low for 7.5ms and then repeat this pattern.
Any idea?
Code: | #include <33EP64GP506.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#define CLK_FREQ 20000000
#use delay(internal=CLK_FREQ)
#include <stdint.h>
#define LED_GREEN PIN_A8
#define LED_RED PIN_D6
//Setup PWM Boost for Display
#use PWM(PWM1,OUTPUT=PIN_G6,TIMER=3,FREQUENCY=50KHz,DUTY=10,STREAM=DISPPWM)
uint16_t LEDTime;
#INT_TIMER1
void timer1_isr(void) {
if (LEDTime++ > 500) {
LEDTime = 0;
output_toggle(LED_RED);
}
}
void main() {
setup_timer1(TMR_INTERNAL | TMR_DIV_BY_1, 10000); //2ms Timer
enable_interrupts(INT_TIMER1);
enable_interrupts(INTR_GLOBAL);
while(TRUE) {
}
} |
Regards
Last edited by alan on Sat Feb 08, 2014 9:38 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Feb 08, 2014 7:03 am |
|
|
hmm..my first thought was that the WDT is enabled, but fuse say nowdt....
maybe a 'brownout' fuse is enabled and Vcc < threshold ?
the 7.5ms rate seems too 'nice'.
I know you don't want to 'step back' but I'd try the '1Hz flashing LED' program with NO ISRs and see what happens.
hth
jay |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Feb 08, 2014 7:14 am |
|
|
Thanks Jay for feed back
1Hz work fine with no interrupts. I also added a delay of 2 sec on start-up to see check whether it is not a restart. Get the delay on startup and then 1Hz on LED.
What I did notice, that sometimes after a reprogram it seems to be about 14ms instead of the 7ms, but when I cycle power it is back on the approx 7.5ms, actually it varies from 7.4 to say 7.7ms.
Regards
Alan |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Feb 08, 2014 7:35 am |
|
|
rats, so much for the 'easy' stuff!
If using MPLAB, any chance you're compiling in 'debug' mode and not 'release'?
That can cause 'odd' things to happen....
jay |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Feb 08, 2014 7:40 am |
|
|
Just to be sure, I disconnect the programmer after programming and the issue are still the same.
Regards
PS I have to use MPLAB and ICD3 as CCS are still beta for this chip. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Feb 08, 2014 7:42 am |
|
|
Maybe I should just mentioned that Pin 3 and 4 are tied together, I do not see an issue with this, but just MAYBE
Regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Feb 08, 2014 7:58 am |
|
|
hmm..I don't use them 'fancy PICs', but perhaps there's a peripheral that needs to be disabled also don't know what's on pins 3 or 4....
hth
jay |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Feb 08, 2014 8:12 am |
|
|
On Pin 3: RPI47/T5CK/RB15
On Pin 4: RP118/RG6
Anyway I cut the tracks, no difference.
Regards |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Feb 08, 2014 9:44 am |
|
|
OK manage to get it working by writing directly to the registers.
Could not use the setup_compare function as the PWM does not use the TIMERS on this specific chip. And the USE PWM also want to specify a TIMER
by just adding the following it worked like a charm.
Code: |
#WORD OC1RS = getenv("SFR:OC1RS")
#WORD OC1CON1 = getenv("SFR:OC1CON1")
#WORD OC1CON2 = getenv("SFR:OC1CON2")
OC1CON1 = 0x1c06;
OC1CON2 = 0x001f;
OC1RS = 200; //Period: 50kHz = 1/50e3 * 1/Tcy
set_pwm_duty(1,20); //10% DutyCycle
|
Also although the datasheet specify that 0x1f are the same as 0x00 when specifying the SYNCSEL bits it does not work on 0x00.
Regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Feb 08, 2014 10:36 am |
|
|
hmm.. well I'm glad someone is winning today !!!!
sounds like a compiler 'bug', easier to deal with tahn -19*C weather I'm in !!
cheers
jay |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sat Feb 08, 2014 11:05 am |
|
|
Nice 28*C here.
Anyway here are an update involving less register manipulation.
Code: | setup_compare(1, COMPARE_SYSTEM_CLOCK | COMPARE_PWM_EDGE );
set_compare_time(1,20,200); //PWM no, Duty, Period
OC1CON2 = 0x001f; //Datasheet fault
|
Regards
Alan |
|
|
arocholl
Joined: 14 Dec 2008 Posts: 21
|
|
Posted: Thu Apr 03, 2014 4:38 pm |
|
|
Hi Alan, do you mind adding the full code you ended up with? I am not sure to realize what you left and what you remove from the original post. I am having some trouble to get a DSPIC33EP to work with PWM.
thanks in advance. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Fri Apr 04, 2014 3:31 am |
|
|
I do not understand. That is the full code to get the PWM working. Do not use the #use PWM directive from CCS.
Are your PIC running the 1Hz LED test successfully?
Regards
Alan |
|
|
|