Hello everyone, I’m trying to use the PWM module to generate a DC level depending on duty cycle, for example if my power supply is 0-5 Volts, then I expect a dc level equal to 2.5 volts when the duty cycle is 50%, what i did, was filtering the output with a first order RC filter using R = 39Kohm and C = 1uf, so the bandwidth would be 4Hz, I’m following the details describe in **broken link removed** , i put my code below:
#include <htc.h>
__CONFIG(1,WDTDIS & MCLRDIS & INTIO);
void init(void)
{
OSCCON=0b10011110; //internal,125KHz
TRISA=0b00000001; //Pin 2 as input RA0
ADCON0=0b00000001; //AN0 as analog channel, ADC enabled ADON=1
ADCON1=0b00001110; // reference voltage 0-5 v, AN0
ADCON2=0b00001100; // INternal clock, 2Tad ACQ, left justification
TRISDbits.TRISD2=0;
TRISCbits.TRISC2=0;
CCP1CON=0b00001100;//PWM mode 131ms PWM period
PR2=255;
T2CON=0b00000010; //timer2 off, prescaler is 16
PIR1bits.TMR2IF = 0;
}
void main(void)
{
init();
T2CONbits.TMR2ON=1;
for(;
{
ADCON0|=0X02;//the convertion starts
while(GODONE==1);
CCP1CONbits.DC1B1 =(ADRESL>>7);
CCP1CONbits.DC1B0 =(ADRESL>>6);
CCPR1L = ADRESH;
if(TMR2IF==1)
{
PIR1bits.TMR2IF=0;
LATDbits.LATD2^=1;
}
}
}
i used some stimulus (MPLAB SIM) and it seemed to work just fine, so my problem is that when i try to use the scope to check out the signal and the dc level while I’m varying the voltage in AN0 i don't see anything, i don't even see the PWM signal while the voltage is equal to 2.5 V in AN0 (the led placed on RD2 works ok), so by now Idk what could be my mistake, maybe i got the whole concept wrong, so i need your help guys, I’ll appreciate any help you can give me, thank you in advance.
Postdate: what is the difference between using FRC from either INTOSC/256 or INTRC directly??