Showing posts with label PSoC. Show all posts
Showing posts with label PSoC. Show all posts

Tuesday, 11 November 2025

WS2812 PSoC5 Creator Project

Introduction 
This short blog continues a previous post about a WS2812 addressable LED for an Infineon (Cypress) PSoC 4 microcontroller. This blog focuses on the project for the PSoC 5 with testing performed on a CY8CKIT-059 development board.

Rebuilding the Project
The PSoC5 project, ‘ws2812_test’, was downloaded from a post on the Infineon Community site.

Upon opening the PSoC5 project, the same issue noted in the previous blog with the PSoC4 was observed. The missing component is evident in the top-level design of the PSoC project.

Missing Components in PSoC Top Design
Missing Components in PSoC Top Design

Unlike the previous post, where the WS2812 library was not included in the compressed project, the WS2812 library is included in the compressed project.

WS281xLib in PSoC Project Folder
WS281xLib in PSoC Project Folder

The issue with the missing component was resolved by updating the project Dependencies in PSoC Creator.

PSoC Creator Dependencies - StripLightLib Error
PSoC Creator Dependencies - StripLightLib Error

The dependency for the existing WS2812 library was deleted. Next, the dependency for WS281xLib was added again to the project. The WS2812 folder in the local ws2812_test project was chosen.

PSoC Creator Dependencies - WS281xLib
PSoC Creator Dependencies - WS281xLib

After exiting the project Dependencies window, the Top Design sheet in the project displays the previously missing WS2812 component.

Updated Components in PSoC Top Design
Updated Components in PSoC Top Design

Before rebuilding the project, a resistive pull-up was added to the SW button to suit a PSoC development board.

Switch Input Pin Configured with Resistive Pull-Up
Switch Input Pin Configured with Resistive Pull-Up

The CY8CKIT-059 development board does not appear to have a resistive pull-up connected to the pushbutton switch ‘SW’ on the development board.

CY8CKIT-059 User Push Button Connection
CY8CKIT-059 User Push Button Connection

This information is noted in Section 3.1 Theory of Operation, in the User Manual. With the default code implementation, the WS2812 will be driven by the development board as soon as the board is powered via the USB KitProg or PSoC connector.

Note from CY8CKIT-059 User Manual
Note from CY8CKIT-059 User Manual


Testing
A WS2812 module with eight LEDs was tested using the CY8CKIT-059 development board. The default code is configured for a single LED in blue, as shown below.


A modification is shown below for festive celebrations!


The LED colours for the above example were extracted from Line 117 in the PSoC project StripLights.c file. Setting of the two LED colours used with the Modulo operator, as shown below in main.c

Updated Code in Main.c from Line 54
Updated Code in Main.c from Line 54

Downloads
Linked below is an updated release of the PSoC project with the corrected dependencies to suit the CY8CKIT-059.

Updated Original PSoC5 Application - WS2812_test


Wednesday, 13 August 2025

Republishing a WS2812 PSoC Creator Project

Introduction 
This short blog republishes a PSoC Creator project that uses a WS2812 component. The WS2812 is an addressable RGB LED, as seen in common devices such as LED strips. The original post with the PSoC Creator Project, ‘WS2812 and 5LP @ 48 MHz’ was posted in the Infineon Developer Community with the project named ws2812_test.cywrk_.Archive01.zip.

Reason to Republish
Four development boards, the micro:bit, Arduino, PSoC, and STM, were chosen for comparison. Most of those boards have been or are currently used in education, and they have a broad sample of projects with code spread across community forums and sites.

Project Example to Compare Development Boards
The addressable RGB LED (WS2812B) was chosen as the example project since LED strips are engaging with students. Example projects were found for all but the PSoC4 part 
CY8C4245AXI-473. The Modus Toolbox PSoC development environment from Infineon supports NeoPixels, but an example did not seem to be available for the PSoC4. The target audience for this project was at the education level, so off-the-shelf and ‘working’ examples were preferred.

Using Modus Toolbox, the CY8C4245AXI-473 PSoC microcontroller was not listed under the ‘Select device part numbers'.

Modus Toolbox BSP Assistant - Device Part Numbers
Modus Toolbox BSP Assistant - Device Part Numbers

