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

SOLVED: Strange PWM behaviour

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



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

SOLVED: Strange PWM behaviour
PostPosted: Sat Feb 08, 2014 6:38 am     Reply with quote

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? Confused

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: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 7:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 7:14 am     Reply with quote

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: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 7:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 7:40 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 7:42 am     Reply with quote

Maybe I should just mentioned that Pin 3 and 4 are tied together, I do not see an issue with this, but just MAYBE Surprised

Regards
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 7:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 8:12 am     Reply with quote

On Pin 3: RPI47/T5CK/RB15
On Pin 4: RP118/RG6

Anyway I cut the tracks, no difference. Crying or Very sad

Regards
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 9:44 am     Reply with quote

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: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 10:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 08, 2014 11:05 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 03, 2014 4:38 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 04, 2014 3:31 am     Reply with quote

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