You are here

More PDL Examples - Wiggling Pins | Cypress Semiconductor

More PDL Examples - Wiggling Pins

Let's see how many ways we can wiggle a pin! OK, there are too many, so let's limit the discussion to firmware-driven pins and just mess about with some more PDL functions instead! I'll point out a few tips and tricks along the way.

I'll start with the humble output pin and I'll wiggle pin 7 on port 13 because it is connected to LED9 (the red one) on the Pioneer kit. The full-featured, no-holds-barred, control-freaks-and-experts-only method is to use the Cy_GPIO_Pin_Init() function. It looks innocent enough, with just three arguments for the port, pin number, and a pointer to a configuration struct.

cy_en_gpio_status_t Cy_GPIO_Pin_Init(
    GPIO_PRT_Type * base,
    uint32_t pinNum,
    const cy_stc_gpio_pin_config_t * config );

The first two are just telling the function which pin to initialize. But that configuration guy is a bit mean!

typedef struct {
    uint32_t outVal;         /**< Pin output state */
    uint32_t driveMode;      /**< Drive mode */
    en_hsiom_sel_t hsiom;    /**< HSIOM selection */
    uint32_t intEdge;        /**< Interrupt Edge type */
    uint32_t intMask;        /**< Interrupt enable mask */
    uint32_t vtrip;          /**< Input buffer voltage trip type */
    uint32_t slewRate;       /**< Output buffer slew rate */
    uint32_t driveSel;       /**< Drive strength */
    uint32_t vregEn;         /**< SIO pair output buffer mode */
    uint32_t ibufMode;       /**< SIO pair input buffer mode */
    uint32_t vtripSel;       /**< SIO pair input buffer trip point */
    uint32_t vrefSel;        /**< SIO pair reference voltage for input buffer trip point */
    uint32_t vohSel;         /**< SIO pair regulated voltage output level */
} cy_stc_gpio_pin_config_t;

OK! Breathe! Don't be scared! I told you this was the expert method! Actually it is easier than it looks and this program should illustrate that.

    cy_stc_gpio_pin_config_t pinConfig =
        .outVal =       1UL,                    
        .driveMode =    CY_GPIO_DM_STRONG,      
        .hsiom =        0,                      
        .intEdge =      CY_GPIO_INTR_DISABLE,
        .intMask =      0UL,
        .vtrip =        CY_GPIO_VTRIP_CMOS,
        .slewRate =     CY_GPIO_SLEW_FAST,
        .driveSel =     CY_GPIO_DRIVE_FULL,
        .vregEn =       0UL,                 
        .ibufMode =     0UL,                   
        .vtripSel =     0UL,                 
        .vrefSel =      0UL,                   
        .vohSel =       0UL               
    Cy_GPIO_Pin_Init( P13_7_PORT, P13_7_NUM, &pinConfig );
        Cy_GPIO_Write( P13_7_PORT, P13_7_NUM, ! Cy_GPIO_Read( P13_7_PORT, P13_7_NUM ) );
        Cy_SysLib_Delay( 100 );

Walking through the code, I initialize the pinConfig struct as follows.

  • outVal is the initial state of the pin (what do I want it to be after initialization and before the wiggling starts)
  • driveMode determines whether it is an input or output and whatr to do when it is coonnected to external hardware (strong means it will control the external LED)
  • hsiom is the internal connection, which I am not using because this is a firmware-controlled pin
  • intEdge is the interrupt type for an input pin
  • intMask enables the port interrupt for this pin
  • vtrip determines the voltage at which an input pin changes state
  • slewRate is the speed at which the pin responds to a change - either fast or slow
  • driveSel determines the strength to drive the pin

Most of that is pretty obvious really. After driveSel there are a bunch of SIO-specific options that do not apply to simple GPIOs.

So, I have initialized my pin and then I wiggle it by reading its state, inverting that, writing it back to the pin and then waiting for 100 milliseconds before repeating the process. Blinky! Now, before you despair of all the code you are going to need for your pins, let's make this easier. There is a very friendly alternative to the Cy_GPIO_Pin_Init() function called Cy_GPIO_Pin_FastInit(). This guy hides all the difficult stuff that most of us never use and just asks you for the drive mode and the connection. Here is my simplified blinky.

    Cy_GPIO_Pin_FastInit( P13_7_PORT, P13_7_NUM, CY_GPIO_DM_STRONG, 1, HSIOM_SEL_GPIO );
        Cy_GPIO_Write( P13_7_PORT, P13_7_NUM, ! Cy_GPIO_Read( P13_7_PORT, P13_7_NUM ) );
        Cy_SysLib_Delay( 100 );

All that configuration data has gone away, which I like, but I still have that ugly read-modify-write code with Cy_GPIO_Read() and Cy_GPIO_Write(). PSoC 6 pins have a handy "invert" bit and the PDL gives us a handy Cy_GPIO_Inv() function that writes to it and makes my program even simpler.

    Cy_GPIO_Pin_FastInit( P13_7_PORT, P13_7_NUM, CY_GPIO_DM_STRONG, 1, HSIOM_SEL_GPIO );
        Cy_GPIO_Inv( P13_7_PORT, P13_7_NUM );
        Cy_SysLib_Delay( 100 );

