![Freescale Semiconductor QE128 Скачать руководство пользователя страница 75](http://html1.mh-extra.com/html/freescale-semiconductor/qe128/qe128_quick-reference-user-manual_2330661075.webp)
Using the Analog to Digital Converter (ADC) for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
Freescale Semiconductor
8-3
•
MCU_Init – MCU initialization, watchdog disable and the ADC clock module enabled.
•
GPIO_Init – Configure PTE port as output.
•
ADC_Init – ADC module configuration.
•
ADC_ISR — The data obtained by ADC module is display on PTE port.
This section consists of varying the potentiometer that also varies the voltage and is connected to the ADC
channel 0. The obtained data is displayed in an 8 LEDs array connected to the PTE port. The ADC module
is configured in continuous conversion mode. The MCU is interrupted constantly and within the ISR the
obtained data is displayed on the PTE port.
The code below executes the instructions to disable the watchdog, enable the Reset option and backgroud
pin. The system option register 1 (SOPT1) is used to configure the MCU. The SCGC1 and SCGC2 are
registers used for power saving consumption, here the bus clock to peripherals can be enabled or disabled.
In this example only the bus clock to the ADC module is active. The clocks to the other peripherals are
disabled.
void MCU_Init(void) {
SOPT1 = 0x23; // Watchdog disabled. Stop Mode Enabled. Background Pin
// enabled. RESET pin enabled
SCGC1 = 0x10; // Bus Clock to the ADC module is enabled
SCGC2 = 0x00; // Disable Bus clock to unused peripherals
}
This is the General Purpose Input/Output configuration. These code lines configure the directions for the
PTE port. The eight LEDs are connected to the PTE port; therefore the PTE port is configured as output.
void GPIO_Init(void) {
PTEDD = 0xFF; // Configure PTE port as output
PTED = 0x00; // Put 0's in PTE port
}
This is the initialization code for the analog-to-digital converter used for the QE MCU. This application
uses the ADC module channel 0. The module is configured in continuous conversion mode and an 8-bit
resolution.
void ADC_Init (void) {
ADCSC1 = 0x20; // Interrupt disable. Continuous conversion and channel 0
// active
ADCSC2 = 0x00; // Software trigger selected
ADCCFG = 0x30; // Input clock/2. Long Sample time configuration. 8-bit
// conversion
APCTL1 = 0x00; // ADC0 pin disable
}
This is the main function, above are the described called functions, and all the interrupts are enabled. The
ADC interrupt can be serviced.
void main(void) {
MCU_Init(); // initializes the MCU
GPIO_Init(); // initializes GPIO
ADC_Init(); // Function that initializes the ADC module
EnableInterrupts; // enable interrupts
ADCSC1_AIEN = 1; // Enable ADC interrupt
APCTL1_ADPC0 = 1; // Select the channel for ADC input
for(;;) {
} // loop forever