PDA

View Full Version : ADCON does not compile 16F628



mslaney
- 14th January 2005, 13:27
Hi there,
Maybe you've [seen this/done this/fixed this...]

PIC16F628
If I try to compile with ADCON:
symbol priviously undefined ADCON0 and GO_DONE

If I try without ADCON: syntax error

There is no reference to adcon in the datasheet.
CMCON does nothing for me either.
If the ANx pins are powered up as comparators, how do I set them to analog inputs to read a pot? Yes, I made an honest attempt at the datasheet.

CODE:

'Read a POT on AN0
'Code converted from F876 to F628 to test ICD with realtime input

'DEFINES
Define ADC_BITS 8
define ADC_CLOCK 30
define ADC_SAMPLEUS 50
define OSC 4
define ADCON1
cmcon = %00000001

'VARIABLES
adval var byte
v_in var byte

Init:
portb = $00
trisb =$0
v_in = porta.1

Main:
trisa = %00000001
trisb = %11111111


loop:
adcin v_in,adval 'Read channel 0 adval

ledtst1:
if adval > 5 then tst2
portb = %00000001
goto cont

tst2:
if adval > 10 then tst3
portb = %00000011
goto cont

tst3:
if adval > 20 then tst4
portb = %00000111
goto cont

tst4:
if adval > 40 then tst5
portb = %00001111
goto cont

tst5:
portb = %00011111

cont:
pause 100
goto loop
end

mister_e
- 14th January 2005, 15:04
there's a simple answer to this. There's no analog to digital converter in the PIC16F628. You have only analog comparator. Wich is a big difference. This is also why you have those error message. If you want some PIC with analog to digital converter you may use the following
PIC16F877,876...
PIC12F675,683
PIC16F819
and many others.


BTW if you want to have a POT reading, there's a function called POT or RCTIME that allow to do something like this in addition of one capacitor. Inputs must be set to digital to perform those statements. CMCON=7

See PBP manual or Melabs website for some code examples.

Archilochus
- 14th January 2005, 15:07
Hi Mike,
As far as I remember the 16F628 does not have an ADC.

It does have comparators - there is a fine tutorial by Melanie either here or on the PicBasic list about using the comparators (search function available at www.melabs.com).

Arch

mslaney
- 14th January 2005, 15:43
Yes, you're right. I have mistaken pins RA0,1,2,3 / "AN0,1,2,3" for analog inputs rather than analog comparators. Doh!

Thanks for the confirmation.