Kinetis SDK v.1.2 Demo Applications User's Guide  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
DAC ADC Demo

This demo application demonstrates the DAC and ADC demo.

Overview

This application demonstrates how to configure the DAC and set the output on the DAC using software. It also demonstrates how to configure the ADC in 'Blocking Mode' and read ADC values.

Supported Platforms

This demo supports these Freescale Freedom development platforms and Tower System modules:

System Requirement

Hardware requirements

Toolchain requirements

Software requirements

Getting Started

Hardware configuration

For the MRB-KW01 it is necessary: To short jumpers J10 and J11 to connect the ADC references. To disconnect J7 to open PTE30 connection with the RESET of the RADIO part. Also analog function for PTE30 - DAC output is necessary on the mrb-kw01 (default is GPIO for RADIO part reset). This is done in hardware_init() function.

Hardware Settings

This table shows the connections that are required for each of the supported platforms. Not mentioned platforms use the internal connection.

Platform DAC Out ADC In
Pin Name Board Location Pin Name Board Location
FRDM-K22F DAC0_OUT J24-11 PTB0/ADC0_SE8 J24-2
FRDM-KL25Z PTE30/DAC0_OUT J10-11 PTE20/ADC0_SE0 J10-1
FRDM-K64F DAC0_OUT J4-11 PTB2/ADC0_SE12 J4-2
FRDM-KL46Z PTE30/DAC_OUT J4-11 PTE20/DIFF_ADC0_DP J4-1
TWR-K21D50M DAC0_OUT Primary Elevator - A32 PTB3/ADC0_SE13 Primary Elevator - B30
TWR-K22F120M DAC0_OUT Primary Elevator - A32 PTB0/ADC0_SE8 Primary Elevator - B27
TWR-K24F120M DAC0_OUT Primary Elevator - A32 ADC0_DP3 Primary Elevator - A29
TWR-K60D100M DAC0_OUT Primary Elevator - A32 PTB4/ADC1_SE10 Primary Elevator - B30
TWR-K64F120M DAC0_OUT Primary Elevator - A32 PTB4/ADC1_SE10 Primary Elevator - B27
TWR-K65F180M DAC0_OUT Primary Elevator - A32 ADC1_SE16 J24-1
TWR-KV10Z32 DAC0_OUT J16-11 PTE17/ADC0_SE5 J16-6
TWR-KV31F120M DAC0_OUT Primary Elevator - A32 PTE2/ADC1_SE6a Primary Elevator - B27
TWR-K21F120M DAC0_OUT Primary Elevator - A23 PTE2/ADC0_SE23 Primary Elevator - B23

Prepare the Demo

  1. Connect a USB cable between the PC host and the OpenSDA USB port on the board.
  2. Open a serial terminal with these settings:
    • 115200 baud rate
    • 8 data bits
    • No parity
    • One stop bit
    • No flow control
  3. Download the program to the target board.
  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

For more detailed instructions, see a Kinetis SDK User's Guide for your board.

Run the demo

This example shows how to run the demo:

DAC ADC Demo!
Please refer to Kinetis SDK Demo Applications User's Guide document,
Chapter DAC ADC demo, for pins configuration information.
Press space bar to start demo.
    

The user is prompted to enter a voltage to output on the DAC:

Select DAC output level:
        1. 1.0 V
        2. 1.5 V
        3. 2.0 V
        4. 2.5 V
        5. 3.0 V
->

After entering a valid input, the ADC captures the voltage set by the DAC and displays the result in the terminal:

Select DAC output level:
        1. 1.0 V
        2. 1.5 V
        3. 2.0 V
        4. 2.5 V
        5. 3.0 V
->3
ADC Value: 2471
ADC Voltage: 1.99
What next?: 1. Test another DAC output value. 2. Terminate demo. ->

At this point, the user can test another DAC output value or terminate the demo.

This configuration exhibits up to 2% error when reading back voltage.

Key Functions

uint8_t demo_start(demo_state_t *prevState)

Prints out a welcome message and pins required by the demo.

Parameters
*prevStatePointer to previous state for state machine.
Returns
msg Returns the character entered into the terminal by the user.

uint8_t device_config(demo_state_t *prevState)

Configures the DAC and the ADC. The DAC is configured for software updates. The ADC is set in 'Blocking Mode'.

Parameters
*prevStatePointer to previous state for state machine.
Returns
msg Returns 0.

uint8_t dac_set(demo_state_t *prevState)

Sets output level on the DAC.

Parameters
*prevStatePointer to previous state for state machine.
Returns
msg Returns the character entered into the terminal by user.

uint8_t wait_state(demo_state_t *prevState)

Performs a wait and possible state change based on the *prevState.

Parameters
*prevStatePointer to previous state for state machine.
Returns
msg Returns 0.

uint8_t adc_get(demo_state_t *prevState)

Gets ADC values from a channel connected to the DAC output.

Parameters
*prevStatePointer to previous state for state machine.
Returns
msg Returns the character entered into the terminal by the user.

uint8_t device_deinit(demo_state_t *prevState)

Deinitializes the DAC and the ADC module following a user command to terminate the demo. Also frees allocated memory.

Parameters
*prevStatePointer to previous state for the state machine.
Returns
msg Returns 0.

uint8_t demo_end(demo_state_t *prevState)

Indicates to the user that the demo has been terminated.

Parameters
*prevStatePointer to previous state for the state machine.
Returns
msg Returns 0.