|
AN200 |
PicStic
5 | |
Accessing the
10-bit and 12-bit ADC
|
December 4, 2001 |
Introduction:
This application note illustrates how to
access the internal 10-bit and external 12-bit ADC on the PicStic 5. | |
Background: The
PicStic 5 is equipped with a total of 6 channels for analog-to-digital
conversion. There are four 10-bit channels and two 12-bit channels. The
four 10-bit channels are supplied by the PIC16F876 processor. While the
PIC processor is equipped with five 10-bit channels, only four of these
channels are available on the PicStic 5. The two 12-bit channels are
available through a separate IC internal to the PicStic 5 but external to
the processor. Generally, the two main characteristics that are looked at
when choosing an ADC is speed and resolution. With the PicStic 5 both are
available. The two 12-bit channels give the user the great resolution at a
fast rate ( up to ~10K samples/sec). The four 10-bit channels give the
user good resolution at much higher data rate ( up to ~21K samples/sec).
The user has the choice of which ADC best suits the given
application. | |
How it
works:
The four 10-bit channels can be easily accessed through the
PicBasicPro command ADCIN.
There are only two steps that need to be followed before a 10-bit
channel can be sampled: 1.
The appropriate ADC pins need to be set as inputs. This is done
through the TRISA register. 2.
The pin function needs to be selected by setting the ADCON1
register. Once these two
steps are completed, the 10-bit channels can be sampled. The available
settings for the ADCON1 register are located on page 11 of the PicStic 5
data sheet. For a more detailed description of the ADCIN command please
refer to the PicBasic Pro Programmers Reference Manual.
The 12-bit
channels are accessed using a call routine that is included when a PicStic
5 program is compiled using PicBasic Pro. These routines were written and
incorporated into PicBasic Pro to simplify the use of the external ADC.
When a channel is ready to be sampled all that
needs to be done is to execute the call for that channel. The result will
be returned in the predefined variable PS5ADC. There are four different
routines that can be called to access the two 12-bit channels. These calls
are listed and described on page 14 of the PicStic 5 data sheet. | |
Program Listing: 1 of 2 ‘ This program will illustrate how to use
the two 12-bit channels of the PicStic 5. ‘ All four of the callable routines will
be executed to show their uses. ‘ The hardware serial port will be used to
display the results of the conversions on a PC. ‘ The hardware serial port
defaults to 8N1 @ 2400Bps. ANY_KEY
VAR BYTE
‘ program to read the A/D START:
HIGH
PORTC.1
‘ Enable the transmitter PAUSE
100
‘ Tenth sec pause to enable trans.
HSEROUT ["Verifying that the ADC call works.",13,10] HSEROUT ["Press any key to continue.",13,10] HSERIN [ANY_KEY]
‘ Wait for user to confirmation PAUSE
1000
‘ One second pause CALL
AIN5
‘ Sample channel 0 HSEROUT ["Channel 0 of the 1298 reads ", dec PS5ADC, 13,10]
PAUSE
1000
‘ Print results serially CALL
AIN6
‘ Sample channel 1 of LTC1298 HSEROUT ["Channel 1 of the 1298 reads ", dec PS5ADC, 13,10] PAUSE
1000
‘ Print results serially CALL
AD01
‘ DIFF read of CH0 to CH1 HSEROUT ["Channel DIF of the 1298 reads ", dec PS5ADC, 13,10] PAUSE
1000
‘ Print results serially CALL
AD10
‘ DIFF read of CH1 to CH0 HSEROUT ["Channel DIF of the 1298 reads ", dec PS5ADC, 13,10] PAUSE
2000
‘ Print results serially END | |
Program listing: 2 of 2
‘ This program will show how to sample the
four 10-bit channels using PicBasic Pro. ‘ The hardware serial port will be used to
display the results of the conversions on a PC. ‘
The hardware serial port defaults to 8N1 @ 2400bps. Define
ADC_BITS
10
' Sets the number of bits in the result Define
ADC_CLOCK
02
' Selects clock source Define
ADC_SAMPLEUS
50
' Sample time in µSec TRISA = 255
' Set PORTA to outputs ADCON1 = %10000000
' Select right justify for the results RSLT
VAR
WORD
' Variable to store the results SAMPLE VAR BYTE
' Variable to select the channel to be sampled ANYKEY VAR
BYTE
HIGH PORTC.1
' Enables the serial transmitter PAUSE 100 START:
FOR SAMPLE = 0 TO 3
' Selects the channel to be sampled
ADCIN
SAMPLE,RSLT
' Go sample the selected channel
HSEROUT [HEX RSLT,10,13]
' Display the result followed by CR,LF
NEXT SAMPLE
' Go do the next channel
HSERIN [ANYKEY]
' Press any key to continue
GOTO START
' Start again END |