This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

F28377xS (Implementing a Switch to enable/disable PWMs)

I'm working with the C2000 F28377xS device and want to implement a switch such that when a voltage is applied to a GPIO21 pin, two ePWM GPIO pins will output a duty cycle based on the input in the ADCINA0 pin.

I currently have the ADCINA0 pin and the two ePWM GPIO pins configured and working properly. I however want to add a single pole double throw switch to give myself more control over the PWMs & ADC pins. 

How do I modify the GPIO21 pin to be able to read ADC inputs? How do I account for debouching from the switch? I believe that it is good practice to have code such that after a signal has been high for about 10 clock cycles, it can be concluded that the switch state is good, and that the corresponding block of code can be executed.

"//GPIO setup: Input qualification?

void Gpio_Setup(void){
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO21 = 0; //enable pullup on GPIO21
GpioCtrlRegs.GPAQSEL2.bit.GPIO21 = 0; //Synch to SYSCLKOUT
GpioCtrlRegs.GPAGMUX2.bit.GPIO21 = 0; //GPIO21 = GPIO21
GpioCtrlRegs.GPADIR.bit.GPIO21 = 0;

} "

  • Hi Haitai,

    GPIO21 could drive an interrupt or could be read as a flag in a state-machine-task/final-loop-forever-while-loop.

    In it, you can start the PWM and start the ADC.  For PWM, you could configure it at this point or configure it early and then force the PWM low at that point via AQCSFRC.  You'd then stop forcing once GPIO21 comes to the enable state.

    You could always be converting the ADC though - you wouldn't need to only have it start when the switch is flipped on.

    ===

    For debouncing, I would recommend using input qualification (GPxQSELn)


    Thank you,
    Brett

  • Thank you for your response. How would I go about enabling GPIO21 as a flag in a state-machine-task?
    I want it such that based on the value of GPIO21, this will enable/disable the ePWM.
    I'm sorry. I'm relatively new to embedded processing and have been struggling. I'm having a very hard time grasping/utilizing control suite code to meet my objectives.

    Thank you for your time.
    -Haitai Ng
  • Hi,
    At the end of main(), I would assume you have something resembling a while(1) {} loop.  Inside the while loop, something like the following pseudo-code is my thought:

    main(){

    configure your 'PWM GPIOs' as GPIO outputs via GPxMUXn and have GPxDAT set low.

    configure PWM peripherals

    while(1)
    {
    if (GpioDataRegs.GPADAT.bit.GPIO21 == 1)

    enable PWMs by changing the GPIO mux (GPxMUXn) such that the PWMs are now output

    else

    disable PWMs by changing the GPIO mux (GPxMUXn) such that a GPIO output is used

    }
    }

    There are likely other options as well.


    Thank you,
    Brett

  • Thank you. I have something relatively similar to your suggested pseudo code. As you stated I should configure the PWM GPIOs and the PWm peripherals which I have done.

    Does the GpioDataRegs.GPADAT.bit.GPIO21 change based on the incoming input voltage?
  • Hi Haitai,

    When a pin is configured to be a GPIO (in the GPAMUX), GPADIR is then used to determine whether the GPIO will be an input or an output. 

    If a pin is a GPIO input or configured as any peripheral function, GPADAT will show the logic level of the pin.  If the pin is configured as a GPIO output, it will now output whatever logic level GPADAT is configured as.

    I would recommend looking at Figure 7-1 of this current device's TRM.  It takes a bit of time to fully comprehend this figure, but it tells the full story of the path between a GPIO pin and how it gets connected into the rest of the chip.

    Hopefully this helps!


    Thank you,
    Brett

  • Thank you very much Brett for the explanation and assisting me. I was able to program my MCU such that it is now meeting my desired specifications. Everything is working fine. I understand this is probably a very basic question, however its a new concept that I have learned.

    Thank you for all you do!
    -Haitai Ng