(edit sidebar)
Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


18 Fxx 20 Analog In

Tutorials.18Fxx20AnalogIn History

Hide minor edits - Show changes to output

Changed lines 3-4 from:
images/18F4520.jpg
to:
http://itp.nyu.edu/physcomp/images/18F4520.jpg
Changed lines 3-4 from:
%center%[[Attach:18F4520.jpg]]
to:
images/18F4520.jpg
Changed lines 3-4 from:
%center%[[Attach:18F4520]]
to:
%center%[[Attach:18F4520.jpg]]
Added lines 1-44:
The PIC 18F4520,  which Microchip intends as a replacement for the 18F452, has 13 analog in channels. The analog ins are on the pins marked AN0 through AN12, as shown below:

%center%[[Attach:18F4520]]

The analog configuration registers have changed as well.  ADCON1 is still the same, but ADCON1 is now used only to set which pins are analog and which are digital. A new register, ADCON2, sets the clock source and the time acquisition bits.  The code below works fine for reading an analog input on analog in channel 0.  It hasn't been tested yet for the other channels.

[@

'****************************************************************
'*  Name    : ADC in for 18F4520.BAS                                      *
'*  Author  : Todd Holoubek                                    *
'*  Notice  : Copyright (c) 2004 Todd Holoubel                  *
'*          : All Rights Reserved                              *
'*  Date    : 6/7/2004                                          *
'*  Version : 1.0                                              *
'*  Notes  :                                                  *
'*          :                                                  *
'****************************************************************
DEFINE OSC 4

start:

INCLUDE "modedefs.bas"
 ' Define ADCIN parameters
 ' Set number of bits in result
 DEFINE ADC_BITS 10
 ' Set clock source (3=rc)
 DEFINE ADC_CLOCK 3                                             
 ' Set sampling time in microseconds
 DEFINE ADC_SAMPLEUS 10
 ' Set PORTA to all input
 TRISA = %11111111
 'bit 7,  1 = right justify - bit 1 = all analog
 adcon2 = %10000010
 'define adc vars
 adcVar0 VAR WORD 'Create variable to store result

main:
    'read adc data, set to a variable "adcVar0"
    ADCIN 0, adcVar0
    'serout your var
    Serout2 portc.6,16468,[ DEC adcVar0,13,10]
GOTO main
@]
  Edit | View | History | Print | Recent Changes | Search Page last modified on November 18, 2005, at 10:16 AM