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
Connected Cloud Challenge
  • Challenges & Projects
  • Design Challenges
  • Connected Cloud Challenge
  • More
  • Cancel
Connected Cloud Challenge
Blog #7 Resolving issue met in previous blog post
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: wanfp97
  • Date Created: 8 May 2020 5:10 AM Date Created
  • Views 737 views
  • Likes 2 likes
  • Comments 0 comments
  • gpio;
  • psoc 6
Related
Recommended

#7 Resolving issue met in previous blog post

wanfp97
wanfp97
8 May 2020

In my previous blog post, #5 GPIO read and write , I faced an issue where my TCPWM keep swapping its compare value and causing the servo to act weirdly.

After some troubleshooting, I have found that the issue occur due to I place the Cy_TCPWM_TriggerCaptureOrSwap(tcpwm1_HW, 1UL);  at the part where I poll the logical status of the GPIO and thus causing the TCPWM to swap its compare value each time the GPIO logical status is checked.

To resolve this issue, the easiest solution would be not using the polling method and use interrupt method instead.

I have checked how to implement the interrupt method in PSoC6 in my previous blog post, #6 GPIO interrupt .

In this blog post, I will utilize the GPIO interrupt and try to resolve the issue that I have faced in my previous blog post#5 GPIO read and write.

 

BOM: PSoC6 WiFi-BT Pioneer Kit, a red LED, a green LED, a servo motor, a push button, jumper wires, and 2 potentiometer with resistance adjusted to be around 300 ohm.

GitHub: https://github.com/wanfp97/PSoC6-ServoControl-using-GPIO-interrupt

 

As previous, I have create a new Empty_PSoC6_App.

image

configuring my TCPWM with a period of 20ms and pulse width of 0.4ms and 2.4ms.

You can refer to my previous blog post on #3 Familiarize with Device Configurator to know the details on how to configure it using Device Configurator.

 

image

Setting the pins the same way as in #5 GPIO read and write.

 

image

In the main.c:

#include "cy_pdl.h" to include Peripheral Driver Library.

#include "cycfg.h" to include the library for Device Configurator.

#include "cyhal.h" as the GPIO interrupt function that I'm going to use come from this library.

image

declare the function prototype for the interrupt service routine (ISR) and also a Boolean type variable to handle the interrupt flag.

 

image

in the int main(), enable the interrupt, initialize all the configuration done in Device Configurator.

Initialize, enable, and trigger start the tcpwm1.

assign the ISR handler to the button pin using cy_hal_register_callback() function.

enable the interrupt event for button pin. Note that CYHAL_GPIO_IRQ_BOTH is used since I need to interrupt on both rising and falling edge of the button pin to interrupt when the button is pressed or released.

image

You can change according to this table for different interrupt requirements.

 

image

In the for(;;) loop:

If button is pressed:

clear the interrupt flag to prepare it for the next interrupt

then read the logical level of the button pin using the Cy_GPIO_Read() function

and then add the task to be done according to the logical level of the button pin.

 

The final product works like this:

image

Note that I'm using active high connection for both the LEDs and the button.

 

Recall block diagram designed in #5 GPIO read and write:

image

The system works exactly like the block diagram, therefore, it can be say that the issue is resolved.

  • Sign in to reply
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