Below are the materials that I have used in this blog, do prepare those items so you can follow what I have done if you wish so.
BOM: PSoC6 WiFi-BT Pioneer Kit, 1 LED, 1 potentiometer with resistance adjusted to around 300 ohm.
When I'm trying to find some step by step guide for PSoC6 online, I found the video below from Cypress's website.
https://www.cypress.com/video-library/PSoC/modustoolbox-101-lesson-2-3-pwm/610036
Unfortunately, I can't embed the video in this blog because the Service timed out! Please try again soon. error keep pooping out, so I have just put the link here.
In this video, Alan used a different way to mimic the Hello World application in the example code. I think this is a good approach to get myself familiarize with ModusToolbox and PSoC6.
You can read through this Device Configurator Guide to get yourself prepared before proceeding.
Following the guide, I opened up Device Configurator in ModusToolbox. Device Configurator is a Tool you can find in ModusToolbox to help you configure yr our pins, peripherals, clock frequency, and so on.
The Device Configurator can be found in the Quick Panel > Tools.
Below are some views in the Device Configurator:
You can configure the peripherals such as timer and peripheral-clocks in the Device Configurator.
First, I have clicked to the Peripheral-Clock tab to configure the peripheral clock.
I then chose a 16-bit divider for my peripheral clock and set the divider value to 10000 to get a 10kHz clock.
At the right bottom, you can click to Code Preview tab to see the code generated according to your parameter setting. You can look through it and copy it for further modification to implement in different type of cases.
I then go the Peripheral tab and chose to activate the TCPWM[0] 32-bit Counter 0 and named it tcpwm1. At the right hand side, you can adjust the parameters of the tcpwm1. In my case, I have set the period to 10000 and compare value to 5000. Since my peripheral clock is 10kHz, setting 10k count for my period and 5k count compare value will give me a 1Hz clock cycle and a 50% duty cycle. I have also assign the 16-bit Divider 0 clk that I have configure previously as the input Clock Signal.
I then scroll down to the Output section, and assign the pin for PWM_n(line_compl). You can look through the datasheet of your board and choose the pin that has the location that is most favorable for you. I have chosen the P9[7] in this case. Similarly, you can look through the code in the Code Preview if you wish so.
When I click to the Pins tab, I have notice that ModusToolbox have already setup the P9[7] for me, all I have to do is just give a name to the pin. You can ignore this step as ModusToolbox will use the default name for it and the application will still work anyway even though you don't name it.
The next thing you need to do is write a few line of codes in the main.c to initialize, enable, and start the tcpwm.
The relevant functions required to interact with the tcpwm can be found through the Open PWM(TCPWM) Documentation link found in the Device Configurator.
In my case, I included the "cycfg.h" header file and initialize the cycfg using the added the 3 lines code below in the main.c and run it on the PSoC6.
#include "cy_pdl.h" #include "cycfg.h"
init_cycfg_all(); Cy_TCPWM_PWM_Init(tcpwm1_HW, tcpwm1_NUM, &tcpwm1_config); Cy_TCPWM_PWM_Enable(tcpwm1_HW, tcpwm1_NUM); Cy_TCPWM_TriggerStart(tcpwm1_HW, tcpwm1_MASK);
And it works, a 1Hz blinking LED with 50% duty cycle using Device Configurator.
GitHub link: https://github.com/wanfp97/Hello-World-using-TCPWM
Top Comments