A related development kit, CY8CKIT-042, associated with the same PSoC4, was not listed under the Modus Toolbox ‘Select BSP template’.

Modus Toolbox BSP Assistant - Template
Modus Toolbox BSP Assistant - Template

Understandably, the target PSoC is an older device, so some limitations were anticipated. Of course, a PSoC6 development kit could be used with the NeoPixel LEDs, but that was hardly a fair comparison against the slightly slower micro:bit or Arduino.

Finding a WS2812 PSoC4 Example Project
A WS2812 library was available for PSoC5, 
CY8C5888-LP097, by the author, Mark Hastings (Cypress Semiconductor). The example project for the WS2812 was taken from the Infineon community forum, but the project is several years old and contains broken component dependencies.

Later, I was to find another PSoC WS2812 project from the same author called FunWithLEDs. This project contains comprehensive examples of the WS2812.

Rebuilding the WS2812 Example Project
Opening the Top Design in the WS2812 PSoC5 project, some missing components were shown.

Missing Components in PSoC Top Design
Missing Components in PSoC Top Design

The missing library was not included with the WS2812 project, so this was found on another site and copied into the project's root folder.

Added WS281xlib to Project Folder
Added WS281xlib to Project Folder

To correct the missing library component in the PSoC project Top Design, the Dependencies menu in PSoC Creator was used to perform an update.

PSoC Creator Dependencies - StripLightLib Error
PSoC Creator Dependencies - StripLightLib Error

The existing dependency for the WS2812, called StripLightLib, was removed.

Lastly, the dependency for WS281xLib was added to the project dependencies, now pointing to the copy in the project’s root folder. 

PSoC Creator Dependencies - WS281xLib
PSoC Creator Dependencies - WS281xLib

The downloaded WS281xLib contains the StripLightLib library and several others worth exploring.

Contents of WS281xLib Folder
Contents of WS281xLib Folder

The missing component issue was resolved in the projects Top Design, as pictured below.

Updated Components in PSoC Top Design
Updated Components in PSoC Top Design

Compiling the project resulted in no further issues.

Complied QS2812 PSoC Creator Project
Complied WS2812 PSoC Creator Project

The PSoC target was changed to the CY8C4245AXI-473. Finally, the development board was programmed and subsequently used for the development kit evaluation.


Downloads
The dependency WS281xLib and the updated project for PSoC5, built for PSoC Creator 4.4, are available below for download. All intellectual property rights and licenses for the libraries and PSoC Projects, including those belonging to Mark Hastings, Cypress Semiconductor, and related parties, are retained and owned by those entities.

WS281xLib
WS281xLib

ws2812_test
ws2812_test

Friday, 27 December 2024

PSoC I2C Address Scanner (I2C Scan)

Introduction 
This short post covers a change to a PSoC Creator project created by Bob Marlow (Infineon Developer Community) for scanning an I2C bus.

Reason for the Updated Project
While experiencing issues when communicating with a Midas I2C display (MC20805A6W-FPTLWI-V2), the I2C address needed confirmation. Upon testing with a PSoC project (I2CScan) authored by Bob Marlow, the PSoC program did not output a response to the terminal program with an I2C address even though the Midas display was connected correctly to the PSoC. This was curious because the display was newly purchased.

Test Setup - PSoC Development Board with Midas I2C Display
Test Setup - PSoC Development Board with Midas I2C Display

Narrowing the I2C Address Range
Using two hardware connections on the Midas display, the I2C address can be configured for various I2C address options. For testing, the range of the
variable I2CAddress in the PSoC code was limited from 0x3A to 0x3F. A short delay (padding between transmissions) was added to the code to make debugging on an oscilloscope easier.

Status = I2C_I2CMasterSendStart(Address,I2C_I2C_READ_XFER_MODE);   

The Midas display did not respond to the read command shown above. However, after changing the code to use the I2C write command, the display responded with its expected address.

Status = I2C_I2CMasterSendStart(Address,I2C_I2C_WRITE_XFER_MODE);

Tera Term - Midas I2C Address
Tera Term - Midas I2C Address

The captures below illustrates the I2C replies, when the 0x3F address was used with the read and write transfer modes for the PSoC function I2C_I2CMasterSendStart.

Midas Display - NACK to Read I2C Packet
Midas Display - NACK to Read I2C Packet

