The next thing I would like to do is to get familiarize with the GPIO as it is one of the easiest way to read and write a single bit of data.
BOM: PSoC6 WiFi-BT Pioneer Kit, a servo motor, a green LED, a red LED, 2 potentiometer with resistance adjusted to around 300 ohm, a push button, and some jumper wires.
I start by using the application I have create during the last blog post. I leave the tcpwm1 and the clock divider untouched.
Enable a pin and named it button. Set its Drive Mode to Resistive Pull-Down. input buffer on. Resistive Pull-Down means that the pin will discharge to logic low when the pin is not connected to a logic high source. This can eliminate the undefined state when the pin is not connected. Meanwhile, input buffer on allow the pin to work as an input pin.
I have also enabled another 2 pins and named them green and red, which they will be connected to a green and a red LED later on. I chose Strong Drive. input buffer off which will let the pin transition faster and act as an output pin.
I then tried the following code on the PSoC6:
#include "cy_pdl.h"
#include "cycfg.h"
int main(void)
{
/* Initialize the device and board peripherals */
__enable_irq();
init_cycfg_all();
Cy_TCPWM_PWM_Init(tcpwm1_HW, tcpwm1_NUM, &tcpwm1_config); // initialize tcpwm
Cy_TCPWM_PWM_Enable(tcpwm1_HW, tcpwm1_NUM); // enable tcpwm1
Cy_TCPWM_TriggerStart(tcpwm1_HW, tcpwm1_MASK); //Start the tcpwm1 (initially 0.5ms high per cycle) (servo positioned at right)
for (;;)
{
if(1UL == Cy_GPIO_Read(button_PORT, button_NUM))
{
Cy_GPIO_Write(green_PORT, green_NUM, 1UL); // green LED on
Cy_GPIO_Write(red_PORT, red_NUM, 0UL); // red LED off
Cy_TCPWM_TriggerCaptureOrSwap(tcpwm1_HW, 1UL); // tcpwm1 swap to 2.5ms(left) high per cycle
}
else
{
Cy_GPIO_Write(green_PORT, green_NUM, 0UL); // green LED off
Cy_GPIO_Write(red_PORT, red_NUM, 1UL); // red LED on
Cy_TCPWM_TriggerCaptureOrSwap(tcpwm1_HW, 1UL); // tcpwm1 swap to 0.5ms(right) high per cycle
}
}
}Notice that the Cy_GPIO_Read and Cy_GPIO_Write function can be found on PSoC6 PDL API Reference page that I have mentioned on previous blog.
Initially, I have meant to program the code to have the following function:
Block diagram of servo and LED controller.
The LEDs work find just like I want them to, however, the servo is behaving weird.
I will try to troubleshoot it and update its' solution on my future blog post.



