PDA

View Full Version : Really simple test program not working.



jmgelba
- 24th October 2011, 17:40
18F2550 20mhz HSPLL set up for USB

PIC functions and pcb is fine. I can get a simple blinky light to work. I can get a correct ADC value to write to EEPROM and read through the programmer, but I cant get it compare the ADC value with the value stored in fb and turn on or off the LED as I vary the voltage in the ACD pin.

What the heck am I missing?


define OSC 48
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
raw var word
raw1 var word
fb var word
fb = 205
ADCON1 = 001011
ADCON2 = 000011


TRISA = 001111
TRISB = 110000
TRISC = 000000
PORTC.2 = 0


main:
pause 100
adcin 0, raw
raw1 = raw/10
if raw1 => fb then
Portc.0 = 1
else
portc.0 = 0
endif


goto main]

cncmachineguy
- 24th October 2011, 18:16
Max value for raw is 1024? assuming 10 bit a/d. 1024/10=102. this is ALWAYS less the 205. So you will never be able to turn on the LED. If its a 12 bit A/D, then IDK

jmgelba
- 24th October 2011, 19:27
You are correct and I did remove the /10.

However, the fix was left vs right justification of the result. It works as expected.