EasyManua.ls Logo

Microchip Technology dsPIC30F - Page 397

Microchip Technology dsPIC30F
738 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
© 2004 Microchip Technology Inc. DS70064C-page 17-21
Section 17. 10-bit A/D Converter
10-bit A/D
Converter
17
17.12.2.1 Free Running Sample Conversion Sequence
As shown in Figure 17-7, using the Auto-Convert Conversion Trigger mode (SSRC = 111) in
combination with the Auto-Sample Start mode (ASAM = 1), allows the A/D module to schedule
sample/conversion sequences with no intervention by the user or other device resources. This
“Clocked” mode allows continuous data collection after module initialization. See Example 17-4
for code example.
Figure 17-7: Converting 1 Channel, Auto-Sample Start, T
AD Based Conversion Start
Example 17-4: Converting 1 Channel, Auto-Sample Start,
T
AD Based Conversion Start Code
ADCLK
SAMP
ADCBUF1
TSAMP
TCONV
DONE
= 16 TAD
TSAMP
TCONV
= 16 TAD
ADCBUF0
BSF ADCON1,ASAM
Instruction Execution
ADPCFG = 0xFFFB; // all PORTB = Digital; RB2 = analog
ADCON1 = 0x00E0; // SSRC bit = 111 implies internal
// counter ends sampling and starts
// converting.
ADCHS = 0x0002; // Connect RB2/AN2 as CH0 input ..
// in this example RB2/AN2 is the input
ADCSSL = 0;
ADCON3 = 0x0F00; // Sample time = 15Tad, Tad = internal Tcy/2
ADCON2 = 0x0004; // Interrupt after every 2 samples
ADCON1bits.ADON = 1; // turn ADC ON
while (1) // repeat continuously
{
ADCValue = 0; // clear value
ADC16Ptr = &ADCBUF0; // initialize ADCBUF pointer
IFS0bits.ADIF = 0; // clear ADC interrupt flag
ADCON1bits.ASAM = 1; // auto start sampling
// for 31Tad then go to conversion
while (!IFS0bits.ADIF); // conversion done?
ADCON1bits.ASAM = 0; // yes then stop sample/convert
for (count = 0; count < 2; count++) // average the 2 ADC value
ADCValue = ADCValue + *ADC16Ptr++;
ADCValue = ADCValue >> 1;
} // repeat

Table of Contents

Other manuals for Microchip Technology dsPIC30F