Tut 6 : Analog to Digital Conversion ADC

Analog to digital conversion (ADC) is necessary when dealing with analog values, they need to be converted to digital values so that the PIC may understand the signals. The signals typically involve many analog signals such as, temperature, speed, pressure, the output of a microphone, etc. Below, we will see how to read an external analog signal using a PIC microcontroller and display the conversion output (a digital number) on a bargraph LED. The input analog signal will be a varying voltage between 0-5V derived using a potentiometer. The output will be the equivalent signal shown in 8-bit binary sequence. The minimum output is 0 (binary 00000000) and the maximum output is 255 (11111111) as shown below.
Circuit Setup
PBP Program
' Example program to display analog value on bargraph LED

DEFINE OSC 20
   @ device hs_osc  'jika guna crytal 20Mhz

' -----[ Define ADC ports]-----------
define adc_bits 8       'define number of bits in result
define adc_clock 3      'clock source3=RC
DEFINE ADC_SAMPLEUS 50  'set delay 50us for every adc inputs

TRISB=0

'Allocate variables
x VAR Byte
ADCON0 = %10000010
ANSEL = 000001
  
loop:
 
ADCIN 0, x           ' Read voltage of the voltage sensor circuit port A.0 ,voltage divider pot 5k
PORTB=x
Pause 10

GoTo loop             ' Do it forever
End

No comments:

Post a Comment