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

PIC33EP512MU810 PWM Module

 
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

PIC33EP512MU810 PWM Module
PostPosted: Tue Jul 16, 2013 2:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 4:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 4:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 4:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 18, 2013 1:57 am     Reply with quote

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