I think this is a really compact program but I can make it even simpler and more maintainable (is that a real word?). You may have noticed that I have not used the schematic file yet. My next step is to use a pin component (GPIO_PDL) and lock it to P13.7 in the resources file.

PSoC Output Pin Customizer

PSoC Creator Pin Selection

By doing this, PSoC Creator initializes the pin for me and so my FastInit call goes away. It also creates macros for the port and pin, so my new program looks like this.

        Cy_GPIO_Inv( LED9_PORT, LED9_NUM );
        Cy_SysLib_Delay( 100 );

There is another reason for working this way - maintainability (yeah, it's a word!). In the first three examples I write directly to the pin registers from firmware. That's fine but if I ever want to wiggle a different pin I need to edit all the code. I can make that better by defining a couple of macros (e.g. #define LED9_PORT P13_7_PORT) and then I can change the pin with a simple edit and rebuild. That works really well but you need to remember all the pins you are accessing in firmware this way and be sure not to map another function to them in the PSoC Creator resource file. Your results will not be super if you try to write to a pin that is being driven from a PWM!!!

Before I go, there is one more function I want to tell you about - Cy_GPIO_ReadOut(). It is a lot like Cy_GPIO_Read() except it reads the state of output driver instead of the input buffer. This is important because the input buffer only refelects the state of the output if the pin is configured to be both and input and an output.

PSoC Creator Customizer Output and Input

If I do not check that extra box then Cy_GPIO_Read() will keep reading the same value, and my LED will not blink, whereas Cy_GPIO_ReadOut() always behaves nicely. Just for fun, here is one last version of blinky.

        Cy_GPIO_Write( LED9_PORT, LED9_NUM, ! Cy_GPIO_ReadOut( LED9_PORT, LED9_NUM ) );
        Cy_SysLib_Delay( 100 );

At the start of this blog I intended to cover both output and input GPIO. But I think I've filled your heads up, so I'll stop now and will write about inputs next week.



marthawilliam008_3278421's picture


vxh01011_3284531's picture

This is introducing psoc creator issued news and information about pdl example wiggling. The instructions you have to read for pay someone to do your assignment australia assignments and essays for all of them.

ianmugoya18_3285061's picture

Me thinks more information would help the few of us with little awareness of the same.


antonia.cummins22_3287486's picture

In this manner, relaxin may expand the sum and rate of tooth development through its impact on the periodontal tendon (PDL). The motivation behind this examination was to quantify the impact of relaxin on orthodontic Write My Essay For Me development and PDL structures. In-vitro motorized challenging and tooth adaptability evaluations showed that the PDL of the mandibular fangs in the relaxin preserved rats had lessened yield load, strain, and firmness. The greater part of this examination has concentrated on operators that impact bone digestion, for example, parathyroid hormone, estrogen, and phosphodiesterase.

mariiykedo_3304631's picture

That is an interesting approach. However I still do not understand what should stay or go. Of course language is influenced by different factors every time period, but anyway it is a significant feature of every people.

tomaswilson18_3321431's picture

Thanks for sharing this information.. these metrics will come in handy when i am making my tankless water heater Useful in every sense. Thank you.

tomaswilson18_3321431's picture

Abit complicated for me but i appreciate the effort. As most ac repair near me involve less complicated calculations. 

본 사이트의 모든 컨텐츠와 자료는 "있는 그대로" 제공됩니다. CYPRESS SEMICONDUCTOR와 해당 공급자는 그 목적에 관계 없이 이러한 자료의 적합성에 대한 표현을 하지 않으며 상업성, 특정 목적에의 적합성, 권리 및 제3자 지적 재산권의 비침해에 대한 모든 묵시적 보증과 조건을 포함하여(이에 제한되지 않음) 이러한 자료와 관련한 모든 보증과 조건을 부인합니다. CYPRESS SEMICONDUCTOR에서는 명시적 또는 묵시적으로 금반언이나 여타의 다른 방법으로 라이센스를 부여하지 않습니다. 이 사이트의 정보를 사용하려면 제3자의 라이센스 또는 CYPRESS SEMICONDUCTOR에서 제공하는 라이센스가 필요할 수 있습니다.

이 사이트의 컨텐츠에는 특정 사용 지침이나 제한이 포함되거나 그러한 제한이 적용될 수 있습니다. 모든 게시물과 이 사이트 컨텐츠 사용에는 사이트 약관이 적용됩니다. 이 컨텐츠를 사용하는 제3자는 제한 또는 지침을 따르고 이 사이트의 약관을 준수할 것이라는 데 동의합니다. Cypress Semiconductor와 그 공급자는 컨텐츠와 자료, 그 제품, 프로그램 및 서비스를 언제든 수정, 삭제, 개조, 개선, 향상 및 기타 변경하거나 예고 없이 컨텐츠, 제품, 프로그램 또는 서비스를 이동 또는 중단할 수 있는 권리를 보유합니다.