The ninth bit (left MSB bit first) in the SCL clock train (yellow trace) in the above trace shows that the corresponding position in the SDA trace (blue trace) was high and therefore represents a negative acknowledgement (NACK) to the read command; the same bit position on the trace below has a low on the ninth bit (blue trace) represents an acknowledgement (ACK) to a write command.

Midas Display - ACK to Write I2C Packet
Midas Display - ACK to Write I2C Packet

For further information, see Figures 6 and 7 in the TI document ‘Understanding the I2C Bus’ for waveforms relating to I2C ACK and NACK responses.

Code Changes
The code change mentioned in the above paragraph was implemented in the PSoC TestI2CAddress function located in 'main.c'. Other changes were made in main to suit the terminal program TeraTerm.

Testing Other Devices
To ensure the code change would work with other devices, two other I2C devices were tested; an Adafruit SI1145 light sensor and an INA219 current sensor

Test Setup - PSoC Development Board with SI1145 Sensor
Test Setup - PSoC Development Board with SI1145 Sensor

Tera Term - I2C Address from SI1145 Sensor
Tera Term - I2C Address from SI1145 Sensor  

Test Setup - PSoC Development Board with INA219 Sensor
Test Setup - PSoC Development Board with INA219 Sensor

Tera Term - I2C Address from INA219 Sensor
Tera Term - I2C Address from INA219 Sensor

Downloads and Disclaimer
The updated PSoC Creator project v1.1, for a PSoC4 device, can be downloaded as linked below. The original project is copyrighted and remains the property of Jörg Meier Software as noted in the project source.

I2CScan-v1_1.cywrk.Archive01.zip

Wednesday, 13 July 2022

PSoC Silicon ID Header File Creation

Summary
This blog offers a solution to generate PSoC header files from Cypress DAT files using PowerShell scripts. Available Cypress DAT files are merged and then converted into a single header file.

There is a thread similar to this post on the Infineon website called ‘JTAG/Silicon ID reference file’.

History
Fluctuations in global chip levels have resulted in a wider range of microcontrollers seen by companies responsible for programming and testing electronic hardware. 

To accommodate changes in microcontrollers using a more automated process for creating software header files, the scripts mentioned in this blog were designed. These scripts are fully functional, however, not without limitations as this is an initial foray into splitting scripts with this type of file content manipulation. 

The scripts were written in two parts because one script was made to run in the Program Files directory that contains the relevant DAT files. The second script was made to run with the merged DAT file.

Installation Requirement
To access the DAT files, the Cypress (Infineon) PSoC Programmer should be installed. The DAT files are located at the following location - C:\Program Files (x86)\Cypress\Programmer\Devices

Example of Cypress .DAT File Listing
Example of Cypress .DAT File Listing

The DAT files contain various items of PSoC information. Of this, the device name and ID range are of primary interest. 

As an example for PSoC device CY8C4125AZI-473, the entry from file CY8C4xxx.dat is displayed below.

2,CY8C4125AZI-473, CY8C4125AZI-473, 48, 32768, 3, 04_2B_11_93, 04_2B_12_93, v33


Whether the PSoC ID is utilised to program PSoC devices or other information such as the size of the flash is needed for programming file verification, the PowerShell script could easily be adapted to suit these purposes.

Implementation
The first script called 'dat_merger.ps1' combines multiple DAT files using the PowerShell add-content command. The script was designed to handle all DAT files in the Cypress Programmer Devices directory however the script will also work on a single DAT file. 

Additionally, the first row in each DAT file is removed since this is redundant. To process the file in the next script, the merged file is saved in CSV format.

$dir = Get-Location
Write-Host "Merging Files"

$source ="$dir\*.dat"
$destination = "$dir\merge.csv"

# Remove first row and merge all files in directory
Get-ChildItem -Filter '*.dat' | ForEach-Object {
Get-Content $_ | Select -Skip 1 | Add-Content $destination
}


The second script dat_parser.ps1 removes any unwanted columns, selects only the first column of PSoC IDs, adds the text ‘#define’, formats the ID into a preferred value by stripping the formatting and then saves the result as a jtag.h file.

$dir = Get-Location
Write-Host "Parsing files in $dir"
# Grab merged csv files
$source = "$dir\merge.csv"
$destination ="$dir\jtag.h"

