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.

How to configure Adc of pic18f4553

Status
Not open for further replies.

hayawana

Member level 1
Joined
Apr 10, 2013
Messages
35
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,524
Hi everyone,

I'm working on PIC18F4553 on Digital Analog Converter(12-bit converter), and I use a 20MHz crystal.

The result is contained in two registers ADRESH and ADRESL.I have read the datasheet but I still do not see how to display the result on the output pin of the µC.
I use mikroC, I send you attached the wiring diagram in proteus. I need some help with that :)

Here initialization:
/ / / / / / / / / Initialization / / / / / / / / / / / / / / / / / /
ADCON0 = 0x00, / / select channel AN0 using ADCON0 register
ADCON1 = 0x03 / / VSS, VDD, select AN0 as analog and digital as AN12
ADCON2 0xAD = / / Right Justified, 12TAD, 16TOSC
TRISA = 0xFF; / / set as inputs TRISA
TRISB = 0x00, / / set TRISB as ouputs
ADON_bit = 1 / / enable conversion

Thank you,
 

Attachments

  • PIC_adc.png
    PIC_adc.png
    31.3 KB · Views: 69

oh my bad i thought i could use the RB0 pin as an analog output this is my first mistake. but still dont know how to conversion.

- - - Updated - - -

oh my bad i thought i could use the RB0 pin as an analog output this is my first mistake. but still dont know how to conversion.
 

Hi,

thank youu but i dont want to display the result :) . I want to transfer it through USB and UART. I have 6 channels to convert then transfer. Any ideas please?
 

thank you.

ANY IDEAS about converting 6 channels using interruptions?
 

You mean 6 Channel ADC using ADC interrupts? Only one channel is read at a time. You can use ADC interrupts. When ADC Conversion is complete ADIF bit is set.
 

YES so he will read the first one when he finishes and send the adif flag he could start the other one?
 

When one conversion is completed which you check by if ADIF is set or not then save the result to a variable and then start second conversion and repeat for all the adc inputs you want to convert.
 

thank you . i also need to know how can i do to transfer the result 12 bits to UART 8 bits ?
 

Hello, thank you very much for your answers

But I'm really bad programming and I just started and I'm lost. But I still do not see how to convert at least two signals and transfer them to 12 bits, while the uart supports 8-bit, I put a small piece of code that may seem stupid to some:

void main()
{
/////////Initialisation//////////////////
ADCON0=0x00; //select AN0 canal using register ADCON0
ADCON1=0x00; //VSS,VDD, select AN0
ADCON2=0xAD; //Right justified, 12TAD, 16TOSC
TRISA=0x01; // set trisA as inputs
TRISD=0x00; // set trisD as ouputs
TRISC=0x00; // set trisD as ouputs
ADIF_bit=0;
ADON_bit=1; // enable conversion
while(1)
{
conversion1 = ADC_Read(0); // Read analog value from channel 0
//conversion =0x0FA5;
PORTD= (char) conversion1;
Delay_Cyc(10);
/*ADIF_bit =1; // set flag adif
ADCON0=0x01; //select AN1 canal using register ADCON0
conversion2 = ADC_Read(1); // Read analog value from channel 0
//conversion =0x0FA5;
PORTC= (char) conversion2;*/
 

if conversion - 0x0FA5;
then
lsb = (unsigned char) (conversion & 0x00FF);
msb = (unsigned char) ((conversion>>8) & 0x00FF);
 

If conversion1 is a int variable (16 bits wide) then add two char type variables lowbyte and highbyte.

lowbyte = conversion1; //puts the low byte of conversion1 into lowbyte
highbyte = conversion >> 8; //puts the high byte of conversion1 into highbyte

PORTC = lowbyte
PORTD = highbyte

UART1_Write(lowbyte);
UART1_Write(highbyte);
 

Thank you very much guys its very helpful. :-D
But can you show me an example of the conversion of 3 canals? how can i convert the first one then say ok its done convert the second one and so on?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top