Hi,

I am having a bit of difficulty understanding the results of the program below. The WORD adval is intended to be the 10-bit output of the ADC (1st line after loop). I then want to display it on HyperTerm as a digital word (next line). It is my understanding that placing # before adval, i.e., #adval, automatically converts adval into digital ASCII characters in the SEROUT command. For example, if adval = 827, SEROUT with #adval would (should) send "8","2","7".

Consequently, I expected to observe values on the screen ranging from 0 to 1023 since adval is a 10-bit word, but instead I see values ranging from 0 to over 12300.

I believe it is correct to right justify the upper 2 bits of adval by setting bit 7 of ADCON1 to 1.

Any ideas what I am doing wrong please?

Thanks,
Barry

' PIC16F819
' ---- ---------
' RB1 Max232(RX)
' RB2 Max232(TX)

' -----[ Includes/Defines ]---------------------------------------------------------
'
include "modedefs.bas" 'include serout defines
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 0 ' Set clock source to high speed
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
define OSC 16

' -----[ Variables ]-------------------------------------------------------
'
RX var byte ' Receive byte
adval var word ' vakue read of reverse power
adcnt var byte 'counter of number of samples taken
period var word ' sets the time between samples
' -----[ Initialization ]--------------------------------------------------
'
Init:
TRISB = %00000010 'All port b output except pin 1 (RX) is input
PORTB = %00000000 'Initialize PortB to all zeros and LED to off
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %100000010 ' Set PORTA analog; MSB = 1 --> right justify adval
period = 100 ' initial period = 100 ms

' -----[ Main Code ]-------------------------------------------------------
'
main:
' ****** [Menu setup on PC screen] *************************
serout 2, T2400, ["Press 1 to Start", 10, 13] 'Display action on PC screen

serin 1, T2400, RX 'Receive action request
RX = RX - $30 'Convert ASCII number to decimal
If RX <> 1 then Error 'Test for good value
adcnt = 0
serout 2, T2400, ["Sample period is ",#period," ms", 10, 13]
serout 2, T2400, ["Press 1 to Accept or 2 to Change", 10, 13]
serin 1, T2400, RX 'Receive period question response
RX = RX - $30 'Convert ASCII number to decimal
If RX > 2 then Error 'Test for good value
if rx = 1 then goto loop
serout 2, T2400, ["Enter new sample period in tenths of a second (2 = 200 ms)", 10, 13]
serin 1, T2400, RX 'Receive new period value
RX = RX - $30 'Convert ASCII number to decimal
period = RX*100 ' new period in milliseconds
If RX > 9 then Error 'Test for good value
loop:
ADCIN 1, adval ' Read channel 1 to adval
serout 2, T2400, [#adval, 10, 13] 'Display adval on PC screen
adcnt = adcnt +1
if adcnt = 100 then end

Pause period 'wait "period" milliseconds
goto loop

Error:
serout 2, T2400, ["error", 10, 13, "Try again", 10, 13]
goto main

end