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.

Pic18f4520 adc programming problem

Status
Not open for further replies.

elvinng

Newbie level 1
Joined
Mar 4, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
Hi, all.. I am a newbie in PIC programming.. i nid help for project which require me to do ADC conversion from strain gauge sensors and analyse the signal..

Details: PIC18F4520, MPLAB, C programming code, datasheet..
note: i will use 2 sensors, so i nid to do assign 2 analog input..

MY questions: 1) any similar c programming code can be provided as example?
2) for 2 analog input, ADCON0 & ADCON1 both can assign analog
input, but how come i have select 1 channel in ADCON0 and i oso nid to select channel input in ADCON1??
3)Besides, from researching (the PIC18 can only convert one channel at a time.) so how should i do this if i apply force to both sensor?
3) after conversion, that is 10bits binary data rite? and how should i relate that to how much force i have applied to sensors?





//===============configuration==============================
;XTAL = 20MHz

#pragma config PLLDIV = 5 //This value has to be 5 for 20Mhz xtal as PLL accepts fixed input of 4MHz only
#pragma config OSC = HS, OSCS = OFF
#pragma config BORV = 45, PWRT = ON, BOR = ON
#pragma config WDT=off //disable Watchdog timer for resetting PIC
#pragma config DEBUG = OFF, LVP = OFF, STVR = OFF



#include <pic.h> //pic cpu header file
#include <18f4520.h>
#include <adc.h>


void Adc_Initial(void)
{
ADCON0 = 0x01; //channel 0(AN0), A/D module is enabled.
ADCON1 = 0x0B; //analog input: AN0-AN3, others digital I/O
TRISA = 0X0F; //make RA0-RA3 as sensor signal input
TRISB = 0X00; //make PORTB as output
ADCON2 = 0x8A; //Fosc/32, right justified, 2Tad
ADCON0bit.GO_DONE = 1; //start the conversion
}

Here is my code which have not yet done since i dunno how to move on, pls teach me !!! I am very nervous for this :? Appreciate much if this forum could help me..
Thank you in advance!!!!!!!!!!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top