Hi Rob,
After your post I looked even further, I use the latest adc lib and tested the first 10 adc channels. they work all the time, and are relatively accurate. I also looked at the adc_clock lib and tried to adjust the code. The 18857 only has 1 clock selection bit "FRC or crystal controlled" , but it didn't work yet. For now, I'm happy with the result.
Here's a piece of the program I used.
const bit ADC_HIGH_RESOLUTION = true
const byte ADC_NCHANNEL = 2
const byte ADC_NVREF = ADC_NO_EXT_VREF
include adc
adc_init()
var word measure
var word voltage
var byte lowmeasure
const byte prefix[] = "Channel "
const byte highstr[] = " (high) "
const byte lowstr[] = " (low) "
const byte suffix[] = ": "
const byte value[] = " U = "
const byte units[] = " Volts."
forever loop
var byte channel = 0
-- loop over all channels and read
led = !led
for 11 using channel loop
-- get ADC result, high resolution
measure = adc_read_high_res(channel)
-- send it back through serial
print_string(serial_hw_data,prefix)
print_string(serial_hw_data,highstr)
print_byte_dec(serial_hw_data,channel)
print_string(serial_hw_data,suffix)
-- print_word_bin(serial_hw_data,measure) ; this one works !
print_word_dec(serial_hw_data,measure) ; I should get ~512
voltage = measure * 0.4883 -- 5 V / 1024 * 100 (for 2 decimals)
print_string(serial_hw_data,value)
--print_word_dec(serial_hw_data,voltage)
--print_string(serial_hw_data,value)
format_word_dec(serial_hw_data,voltage,5,2) -- decimal 2 = /100
print_string(serial_hw_data,units)
print_crlf(serial_hw_data)
delay_1ms(250)
-- Even if we set high resolution, we can still access results
-- in low resolution (the 2 LSb will be removed)
lowmeasure = adc_read_low_res(channel)
print_string(serial_hw_data,prefix)
print_string(serial_hw_data,lowstr)
print_byte_dec(serial_hw_data,channel)
print_string(serial_hw_data,suffix)
print_byte_dec(serial_hw_data,lowmeasure) ; I should get ~127
print_crlf(serial_hw_data)
-- and sleep a litte...
--led = OFF
delay_1ms(2500)
end loop
end loop
Kind regards Bill.