PDA

View Full Version : analog to digital setup on 18F2550



missouri100
- 8th February 2014, 21:09
below is the setup portion of some code down the the ADCIN, adval1 command. the digital value is used to turn on 10 leds as a binary representation of adval1. num is set equal to adval1 and displayed as a binary number using LEDs. that part is farther down the program on not included. We had it working before connecting the potentiometer.

It appears that we don't have a proper analog reference. We want to use the Vss as the ref. We have bits 4 and 5 set to 0 which should make it use Vdd and Vss. The reason for thinking it is the setup is the LED's light but not correctly.

Can one of you experts please review our setup and tell us if we have it set up the way we think we do?

thanks

************************************************** ************************************************** ***********

'Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 100 ' Set sampling time in uS

'define hpwm parameters
DEFINE CCP1_REG PORTC 'Hpwm 1 port bit
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE HPWM1_TIMER 1 'Hpwm 1 timer select
DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
DEFINE CCP2_BIT 1 'Hpwm 2 pin bit
DEFINE HPWM2_TIMER 1 'Hpwm 2 timer select

DEFINE OSC 8

TRISA = %11111111 'in,in,in,in,in,in,in,in
TRISB = %00000000 'out,out,out,out,out,out,out,out
TRISC = %00000000 'out,out,out,out,out,out,out,out
OSCCON = %01110010
ADCON0 = %00000101
ADCON1 = %00001101

out1 VAR PortC.6
out2 VAR PortC.7
out4 VAR PortB.0
out8 VAR PortB.1
out16 VAR PortB.2
out32 VAR PortB.3
out64 VAR PortB.4
out128 VAR PortB.5
out256 VAR PortB.6
out512 VAR PortB.7
adval1 VAR WORD
'adval2 VAR WORD
num var word

mainloop:

ADCIN 0, adval1
'ADCIN 1, adval2

Pause 10

num = adval1

.
.
.
.

missouri100
- 20th February 2014, 14:49
Just in case someone is having the same issue - - we resolved it by reversing the justification of the A to D conversion value. It can be left to right for 8 bit values but for a 10 bit conversion value it has to be right to left. I found one little sentence somewhere in my reading that said that and it worked. I don't even remember if it was the datasheet or not.