# Strip columns, add hash define and number format for each line, strip CSV then save as header file
Import-CSV-Delim ','$source -Header a,b, c, d, e, f, g |
Select "b","g" | ForEach-Object {$_."b" = "#define $($_."b")";$_} |
ForEach-Object {$_."g" = "0x$($_."g")";$_} |
ConvertTo-Csv -NoTypeInformation |
Select-Object -Skip 1 |
# Option for tab instead of spaces
#% { $_ -replace ‘_‘, “” -replace (‘,‘, "`t")  -replace ('"', '')} |
% { $_ -replace ‘_‘, “” -replace (‘,‘, ''.padleft(10, ' '))  -replace ('"','')} |
Out-File $destination -Encoding utf8


Output
The first script would merge DAT files. Two example files were chosen CY8C42xx-D.dat and CY8C44xx.dat.

Before Script 

1,CY8C42xx-D, CY8C42xx-D, 8, 5, 128
2,CY8C4245PVI-DS402, CY8C4245PVI-DS402, 28, 32768, 3, 17_03_11_A7, v17
2,CY8C4245FNI-DS402, CY8C4245FNI-DS402, 25, 32768, 3, 17_02_11_A7, v17
2,CY8C4246PVI-DS402, CY8C4246PVI-DS402, 28, 65536, 3, 17_01_11_A7, v17
2,CY8C4246FNI-DS402, CY8C4246FNI-DS402, 25, 65536, 3, 17_00_11_A7, v17

1,CY8C44xx, CY8C44xx, 8, 5, 128
2,CY8C4A45PVI-481, CY8C4A45PVI-481, 28, 32768, 3, 1C_02_11_AC, v17
2,CY8C4A45FNI-483, CY8C4A45FNI-483, 45, 32768, 3, 1C_03_11_AC, v17
2,CY8C4A45LQI-483, CY8C4A45LQI-483, 48, 32768, 3, 1C_00_11_AC, v17
2,CY8C4A45AZI-483, CY8C4A45AZI-483, 48, 32768, 3, 1C_01_11_AC, v17
2,CY8C4A45FNQ-483, CY8C4A45FNQ-483, 45, 32768, 3, 1C_41_11_AC, v17
2,CY8C4A45LQQ-483, CY8C4A45LQQ-483, 48, 32768, 3, 1C_40_11_AC, v17

After Script 
2,CY8C4245PVI-DS402, CY8C4245PVI-DS402, 28, 32768, 3, 17_03_11_A7, v17
2,CY8C4245FNI-DS402, CY8C4245FNI-DS402, 25, 32768, 3, 17_02_11_A7, v17
2,CY8C4246PVI-DS402, CY8C4246PVI-DS402, 28, 65536, 3, 17_01_11_A7, v17
2,CY8C4246FNI-DS402, CY8C4246FNI-DS402, 25, 65536, 3, 17_00_11_A7, v17
2,CY8C4A45PVI-481, CY8C4A45PVI-481, 28, 32768, 3, 1C_02_11_AC, v17
2,CY8C4A45FNI-483, CY8C4A45FNI-483, 45, 32768, 3, 1C_03_11_AC, v17
2,CY8C4A45LQI-483, CY8C4A45LQI-483, 48, 32768, 3, 1C_00_11_AC, v17
2,CY8C4A45AZI-483, CY8C4A45AZI-483, 48, 32768, 3, 1C_01_11_AC, v17
2,CY8C4A45FNQ-483, CY8C4A45FNQ-483, 45, 32768, 3, 1C_41_11_AC, v17
2,CY8C4A45LQQ-483, CY8C4A45LQQ-483, 48, 32768, 3, 1C_40_11_AC, v17

 

Running the second script on the merged file output from the first script results in a new file called jtag.h as shown below.

#define CY8C4245PVI-DS402         0x170311A7
#define CY8C4245FNI-DS402         0x170211A7
#define CY8C4246PVI-DS402         0x170111A7
#define CY8C4246FNI-DS402         0x170011A7
#define CY8C4A45PVI-481         0x1C0211AC
#define CY8C4A45FNI-483         0x1C0311AC
#define CY8C4A45LQI-483         0x1C0011AC
#define CY8C4A45AZI-483         0x1C0111AC
#define CY8C4A45FNQ-483         0x1C4111AC
#define CY8C4A45LQQ-483         0x1C4011AC

