Created Mon, 12 Dec 2016 13:44:46 +0000 by Towan
Mon, 12 Dec 2016 13:44:46 +0000
Hello,
I would like to send analog output through PWM by using the OC1-port, where i have connected a summer that i would like to play a sound.
My code is as follows:
#include <pic32mx.h>
void genpwm(int dutycycle) {
PR2 = 255; // set period to 255+1 ticks = 78.125 KHz
OC1RS = dutycycle; // set duty cycle, switch tone with this
OC1CON |= 0x06; // set bits 0 through 2 to 0b110, setting the OC! to PWM-mode
T2CON |= 0x04000; // turn on timer 2 in default mode (20 MHz, 16 bit)
OC1CON |= 0x04000; // turn on output compare 1 module
}
int main(void) {
while(1) {
//PORTE = (PORTF >> 1) & 0x1;
genpwm(100);
}
return 0;
}
Could anyone please help me out? I have no clue what to do!
Mon, 12 Dec 2016 13:59:59 +0000
chipKIT doesn't use "main()" - it uses "setup()" and "loop()".
There is "analogWrite(...)" which generates PWM.
It looks like you aren't using the chipKIT software, but Microchip software. We cannot directly support Microchip software, you should seek help with their forums for that.
I will say, though, that you never need to keep PWM running by constantly calling the function. You call it once to start it going then just leave it running. Your genpwm() should be before your while loop, not in it.