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

dsPIC33EP256Mu806 PWM or DAC how

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



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

dsPIC33EP256Mu806 PWM or DAC how
PostPosted: Sun Jun 01, 2014 6:52 pm     Reply with quote

CCS C 4.130

i went through the wizard: and it created something, but doesn't compile

now the thing is, i cant for the life or me work out the code to setup TWO PWM outputs!??

33EP256Mu806

Code:

#include <main.h>


#PIN_SELECT   OC1 = PIN_F0

void main()

 setup_compare(1,COMPARE_PWM | COMPARE_TIMER2 );
   setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1,0 );

   setup_spi( FALSE );
setup_spi2( FALSE );


//setup_dac(DAC_RIGHT_ON, 5);

   


   setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);



   for(;;){
      output_high(E1);
      delay_ms(500);
      
      output_Low(E1);
      delay_ms(500);
   }

}


bit of a fail for compiling :(

its a really really basic code, just to being the Hello-world function...
not working :(
dyeatman



Joined: 06 Sep 2003
Posts: 1937
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Jun 01, 2014 8:55 pm     Reply with quote

Where are the contents of main.h?

We need to see all the code if you cant get it to compile so we can test it
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19554

View user's profile Send private message

PostPosted: Mon Jun 02, 2014 6:34 am     Reply with quote

Depending on what frequency you want (using 0 for the timer will give you a very low frequency), you need something like:
Code:

#pin_select OC1=PIN_F0
#pin_select OC2=PIN_F1

   setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 500);

   setup_compare(1, COMPARE_PWM_EDGE | COMPARE_TIMER2);
   set_pwm_duty(1, 250L);
   setup_compare(2, COMPARE_PWM_EDGE | COMPARE_TIMER2);
   set_pwm_duty(2, 250L);

If you want different frequencies, then use a second timer.

Dyeatman's comment is exactly right. The general rule is that what you post should be compilable, or what you are trying to compile. Otherwise we have no hope of knowing what the problem is.

Your compiler is rather early for the chip, so there might well be problems with some functions.
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

Thank you
PostPosted: Tue Jun 03, 2014 7:06 am     Reply with quote

Is that ALL you need to do??

a pin select??

OHHHH setup_compare(1, compare_pwm_edge)...... im used to see

OHHHH setup_compare(1, compare_pwm | .....)...... im used to see

Whoohoo.. thought i bought a bunch of chips that couldn't cope with it (concerned as dsPIC depicts a Digital audio out stuff! hehe)


Thank you Ttelmah Smile
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