One of the limitations with the current implementation is the uneven padding between the PSoC device name and the ID. The parser code inserts ten white spaces which may not conform with all programming styles.

Final Thoughts
The PowerShell scripts (under GPL) have been tested on several DAT files however the outputs should be verified as part of standard practice. Improvements are welcomed!

Downloads
 

Cypress Dat Merger PowerShell Script
dat_merger.ps1

Cypress Dat Merger PowerShell Script
dat_parser.ps1

Cypress Dat Merger PowerShell Script
jtag.h
(Example of PSoC4, PSoC5)


 

Thursday, 29 April 2021

Novel Voltage Interruption Tester for IEC 61496-1

Summary
This blog provides details of a novel voltage interruption tester that demonstrates the requirements listed in the IEC 61496-1 standard, section 4.3.2.2. 

The tester was needed because certain types of electronic hardware must be tested to the IEC 61496-1 standard and dedicated testing facilities have had reduced access during the pandemic. The purpose of the tester in this blog is preliminary testing which would not replace an authorised testing facility.

Description
The interruption test hardware described in this blog was designed for DC systems to 48 V and currents to 3 A. For design constraints, interruption timing was considered important, followed by access to available hardware then output voltage regulation.

The capture below displays section 4.3.2.2 of the IEC standard which shows the timing of the three interruption tests.

Supply Voltage Interruptions
Supply Voltage Interruptions

Hardware Solutions
Off the shelf power supply evaluation boards such as the Vishay SiC461 were tested initially. To control the output voltage, a programmable resistor replaced one of the feedback elements. By using a programmable resistor, a 10 ms pulse width was achievable. However, the output voltage rise and fall times were asymmetrical and several milliseconds in duration.

Alternative solutions utilising linear regulators such as the LM317T were analysed. The linear regulator produced very sharp output voltage rise and fall times. The limitation of the linear regulator was the LM317 voltage regulation and accompanying device heat dissipation.

By utilising existing resources, such as individual benchtop supplies, a simpler solution was identified. It was likely that workspaces would have access to one dual output or two single regulated adjustable power supplies. These supplies could be used together for the switching tests.

The hardware in the system consisted of a microcontroller (PSoC) that interfaced to a pair of optocouplers (4N28) in turn driving two high-side switches (BTS50085). The output of each high-side switch was tied together with series diodes (1N5404) to produce the output.

One design weakness using this solution was the supply to output voltage drop. As the cumulative voltage drop of the high-side switch and diode changed with load current, the power supplies required adjustment to achieve the correct test voltages.

Hardware Concept
Shown below was the original concept proof of the hardware. The high-side switch datasheet lists an operating voltage to some 58 V and a current of 11 A.

Interruption Tester Concept Hardware
Interruption Tester Concept Hardware


Circuit Overview
Control signals generation was performed by a microcontroller; any type could perform the task as the signals are slow-moving. Two control signals from the microcontroller drive a set of optocouplers. For this design, an ancient pair of 4N28’s were fitted. 

The transistor output of the optocouplers switched the high-side driver inputs to 0 V. This was required as the inputs of the high-side drivers BTS50085 must be switched to 0 V to activate their outputs.

Microcontroller
An off the shelf CY8CKIT-059 Cypress development board implemented a PWM to drive two outputs for the optocouplers. 

The onboard switch and LED acted as the user interface. 

Repetitive switch presses selected a subsequent test. Flashes from the onboard blue LED indicated the test number. No flash for off, one flash for test one up to three flashes for test three.

For the top design in PSoC Creator, the first PWM output provided the timing for the voltage dip. The second PWM output configuration and some flip flops ensured that the half voltage was active before and after the first PWM changed state. Understandably there are other ways to use the PWM component, again this was a concept proof.

PSoC Creator PWM Test Setup
PSoC Creator PWM Test Setup

The PWM was configured as illustrated below. Settings were controlled from within the code.

PWM Component Setup
PWM Component Setup


The rise and fall times (10%, 90%) were 20 us and 90 us respectively
with the output driving a resistive load.

Rise Time for Resistive Load
Rise Time for Resistive Load

