Table of Contents
- Introduction
- Getting Started
- Adding CapSense Buttons
- How to Configure The OLED Display
- Device Assembly
- Programming, Test and Troubleshooting
- Summary
**********************************************************************************************************************
In this project we will use ModusToolbox 3.0 which has enhanced support for multi-core project workflow. The release features dual-core device support, a new graphical tool for customer board support package (BSP) development, infrastructure support for ModusToolbox Packs and backend system improvements.
About ModusToolbox software you can find the documentation here: https://www.infineon.com/cms/en/design-support/tools/sdk/modustoolbox-software/
The PSoC 62S4 Pioneer Kit features the PSoC 62 MCU CY8C62x4 (CY8C6244LQI-S4D92) with: 150-MHz Arm® Cortex®-M4 and 100-MHz Arm Cortex-M0+ cores, 256KB of Flash, 128KB of SRAM, programmable analog blocks including two 12-bit SAR ADCs, programmable digital blocks, Full-Speed USB, a serial memory interface, a CAN-FD interface, and industry-leading capacitive-sensing with CapSense.
Documentation: CY8CKIT-062S4
Below I show you the pinout of the PSoC 62S4 board.
In my opinion, the technical changes on this board were successful. This board is smaller than its previous version, so it can be more easily adapted to projects such as a robotic car where spaces are reduced. In my case it will be easier to adapt it to the beverage dispenser that I will develop.
Testing the Kit
As part of my post, I am going to carry out a simple test with the PSoC 62S4 board in order to verify its proper functioning. The example I'm going to use is CapSense buttons and Slider, since I plan to modify it in my final project. We start by creating a new application with ModusToolbox 3.0
Now we select the CY8CKIT-062S4 kit as shown in the image below:
Finally, I selected the CapSense buttons and slider app, and gave it a name as shown below:
We wait a few minutes and the application is shown below. The app shows us the README file with a tutorial of the application.
By now, I don´t plan to make changes to the code. The led.c file controls the LED diode, the two Capsense buttons and the Capsense Slider.
/******************************************************************************* * Header files includes *******************************************************************************/ #include "cybsp.h" #include "cyhal.h" #include "led.h" /******************************************************************************* * Global constants *******************************************************************************/ #define PWM_LED_FREQ_HZ (1000000lu) /* in Hz */ #define GET_DUTY_CYCLE(x) (100 - x) /******************************************************************************* * Global constants *******************************************************************************/ led_state_t led_state_cur = LED_OFF; cyhal_pwm_t pwm_led; /******************************************************************************* * Function Name: update_led_state ******************************************************************************** * Summary: * This function updates the LED state, based on the touch input. * * Parameter: * ledData: the pointer to the LED data structure * *******************************************************************************/ void update_led_state(led_data_t *ledData) { if ((led_state_cur == LED_OFF) && (ledData->state == LED_ON)) { cyhal_pwm_start(&pwm_led); led_state_cur = LED_ON; ledData->brightness = LED_MAX_BRIGHTNESS; } else if ((led_state_cur == LED_ON) && (ledData->state == LED_OFF)) { cyhal_pwm_stop(&pwm_led); led_state_cur = LED_OFF; ledData->brightness = 0; } else { } if ((LED_ON == led_state_cur) || ((LED_OFF == led_state_cur) && (ledData->brightness > 0))) { cyhal_pwm_start(&pwm_led); uint32_t brightness = (ledData->brightness < LED_MIN_BRIGHTNESS) ? LED_MIN_BRIGHTNESS : ledData->brightness; /* Drive the LED with brightness */ cyhal_pwm_set_duty_cycle(&pwm_led, GET_DUTY_CYCLE(brightness), PWM_LED_FREQ_HZ); led_state_cur = LED_ON; } } /******************************************************************************* * Function Name: initialize_led ******************************************************************************** * Summary: * Initializes a PWM resource for driving an LED. * *******************************************************************************/ cy_rslt_t initialize_led(void) { cy_rslt_t rslt; rslt = cyhal_pwm_init(&pwm_led, CYBSP_USER_LED, NULL); if (CY_RSLT_SUCCESS == rslt) { rslt = cyhal_pwm_set_duty_cycle(&pwm_led, GET_DUTY_CYCLE(LED_MAX_BRIGHTNESS), PWM_LED_FREQ_HZ); if (CY_RSLT_SUCCESS == rslt) { rslt = cyhal_pwm_start(&pwm_led); } } if (CY_RSLT_SUCCESS == rslt) { led_state_cur = LED_ON; } return rslt; } /* [] END OF FILE */
I build the project, and the console show me that there are no errors.
To upload the code to the PSoC 62S4 board, click on Run -> Run configurations
Select KitProg3(MiniProg4) and click Run
This code example features a 5-segment CAPSENSE slider and two CAPSENSE buttons. Button 0 turns the LED ON, button 1 turns the LED OFF, and the slider controls the brightness of the LED as shown below.
Now we are ready to start the drink dispenser project. In the next post I will modify the code of this project to control the drink flow using the capsense buttons and a mini water pump. Thanks for reading this content!