
VMX51C1020
_________________________________________________________________________________________________
www.ramtron.com
page 62 of 80
ADC Status Register
The ADC shares interrupt vector 0x6B with the
Interrupt on Port 1 Change and the Compare
and Capture Unit 3. To enable the ADC
interrupt, the ADCIE bit of the ADCCTRL
register must be set. Before or at the same time
this bit is set, the ADCIRQCLR and the ADCIRQ
bits must be cleared. The ADCPCIE bit of the
IEN1 register must also be set, as well as the
EA bit of the IEN0 register.
Once the ADC interrupt occurs, ADC Interrupt
must be cleared by writing a ‘1’ into the
ADCINTCLR bit of the ADCCTRL register. The
ADCIF flag in the IRCON register must also be
cleared.
A/D Converter Example
The following provides example code for the A/D
converter. The first section of the code covers
interrupt setup/module configuration whereas
the second section is the interrupt function itself.
Sample C code to setup the A/D converter:
//-----------------------------------------------------------------------//
// MAIN FUNCTION
//-----------------------------------------------------------------------//
(…)
at 0x0100 void main (void) {
//*** Initialize the Analog Peripherals ***
ANALOGPWREN = 0x07;
//Enable the following analog
//peripherals: ISRC, ADC, PGA,
// BGAP. TA = OFF (mandatory)
//Configure the ADC and Start it
ADCCLKDIV=0x0F;
//SET ADC CLOCK SOURCE
ADCCONVRLOW=0x00;
//CONFIGURE CONVERSION RATE
ADCCONVRMED=0x40;
//= 100Hz @ 14.74 MHz
ADCCONVRHIGH =0x02;
INMUXCTRL=0x0F;
//Enable All ADC External inputs
//buffers and select ADCI0
ADCCTRL=0xEA;
//Configure the ADC as follow:
//bit 7: =1 ADCIRQ Clear
//Bit 6: =1 XVREFCAP (always)
//Bit 5: =1 (always)
//Bit 4: =0 = ADCIRQ (don’t care)
//Bit 3: =1 = ADC IRQ enable
//Bit 2: =0 conversion on 4
//channels
//Bit 1: =1 Continuous conversion
//Bit 0: =0 No single shot mode
//*** Configure the interrupts
IEN0 |= 0x80;
IEN1 |= 0x020;
while(1);
}// End of main()...
//-----------------------------------------------------------------------//
// ADC INTERRUPT ROUTINE
//-----------------------------------------------------------------------//
void int_adc (void) interrupt 13 {
idata int value = 0;
IEN0 &= 0x7F;
ADCCTRL |=0x80;
// Read ADC channel 0
value = ADCD0HI;
value = valeur*256;
value = valeur + ADCD0LO;
(…)
// Read ADC channel 3
value = ADCD3HI;
value = valeur*256;
value = valeur + ADCD3LO;
(…)
IRCON &= 0xDF;
ADCCTRL |=0xFA;
IEN0 |= 0x80;
}// End of ADC IRQ
(…)
Warning:
When using the ADC, make sure the
output multiplexer controlled by the
TAEN bit of the ANALOGPWREN
register (92h) is powered down at all
times, otherwise, the signal present on
the ISRCOUT can be routed back to the
selected ADC input, causing conversion
errors.
//enable main interrupt
//Enable ADC Interrupt
//Infinite loop waiting ADC interrupts
//disable ext0 interrupts
//Clear ADC interrupt
//Clear adc irq flag
//prepare adc for next acquisition
// enable all interrupts