Freescale ADC and QADC Modules With ColdFire Microcontrollers
Freescale ADC and QADC Modules With ColdFire Microcontrollers
Rev.0, 10/2008
Application Note
1 Introduction Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
This application note helps understand how to use the 2 Queued Analog-to-Digital Converter . . . . . . . . . . . . . . . . 2
2.1 Brief Description . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
ColdFire MCF528x, MCF5214/16 microcontrollers 2.2 Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
queued analog-to-digital converter and the ColdFire 2.3 Conversion Command Word (CCW) Table . . . . . . . 2
MCF5211/12/13, MCF522xx microcontrollers 2.4 Modes of Operation . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.5 QADC Programming Examples. . . . . . . . . . . . . . . . 5
analog-to-digital converter. It provides basic examples 3 Analog-to-Digital Converter . . . . . . . . . . . . . . . . . . . . . . 14
for different ADC and QADC configurations. QADC 3.1 Brief Description . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2 Operation Modes . . . . . . . . . . . . . . . . . . . . . . . . . . 14
examples were created for evaluation board M5282EVB 3.3 ADC Programming Examples . . . . . . . . . . . . . . . . 16
and ADC examples for evaluation board 4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
M52233DEMO.
The M5282EVB does not include any devices connected
to the QADC inputs. It needs to have a signal generator
or voltage source (preferably both).
The M52233DEMO includes a potentiometer and
accelerometer connected to a few analog pins. No
external equipment is needed.
2.2 Terms
Queue 1 (Q1) — Sequence of commands that begin with the first entry of CCW and ends with one of the
following options:
• An entry that contains the first EOQ code. Using the EOQ code is strongly recommended.
• One entry before the entry determined by BQ2.
Queue 2 (Q2) — Sequence of commands that begins with the entry the BQ2 points to and ends with second
EOQ code or ends at the end of the CCW table if the second EOQ is not used.
Subqueue (SQxx) — Sequence of commands between the beginning and the CCW entry with pause bit
set, two entries with pause bit set, or entry with pause bit set, and the end of queue.
Pause — If pause bit in the CCW entry is set the conversion is paused after this command execution and
waits for another trigger event. The queue is in a pause state except both externally gated modes and both
software-triggered modes where pause state is ignored.
End of queue (EOQ) — If the command has set channel number 63, the whole command is interpreted as
end of queue notification. The rest of this entry is not important.
Beginning of queue 2 (BQ2) — An entry of the CCW table pointed to by QACR2[BQ2]. The entry prior
can contain the EOQ code.
Command (entry)
00 0 No No 0
01 1 No No 0
SQ11
02 2 No No 0
03 3 Yes No 0
04 0 No No 0 Q1
05 1 No No 0
06 2 No No 0 SQ12
07 3 No No 0
08 63 (EOQ) x x x
09 52 No No 0
SQ21
10 53 Yes No 0
11 52 No No 0
SQ22
12 53 Yes No 0 Q2
13 55 No No 0
14 56 No No 0 SQ23
15 63 (EOQ) x x x
Signal name AN0 AN1 AN2 AN3 AN52 AN53 AN55 AN56 VSSA
When using an evaluation board a few jumpers influence the QADC behavior.
Table 3. Analogue Power Selector
1–2* 3.3 V
3–4 5V
5–6 On pin J5–18
1–2* GND
2–3 Pin J5–1
1–2* VDDA
2–3 Pin J5–20
1–2* VSSA
2–3 Pin J5–2
*Default settings
NOTE
The MCF5282 is a 5 V tolerant device and has up to a 5 V digital output
driven by a VDDH input.
In case of using a LITE board, fixed analog references are used:
• VDDA = VRH = +3.3 V
• VSSA = VRL = 0 V
2.5.2.2.1 vectors.s
Added vectors for the following interrupt service routines:
• EPORT_IRQ7_button_pressing
• QADC_Q1_conversion_pause
• QADC_Q2_conversion_pause
• QADC_Q1_conversion_complete
• QADC_Q2_conversion_complete
2.5.2.2.2 int_handlers_x.c
Added interrupt service routines for the sources mentioned above.
2.5.2.2.3 main_x.c
This file includes a description of the example by displaying a notice on the terminal window, initialization
part of EPORT module, interrupt controller module, and the QADC module.
Functions:
• void QADC_init(void) — Initializes the QADC module and its CCW table. This function calls
functions set_CCW and get_BQ2.
• void cpu_pause(int usecs) — For the required time in s, this function can be used for a wait in the
loop. It uses the DMA timer 3.
2.5.2.2.4 QADC_opmodes.h
The file includes headers with the list of Q1 and Q2 operating modes for easy configuration of
QACR1[MQ1] field and QACR2[MQ2].
2.5.2.2.5 QADC_CCW_table_x.c
This file includes two functions and a template for creating the CCW table.
The table is prepared as a one-dimensional unknown size data field. Every item (row) is composed of
macros and is an entry to the CCWtable.
Functions:
• void set_CCW (void) — Copies the CCW table from the data field CCWtable[] located in the file
QADC_CCW_table.c to the appropriate registers.
• int32 get_BQ2 (void) — Identifies and returns the beginning of Queue 2. The return value is the
index of the first EOQ entry increased by one. The CCW table can contain two entries with the
EOQ code. If the CCW table includes only one EOQ code all entries below are considered as
Queue 2 and the end of the CCW table is considered as end of Queue 2. If the CCW table does not
include any EOQ code default value, 127 is returned. It is the same as the default QACR[BQ2]
value and it means that the trigger event for Q2 does not cause any conversion.
2.5.2.2.6 QADC_CCW_table.h
Headers for configuring the CCW table.
3. QADC Conversion Command Table — The following function is used for copying the
CCWtable[] data field to the CCW registers:
void set_CCW (void)
{
int32 i;
int32 CCWtable_length = sizeof(CCWtable)/2; // length of CCW is 16 bit words
4. The rest of the QADC — Settings vary according to the given example. All examples use a
function for getting the BQ2 parameter from the CCW table. Call of this function is placed to the
MCF5282_QADC_QACRx_BQ macro instead of a direct number parameter:
int32 get_BQ2 (void)
{
int32 i;
int32 CCWtable_length = sizeof(CCWtable)/2; // length of CCW
The variable previous_CWPQ2 by default has to be set as a pointer to a command prior the beginning of
queue 2 (variable BQ2). The BQ2 is read during runtime from the QACR2[BQ2]. The conversion pause
interrupt service routine checks variable first_entry_flag and if it is set the variable previous_CWPQ2 is
initialized by function first_entry, and the first_entry_flag is cleared.
void first_entry (void) /* shared function for all QADC interrupt handlers */
{
int32 BQ2; // beginning of Q2
previous_CWPQ1 = -1; // set pointer before
beginning of Q1
BQ2 = MCF5282_QADC_QACR2 & MCF5282_QADC_QACRx_BQ(0x7F); // beginning of Q2
previous_CWPQ2 = BQ2 - 1; // set pointer before beginning of Q2
first_entry_flag = 0; // this function will
no longer be called
}
printf("\n\rRESTART QADC\n\r");
QADC_activity = 1; // set flag for QADC active state
MCF5282_QADC_QADCMCR &= ~MCF5282_QADC_QADCMCR_QSTOP; // restart QADC
cpu_pause(10); // wait 10us to stabilize the analog circuits
MCF5282_QADC_QACR1 = QACR1;
MCF5282_QADC_QACR2 = QACR2; // store control registers
}
else
{
printf("\n\rLOW POWER STOP MODE\n\r");
QADC_activity = 0; // set flag for QADC inactive state
QACR1 = MCF5282_QADC_QACR1;
QACR2 = MCF5282_QADC_QACR2; // reload control registers
MCF5282_QADC_QADCMCR |= MCF5282_QADC_QADCMCR_QSTOP; // stop QADC
}
}
CHAN(0) | IST(0) , // 00
CHAN(1) | IST(0) | P , // 01
CHAN(2) | IST(0) , // 02
CHAN(3) | IST(0) , // 03
EOQ1 , // 04
CHAN(52) | IST(0) , // 05
CHAN(53) | IST(0) , // 06
EOQ2 // 07
};
MCF5282_QADC_QACR2 =
MCF5282_QADC_QACRx_CIE | //Q2 completion interrupt enable
MCF5282_QADC_QACRx_PIE | //Q2 pause interrupt enable
MCF5282_QADC_QACRx_RESUME | //after suspension begin with
aborted CCW
MCF5282_QADC_QACRx_BQ(get_BQ2()) | //identify BQ2 parameter
MCF5282_QADC_QACRx_MQ(Q2_EXT_TRIGGER_CONTINUOUS_SCAN_RISING);//opmode
}
3 Analog-to-Digital Converter
3.1 Brief Description
• 12-bit resolution
• Two separate and complete ADCs (4 channels per ADC)
• Ability to simultaneously sample and hold two inputs
• Ability to sequentially scan and store up to eight measurements
• Single ended or differential inputs
• Optional interrupts at the end of a scan if an out of range limit is exceeded (high or low), or at zero
crossing
• Optional sample correction by subtracting a pre-programmed offset value also used to indicate
signed or unsigned results.
• Power saving modes
ADC mode
Parallel, Parallel,
Sequential
simultaneous independent
Single-ended Differential
3.3.2.2.1 mcf5xxx_vectors.s
Added vectors for the following interrupt service routines:
• EPORT_SW1_button_pressing
• EPORT_SW2_button_pressing
• ADCA_conversion_complete
• ADCB_conversion_complete
• ADC_zero_crossing_or_limit_error
3.3.2.2.2 int_handlers.c
Added interrupt service routines for the sources mentioned above.
3.3.2.2.3 main_x.c
This file includes the example description that appears in the terminal window, initialization part of general
purpose I/O module, interrupt controller module, and ADC module.
Functions:
• void ADC_init(void) — initializes ADC module
Interrupt sources for INTC0 are set in such a way that higher priority has buttons and conversion complete
interrupts. See Table 8:
Table 8. Interrupt Levels and Priorities of Interrupt Sources
2. A general purpose module to assign all analog pins to their primary function
3. ADC initialization — Settings vary according to the example
Interrupt service routines are written for universal service of all modes.
ADCA_conversion_complete routine has two main branches. First, the sequential or parallel simultaneous
mode and the second for the parallel independent mode. In case parallel independent sampling, read half
of the result registers in the interrupt service routine initiated by the ADCA. Read the other half in ISR
initiated by ADCB.
Sequential mode is possible to determine by CTRL1[SMODE0]:
!(MCF_ADC_CTRL1 & 0x0001)
Similar testing is used in routines EPORT_SWx_button_pressing and used for the following condition:
!(MCF_ADC_CTRL1 & 0x0006)
This determines whether ADC uses the mode once or not. If yes, pressing the button starts the conversion.
If no, it means loop or triggered mode is used and pressing the button alternately starts/stops conversion.
3.3.3 Example 1 – Mode Once, One Channel Scan, (Single Ended Input)
This example uses a parallel independent scan. It does not matter what mode is chosen in this case because
behavior is the same.
Pressing the SW1 button starts scanning channel AN0 where the demo board has the potentiometer
connected. Jumper POT_EN has to be on.
if (CORE_CLOCK % 20000)
MCF_ADC_CTRL2 = MCF_ADC_CTRL2_DIV(CORE_CLOCK/20000) | // divison remainder!=0
MCF_ADC_CTRL2_STOP1; // stop ADCB
else
MCF_ADC_CTRL2 = MCF_ADC_CTRL2_DIV((CORE_CLOCK/20000)-1) | // divison reminder=0
MCF_ADC_CTRL2_STOP1; // stop ADCB
After each scan the converted value is displayed on the terminal window. The signed results are used. First
column shows potentiometer value, second, third, and fourth shows X, Y, and Z axis of accelerometer
outputs.
The ADC power-up sequence, clock divisor select, offset settings, and disabling unused sample slots are
essentially the same parts as Section 3.3.3, “Example 1 – Mode Once, One Channel Scan, (Single Ended
Input)”.
4 References
MCF52235 ColdFire® Integrated Microcontroller Reference Manual, MCF52235RM
MCF52235 ColdFire Microcontroller Data Sheet, MCF52235DS
MCF52235 Device Errata, MCF52235DE
MCF5282 ColdFire® Microcontroller User’s Manual, MCF5282UM
MCF5282 Device Errata, MCF5282DE
Web Support: Freescale Semiconductor reserves the right to make changes without further notice to
http://www.freescale.com/support any products herein. Freescale Semiconductor makes no warranty, representation or
USA/Europe or Locations Not Listed: guarantee regarding the suitability of its products for any particular purpose, nor does
Freescale Semiconductor, Inc. Freescale Semiconductor assume any liability arising out of the application or use of any
Technical Information Center, EL516 product or circuit, and specifically disclaims any and all liability, including without
2100 East Elliot Road limitation consequential or incidental damages. “Typical” parameters that may be
Tempe, Arizona 85284 provided in Freescale Semiconductor data sheets and/or specifications can and do vary
1-800-521-6274 or +1-480-768-2130 in different applications and actual performance may vary over time. All operating
www.freescale.com/support parameters, including “Typicals”, must be validated for each customer application by
customer’s technical experts. Freescale Semiconductor does not convey any license
Europe, Middle East, and Africa: under its patent rights nor the rights of others. Freescale Semiconductor products are
Freescale Halbleiter Deutschland GmbH not designed, intended, or authorized for use as components in systems intended for
Technical Information Center
Schatzbogen 7 surgical implant into the body, or other applications intended to support or sustain life,
81829 Muenchen, Germany or for any other application in which the failure of the Freescale Semiconductor product
+44 1296 380 456 (English) could create a situation where personal injury or death may occur. Should Buyer
+46 8 52200080 (English) purchase or use Freescale Semiconductor products for any such unintended or
+49 89 92103 559 (German) unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor and
+33 1 69 35 48 48 (French) its officers, employees, subsidiaries, affiliates, and distributors harmless against all
www.freescale.com/support claims, costs, damages, and expenses, and reasonable attorney fees arising out of,
directly or indirectly, any claim of personal injury or death associated with such
Japan:
unintended or unauthorized use, even if such claim alleges that Freescale
Freescale Semiconductor Japan Ltd.
Headquarters Semiconductor was negligent regarding the design or manufacture of the part.
ARCO Tower 15F
1-8-1, Shimo-Meguro, Meguro-ku,
Tokyo 153-0064
Japan
0120 191014 or +81 3 5437 9125
[email protected]
Asia/Pacific:
Freescale Semiconductor China Ltd. Freescale™ and the Freescale logo are trademarks of
Exchange Building 23F Freescale Semiconductor, Inc. All other product or service names
No. 118 Jianguo Road are the property of their respective owners.
Chaoyang District
Beijing 100022 © Freescale Semiconductor, Inc. 2008. All rights reserved.
China
+86 10 5879 8000 AN3749
[email protected] Rev. 0
08/2008
For Literature Requests Only:
Freescale Semiconductor Literature Distribution Center
P.O. Box 5405
Denver, Colorado 80217
1-800-441-2447 or +1-303-675-2140
Fax: +1-303-675-2150
[email protected]