element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
At The Core Design Challenge
  • Challenges & Projects
  • Design Challenges
  • At The Core Design Challenge
  • More
  • Cancel
At The Core Design Challenge
Blog Infineon Beverage Dispenser # 6 - Programming, Test and Troubleshooting
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join At The Core Design Challenge to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: guillengap
  • Date Created: 30 Apr 2023 5:39 AM Date Created
  • Views 507 views
  • Likes 5 likes
  • Comments 3 comments
  • infineon
  • PSoCTm︎ 62 MCU
  • element14
  • modustoolbox
  • Embedded Systems
  • microcontroller
  • challenge
  • arm
Related
Recommended

Infineon Beverage Dispenser # 6 - Programming, Test and Troubleshooting

guillengap
guillengap
30 Apr 2023
Infineon Beverage Dispenser # 6 - Programming, Test and Troubleshooting

Table of Contents

  • Introduction
  • Getting Started
  • Adding CapSense 
  • How to Configure The OLED Display
  • Device Assembly
  • Programming, Test and Troubleshooting
  • Summary

**********************************************************************************************************************

In this chapter I will show you the programming of the PSoC 62S4 board, the tests, and the bugs that I report to Infineon. Let me tell you that I made changes to my final project due this bugs. In the previous chapter we assembled the drink dispenser, in the image below I show you how it would look like:

image

Programming

I have created the second version of the project in modustoolbox. Below the image of the project created.

image

I have used as a reference the project that I did in chapter 3 with CapSense sensors. Below I show you the code of the file "beverage_dispenser.c" which contains the main instructions of my project.

// Author: Guillermo Perez

/*******************************************************************************
* Header files includes
*******************************************************************************/
#include "beverage_dispenser.h"
#include "cybsp.h"
#include "cyhal.h"
#include <stdio.h>
#include <math.h>

/*******************************************************************************
* Global constants
*******************************************************************************/
#define PWM_LED_FREQ_HZ    (1000000lu)  /* in Hz */
#define GET_DUTY_CYCLE(x)    (100 - x)

#define DELAY_LONG_MS           (3000)   /* ADD 2 milliseconds */
/* PWM Frequency */
#define PWM_FREQUENCY (50u)

/*******************************************************************************
* Global constants
*******************************************************************************/
led_state_t led_state_cur = LED_OFF;
cyhal_pwm_t pwm_led;
cyhal_pwm_t pwm_dispenser;
cyhal_pwm_t pwm_dispenser2;

/*******************************************************************************
* 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;
        cyhal_gpio_write(P0_2, CYBSP_LED_STATE_OFF); // tea dispenser
        cyhal_gpio_write(P0_3, CYBSP_LED_STATE_OFF); // red LED
    }
    else if ((led_state_cur == LED_ON) && (ledData->state == LED_OFF))
    {
        cyhal_pwm_stop(&pwm_led);
        led_state_cur = LED_OFF;
        cyhal_gpio_write(P0_2, CYBSP_LED_STATE_ON); // tea dispenser
        cyhal_gpio_write(P0_3, CYBSP_LED_STATE_ON); // red LED
    }
    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;
        uint32_t PWM_DUTY_CYCLE_DISPENSER = brightness;

        cyhal_pwm_set_duty_cycle(&pwm_dispenser, PWM_DUTY_CYCLE_DISPENSER, PWM_FREQUENCY); // coffee dispenser
        cyhal_pwm_start(&pwm_dispenser); // coffee dispenser

        cyhal_pwm_set_duty_cycle(&pwm_dispenser2, PWM_DUTY_CYCLE_DISPENSER, PWM_FREQUENCY); // green LED
        cyhal_pwm_start(&pwm_dispenser2); // green LED

    }
}

/*******************************************************************************
* 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);
    rslt = cyhal_pwm_init(&pwm_dispenser, P2_4, NULL); // connect to water pump 2
    rslt = cyhal_pwm_init(&pwm_dispenser2, P2_6, NULL); // connect to red LED
    rslt = cyhal_gpio_init(P0_2, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_ON); // connect to water pump 1
    rslt = cyhal_gpio_init(P0_3, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_ON); // connect to green LED

    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 */

How does it work?

  • In this case, I have added a red LED to visually indicate that pump 2 is working when the CapSense buttons are activated. In my case I have used these buttons to control a tea dispenser.
  • Similarly, I've added a green LED to visually indicate that pump 1 is working when I slide my finger across the CapSense slider. Here the slider controls a coffee dispenser.

