Hello all,
I've never played around with PWMon the pic24, so I've taken a look at the data sheet and came up with the below code, but I can't seem to obtain the output. I have a scope and I'm using the explorer 16 to see if I can get this working. The code compiles ok. I'm using the FRC as main clock signal, don't think this should be a problem. I'm trying to generate a 5KHz signal, but don't really understand how the values for OC1R = 1000;
OC1RS = 2000; should be set.
I've never played around with PWMon the pic24, so I've taken a look at the data sheet and came up with the below code, but I can't seem to obtain the output. I have a scope and I'm using the explorer 16 to see if I can get this working. The code compiles ok. I'm using the FRC as main clock signal, don't think this should be a problem. I'm trying to generate a 5KHz signal, but don't really understand how the values for OC1R = 1000;
OC1RS = 2000; should be set.
Code:
#include <P24FJ256GB110.h>
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2 )
_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_NONE & FNOSC_FRC & DISUVREG_ON & IOL1WAY_ON & IESO_OFF)
//Fast Internal RC (FRC) Oscillator 8MHz Clock Source
main ()
{
TRISAbits.TRISA0 = 0x00;
PORTAbits.RA0 = 0x00;
RPOR15bits.RP30R = 1; //Comparator 1 Output to Pin RF2 PWM0
TRISFbits.TRISF8 = 0xFF; //Set RF8 as input
TRISFbits.TRISF2 = 0x00; //Set RF2 as Output for PWM0
void PWM0 (void)
{
OC1CON1 = 0;
OC1CON2 = 0;
OC1CON1bits.OCTSEL = 0x07;
OC1R = 1000;
OC1RS = 2000;
OC1CON1bits.OCM = 6;
}//endPWM0
//PWM0 ();
while (1)
{
if (PORTFbits.RF8 == 1)
{
PORTAbits.RA0 = 0xFF;
}
else if (PORTFbits.RF8 == 0)
{
PORTAbits.RA0 = 0x00;
}
}
}