View previous topic :: View next topic |
Author |
Message |
neochrome32
Joined: 09 Jun 2013 Posts: 153
|
dsPIC33EP256Mu806 PWM or DAC how |
Posted: Sun Jun 01, 2014 6:52 pm |
|
|
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: 1938 Location: Norman, OK
|
|
Posted: Sun Jun 01, 2014 8:55 pm |
|
|
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: 19559
|
|
Posted: Mon Jun 02, 2014 6:34 am |
|
|
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
|
Thank you |
Posted: Tue Jun 03, 2014 7:06 am |
|
|
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 |
|
|
|