Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

About A/D Module in PIC18F458

Status
Not open for further replies.

Sm.r.Tadayoni

Junior Member level 1
Joined
Jul 28, 2010
Messages
15
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,439
hi every body.
i have a problem about Analog to digital Processing in PIC18f458.
when i want to convert , the result is wrong, and its not work true.
this is my Code :

void set_registers(void)
{
// *********************** A/D Module **************

ADCON0bits.ADON = 1; // AD ON

ADCON1bits.ADCS2 = 1; // A/D Clock Source F_OSC/4
ADCON0bits.ADCS1 = 0;
ADCON0bits.ADCS0 = 0;

ADCON0bits.CHS2 = 0; // AD Port
ADCON0bits.CHS1 = 0;
ADCON0bits.CHS0 = 0;
ADCON0bits.GO_DONE = 1; // AD GO_DONE

ADCON1bits.ADFM = 1; // Justify


ADCON1bits.PCFG3 = 1; // PORTA --> DDDDA;
ADCON1bits.PCFG2 = 1;
ADCON1bits.PCFG1 = 1;
ADCON1bits.PCFG0 = 0;

}

unsigned float AtoD_Load(void)
{ unsigned float v_out;
unsigned int v_AD;

ADCON0bits.GO_DONE = 1;

while (ADCON0bits.GO_DONE);

ADCON0bits.GO_DONE = 0;

v_AD = ADRESH * 256 + ADRESL;
v_out = (v_AD * v_max) / 1024;

return v_out;
}

void filtering(unsigned float v_disired)
{ unsigned float dv, v_out;

TRISAbits.TRISA0 = 1;

v_out = AtoD_Load();

dv = v_out - v_disired;

if (v_out != v_disired) { while (v_out < v_disired) { CCPR1L++;
v_out = AtoD_Load();
}
while (v_out > v_disired)
{ CCPR1L--;
v_out = AtoD_Load();
}
}
}

and this is my PWM Code :

//*************************** PWM Module *******************
void PWM_Signal(unsigned float v_disired)
{ unsigned float dutycycle;
unsigned char n;

TRISCbits.TRISC2 = 0;

CCP1CONbits.CCP1M3 = 1; //PWM mode
CCP1CONbits.CCP1M2 = 1;

T2CONbits.T2CKPS1 = 0; // Timer2 : prescaler, 1:1
T2CONbits.T2CKPS0 = 0;

PR2 = 255;
dutycycle = (v_disired * 1024)/v_max;

CCPR1L = dutycycle/4; // PWM Dusty Cycle

n = dutycycle/256;
CCP1CONbits.DC1B1 = (n)/2;
CCP1CONbits.DC1B0 = (n)%2;

T2CONbits.TMR2ON = 1; // Timer2 ON

filtering(v_disired);
}
what should i do?

Thanks.
 

the result is wrong

what result?

you have to take a modular approach and try to isolate the problem.
 

thanks about your help, i found out my problem and solve it, i have a oscilloscope and it was not Calibration then it made me Wrong signal and wrong Voltage (Average Voltage).
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top