Fall Time for Resistive Load
Fall Time for Resistive Load

Output Waveforms
The following captures were taken when driving a resistive load.
 

Interruption Test 1 with Resistive Load
Interruption Test 1 with Resistive Load
 

Interruption Test 2 with Resistive Load
Interruption Test 2 with Resistive Load

 

Interruption Test 3 with Resistive Load
Interruption Test 3 with Resistive Load

The next captures were taken when driving a DC 12 V fan.

Interruption Test 1 with DC Fan
Interruption Test 1 with DC Fan

Interruption Test 2 with DC Fan
Interruption Test 2 with DC Fan

Interruption Test 3 with DC Fan
Interruption Test 3 with DC Fan

Output Voltages
For the three interruption tests, various loads were tested and peak voltages measured.

Interruption Test 1 with Various Resistive Loads
Interruption Test 1 with Various Resistive Loads

Interruption Test 2 with Various Resistive Loads
Interruption Test 2 with Various Resistive Loads

Interruption Test 3 with Various Resistive Loads
Interruption Test 3 with Various Resistive Loads
 

The above test results show that adjustment to the power supply voltages was required to accommodate for the system voltage drop.

PSoC Code
Listed below is the test code for the PSoC controller.


/**
* @file main.c
* @brief Basic example of IEC61496-1 tests
* @version 0
*
* History
* Version       Change Notes
* 0.0           Test code
*/

#include <project.h>
#include <stdbool.h>

/* Prototypes */
void led_flash_state(uint8 state_num);


/**
* @brief Flash LED
* @param state
*/
void led_flash_state(uint8 state_num)
{   
    while (state_num != 0)
    {
        LED_Write(true);
        CyDelay(250);
        LED_Write(false);
        CyDelay(250);
        state_num--;
    }
}

/**
* Main
*/
int main()
{                       CyGlobalIntEnable;

    
uint8 state = 0;
    uint8 state_update = false;
    
    for(;;)
    
{
    if (SW1_Read()== false)
    {
        CyDelay(200);         /* Some debounce */
        
state++;
        state_update = false;
        if (state == 4)      /* Toggle states */
        {
            state = 0;
        }
    }

    if ((state == 0) && (state_update == false))
    {
        PWM_Stop();
        state_update = true;          /* No PWM in first state */
    }
    
    if ((state == 1) && (state_update == false))
    {
        PWM_Stop();                     /* Test 1 - 10 ms 100% dip */
        PWM_WritePeriod(999u);
        PWM_WriteCompare1(110u);        /* Control PWM output 1 */  
    
    PWM_WriteCompare2(0u);
        PWM_WriteControlRegister(PWM_CTRL_ENABLE);
        PWM_Start();
        led_flash_state(state);
        state_update = true;
    }

    if ((state == 2) && (state_update == false))
    {
        PWM_Stop();                      /* Test 2 - 20 ms 50% dip */
        PWM_WritePeriod(1999u);
        PWM_WriteCompare1(200u);
        PWM_WriteCompare2(210u);         /* Control PWM output 2 for lower voltage */         PWM_Start();
        led_flash_state(state);
        state_update = true;
    }

    
if ((state == 3) && (state_update == false))
    {
        PWM_Stop();                      /* Test 3 - 500 ms 50% dip */
        PWM_WritePeriod(49999u);
        PWM_WriteCompare1(5000u);
        PWM_WriteCompare2(5010u);        /* Control PWM output 2 for lower voltage */         led_flash_state(state);
        state_update = true;
    }
  }
}

/* End */

 

Summary
For concept proof, the tests using high-side switches controlled by a microcontroller verified specific requirements detailed in the IEC 61496-1 standard. During tests, the input to output voltage drop was less than 10 %. Compensation for voltage drop was achieved by adjusting power supply voltages.

Depending on design requirements, a different microcontroller, high-side switches with a lower operating voltage, or alternative components could be selected. If isolation from the switched output voltage was not a consideration, the optocouplers could be omitted.

With access to testing facilities being limited, having the hardware to provide preliminary on bench verification can be a consolation.

Downloads
The PSoC Creator 4.4 project and schematic from the Top Design are available for download.

PSoC Creator Top Design Schematic

PSoC Creator 4.4 Project