/*******************************************************************************
* 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);
    rslt = cyhal_pwm_init(&pwm_dispenser, P2_4, NULL); // connect to water pump 2
    rslt = cyhal_pwm_init(&pwm_dispenser2, P2_6, NULL); // connect to red LED
    rslt = cyhal_gpio_init(P0_2, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_ON); // connect to water pump 1
    rslt = cyhal_gpio_init(P0_3, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_ON); // connect to green LED

    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;
}

I've also made the necessary changes so that the buttons and the slider don't interfere with each other.

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;
        cyhal_gpio_write(P0_2, CYBSP_LED_STATE_OFF); // tea dispenser
        cyhal_gpio_write(P0_3, CYBSP_LED_STATE_OFF); // red LED
    }
    else if ((led_state_cur == LED_ON) && (ledData->state == LED_OFF))
    {
        cyhal_pwm_stop(&pwm_led);
        led_state_cur = LED_OFF;
        cyhal_gpio_write(P0_2, CYBSP_LED_STATE_ON); // tea dispenser
        cyhal_gpio_write(P0_3, CYBSP_LED_STATE_ON); // red LED
    }
    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;
        uint32_t PWM_DUTY_CYCLE_DISPENSER = brightness;

        cyhal_pwm_set_duty_cycle(&pwm_dispenser, PWM_DUTY_CYCLE_DISPENSER, PWM_FREQUENCY); // coffee dispenser
        cyhal_pwm_start(&pwm_dispenser); // coffee dispenser

        cyhal_pwm_set_duty_cycle(&pwm_dispenser2, PWM_DUTY_CYCLE_DISPENSER, PWM_FREQUENCY); // green LED
        cyhal_pwm_start(&pwm_dispenser2); // green LED

    }
}

Test

Below I show you the tests that I carried out with this device. One of the things I discovered is that using the capsense buttons the water pump throws the liquid more forcefully. On the other hand, with the slider we can control the speed of the liquid until it becomes smoother.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Troubleshooting

I recommend using plastic and having a kitchen towel ready for possible liquid spills. It's also necessary to unfold the plastic hose. When I developed my project, I found into problems that I couldn't solve, so I request help to Infineon technical support and I started the cases shown below and their status.

Case IFX-230328-890211

My idea was to use the OLED display to visually indicate when a cup of coffee or tea was ready. However I found that there is a bug if I want to use the CapSense buttons and the OLE display simultaneously. I don't know if the problem is hardware or software because the I2C protocol in theory indicates that I can connect several devices and the protocol assigns an address to control the communication of each device. I opened the case number IFX-230328-890211 on March 28 with high priority and today it has not been solved.

image

The person in charge of this case is Sobhit Panda, and if there is any solution to this case, my idea is to update the version of my project as soon as I can.

Last update: On May 31 Rohan Manish contacted me to let me know that he had fixed this bug. I already have the information to update this project and I will publish the solution as soon as I can.

Case IFX-230315-875860

Another idea that I wanted to carry out was the use of the HC-SR04 ultrasonic sensor to know if there was a glass in the drink dispenser. To do so, it is necessary to use Timer/Counter and PWM functionalities. However, there is no example code with counters, and technical support told me that only theoretical information existed. In the end, they committed to doing sample code with counters in the future. The contest is close to end, so my idea is to update the version of the drink dispenser as soon as I solved this issue.

image

In the next chapter I will give you a summary of all my experience related to this project.

  • Sign in to reply

Top Comments

  • navadeepganeshu
    navadeepganeshu over 2 years ago +1
    Nice build! Interesting to see how you've applied the system to dispenser usage. That's a lot of coffee Yeah, I agree about the sample project availability - but the PDL API documentation has some short…
  • navadeepganeshu
    navadeepganeshu over 2 years ago in reply to guillengap

    Hi @guillengap,

    I've come across this while searching for something to pass data between cores and using IPC piple in one of my implementations. Haven't actually explored TCPWM peripheral and thought you'd find it interesting. Certainly, I am looking to do something related to implementing multiple pushbutton sequences based on press and hold time for which Counter or Timer can be very suitable.  

    • Cancel
    • Vote Up -1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • guillengap
    guillengap over 2 years ago in reply to navadeepganeshu

    Thanks for your comment and sharing the link... today, I'm going to experiment with this and possibly update my project after the contest, because I don't have enough time to solve bugs... if you already solved this issue, why don't you share it?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • navadeepganeshu
    navadeepganeshu over 2 years ago

    Nice build! Interesting to see how you've applied the system to dispenser usage. That's a lot of coffee Slight smile

    Yeah, I agree about the sample project availability - but the PDL API documentation has some short example snippets for each APIs and usage of timers, counters and other peripherals like this PSoC 6 Peripheral Driver Library: Functions (infineon.github.io)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube