Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A to D

Status
Not open for further replies.

bigfarmerdave

New Member
I'm using the PICKIT 2 and demo board that came with it to write code for an analog to digital converter for my 16F690. A few questions... when I set the ADC_CLOCK to 3, it's using the pics internal clock source? I believe I've instructed the voltage reading to go into the register named voltage, correct? I'm also not clear on what is meant by the results being left justified or right justified, which from what I read is done by setting ADCON1 = 0 or 1. Now, I don't have an LCD to display my results but do have LEDS that I can use to indicate different voltages. With the code I have below, PORTC.2 goes high when my voltmeter registers .85 volts and goes low below .85 volts. PORTC.1 never does turn on. Also, I've specified to use 10 bits to store my result but when I try to compare "voltage" to a 10 bit number (rather than the 8 bits I show currently) it gives me a WARNING- NUMERIC OVERFLOW, VALUE TRUNCATED when I try to compile. Still learning guys... sorry for all the questions.


Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

voltage var word ' Create voltage to store result

TRISA = %11111111 ' Set PORTA to all inputs
ADCON1 = %1

Pause 500 ' Wait .5 second

loop: ADCIN 0, voltage ' Read channel 0 to voltage

if voltage < 00011111 then
high PORTC.1
LOW PORTC.2
ENDIF
IF VOLTAGE > 00011111 THEN
LOW PORTC.1
HIGH PORTC.2
ENDIF

Pause 1000 ' Wait 1 second

Goto loop ' Do it forever
End
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top