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 CADC Demo

This demo application demonstrates the DAC and CADC 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 Settings

This table shows the connections that are required for each of the supported platforms:

Platform DAC Out ADC In
Pin Name Board Location Pin Name Board Location
TWR-KV46F150M DAC0_OUT J23-4 ADCA_CH4

J23-2

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 on TWR-KV46F150M:

DAC ADC Demo!
Please refer to Kinetis SDK Demo Applications User's Guide document,
Chapter DAC CADC 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.