PDA

View Full Version : analog inputs on 16F716



schwinn_rider
- 5th October 2005, 20:22
Hi all,

I'm trying to do a row-column setup of analog inputs with the 16F716, and send the analog values out through serial. My problem is pretty basic though-I'm just not sure how to set up analog input on this chip. WHen I compile I get the following errors:

Symbol not previously defined (ADRESH)
Symbol not previously defined (ADRESL)

Here's the code:
<CODE>
' set up constants to use in the code
numRows con 4 ' number of rows
numCols con 4 ' number of columns
colOffset con 0 ' first column pin in column port
' set up variables:
rows var byte ' the row counter
cols var byte ' the column counter

' set up ADC parameters
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 20

' set up ADC variables
ADCVar var word

' set pins RA0-RA3 as input :
TRISA = %00001111
' set pins RB0-RB3 as output (and RB6 as output for serial comm.):
TRISB = %10110000
' set adcon?

ADCON0 = %10000010 ' set porta analog and right justify result
Pause 500

main:

'send out a message showing that this is the beginning of the loop
Serout2 portb.6, 16468, ["end of loop", 13, 10]

' loop over the columns, turning on one at a time
for cols = 0 to 3
' set this column high to check the switches in it:
PORTB = 1 << cols
' loop over the rows, reading one switch at a time:
for rows = 0 to 3

' read the analog value in
adcin 0, ADCVar

' send the value out through serial
Serout2 portb.6, 16468, [DEC ADCVar, 13, 10]
next
'set this column low to prep for the next column loop:
PORTB = 0
next


goto main
</CODE>

Any clues on how to set up the analog input stuff? I'm pretty new at this, but i have done similar things on other chips.

Thanks,

Matt

Bruce
- 5th October 2005, 21:16
You can only instruct PBP to use "10-bit" A/D resolution on a target with a 10-bit A/D module.

Try changing to 8-bit, and see how it works...;o}

CocaColaKid
- 5th October 2005, 21:20
Your trying to configure the chip for a 10-bit converter when it only has an 8-bit.

schwinn_rider
- 6th October 2005, 04:07
that did it. thanks!