GitHub hosted
Public

This example demonstrates using the CSD current digital-to-analog converter (IDAC) as a current source and a current sink.



Download repository: zip

Introduction

This code example demonstrates using the CSD current digital-to-analog converter (IDAC) as a current source and a current sink. CSD IDAC block supports two channels - A and B.

  1. IDAC as current source: Channel A is configured as a current source. The current increases when a switch is pressed. Once the output reaches its maximum value, it resets to zero and starts to increase the value again. If the switch is not pressed, it holds the last value.

  2. IDAC as current sink: Channel B is configured for sinking current and used for driving an LED. Firmware controls the sinking current to toggle the LED every second.

Additional PSoC 6 MCU-related code examples are available in other repos. See all examples at Code Examples for Modus Toolbox.

Supported Kits

Instructions to run the CSDIDAC code example

  1. Import the code example.
    mbed import https://github.com/cypresssemiconductorco/mbed-os-example-csdidac
  1. Change the working directory to the example folder.

cd mbed-os-example-csdidac

  1. Plug in the CY8CPROTO-062-4343W kit. Ensure that the kit has the latest version of KitProg3 firmware and is in DAPLink mode to allow programming from Mbed CLI. See Firmware-loader for more information on how to update the firmware and switch to DAPLink mode.

  2. Compile the example and program.

    mbed compile --target CY8CPROTO_062_4343W --toolchain GCC_ARM --flash --sterm

    For other targets:

    mbed compile -m CY8CKIT_062_WIFI_BT -t GCC_ARM -f --sterm mbed compile -m CY8CKIT_062_BLE -t GCC_ARM -f --sterm

    Note: The –sterm option opens the serial terminal with 9600-8N1 setting on the command prompt itself after programming completes. Do not use this option if you wish to connect using another serial terminal application.

  3. The following message is displayed on the serial terminal. The LED blinks every second when the application starts running.

    CSDIDAC Code Example

  4. Place a resistor across Pin 10[0] and measure the voltage across the resistor to find out the current value.

  5. Press user button (SW2) to increase the source current. When the user button is pressed, the terminal application should also show the current value the IDAC is configured for.

```
CSDIDAC Code Example

CSDIDAC is configured for sourcing current: 0 nA
CSDIDAC is configured for sourcing current: 10000 nA
CSDIDAC is configured for sourcing current: 20000 nA
CSDIDAC is configured for sourcing current: 30000 nA
```

How to modify the CSDIDAC pins for this project

Do the following to modify the pins:

  1. Update the variables csdidac_a_pin and csdidac_b_pin. For example, to connect P10[0] to channel A and P10[1] to channel B, update the variables as follows:
static const cy_stc_csdidac_pin_t csdidac_a_pin = 
{
    .ioPcPtr = GPIO_PRT10,
    .pin = 0u,
};

static const cy_stc_csdidac_pin_t csdidac_b_pin = 
{
    .ioPcPtr = GPIO_PRT10,
    .pin = 1u,
};
  1. Update the function config_routing with new AMUX bus connection.
  • For CY8CKIT-062-BLE PSoC 6 BLE Pioneer Kit:
Port AMUX configuration
Port 0
Port 11
Port 12
Port 13
HSIOM->AMUX_SPLIT_CTL[5] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
HSIOM->AMUX_SPLIT_CTL[6] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 1 HSIOM->AMUX_SPLIT_CTL[2] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
HSIOM->AMUX_SPLIT_CTL[4] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 5
Port 6
Port 7
Port 8
HSIOM->AMUX_SPLIT_CTL[4] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 9
Port 10
HSIOM->AMUX_SPLIT_CTL[5] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
  • For CY8CKIT-062-WiFi-BT PSoC 6 WiFi-BT Pioneer Kit:
Port AMUX configuration
Port 0
Port 11
Port 12
Port 13
HSIOM->AMUX_SPLIT_CTL[5] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
HSIOM->AMUX_SPLIT_CTL[6] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 1
Port 2
Port 3
Port 4
HSIOM->AMUX_SPLIT_CTL[2] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
HSIOM->AMUX_SPLIT_CTL[4] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 5
Port 6
Port 7
Port 8
HSIOM->AMUX_SPLIT_CTL[4] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 9
Port 10
HSIOM->AMUX_SPLIT_CTL[5] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
  • For CY8CPROTO-062-4343W PSoC 6 Wi-Fi BT Prototyping Kit
Port AMUX configuration
Port 0
Port 11
Port 12
Port 13
HSIOM->AMUX_SPLIT_CTL[5] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
HSIOM->AMUX_SPLIT_CTL[6] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 1
Port 2
Port 3
Port 4
HSIOM->AMUX_SPLIT_CTL[2] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
HSIOM->AMUX_SPLIT_CTL[4] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 5
Port 6
Port 7
Port 8
HSIOM->AMUX_SPLIT_CTL[4] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;
Port 9
Port 10
HSIOM->AMUX_SPLIT_CTL[5] = HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk \| HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk;

Reference

Release Notes

Version Description
1.0 Initial release.
Tested with mbed-os v5.13.1 and CSDIDAC MW v2.0