Can I read back the state of a PWM GPIO?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
StBa_721356
Level 5
Level 5
50 likes received 25 likes received 10 likes received

I want to use PWM0 to generate a 5kHz PWM signal. Inside my code I want to trigger an action on the falling edge of the PWM signal.

Can I use gpio_getPinInput() to monitor the state of P26 while it is configured for PWM?

If yes then can I also configure P26 as an interrupt source so that I don't have to do a busy-wait with gpio_getPinInput()?

0 Likes
1 Solution

Funny thing is: I tried it out today on a BCM92073X_LE_KIT and it *does* work.

I configured PWM0 @ GPIO P26 to output a 5kHz PWM signal with 50% duty cycle. So the PWM high and PWM low have the same period.

I configured P26 as output and P12 (which is dual-bonded to P26 via pin 32) as input.

Then I did a busy loop with 10 iteration which reads both P12 and P26 via gpio_getPinInput() and output it via ble_trace2().

Code:

int     i;

for (i=0;i<10;i++)

{

     BYTE          p12 = gpio_getPinInput(GPIO_PIN_12/16, GPIO_PIN_12%16);    

     BYTE          p26 = gpio_getPinInput(GPIO_PIN_26/16, GPIO_PIN_26%16);

     ble_trace2("P12:%d P26:%d\n", p12, p26);

}

Result:

P12:1 P26:1

P12:0 P26:0

P12:1 P26:1

P12:0 P26:0

P12:1 P26:1

P12:0 P26:0

P12:0 P26:0

P12:1 P26:1

P12:0 P26:0

P12:1 P26:1

So this indicates that gpio_getPinInput() does return the state of a GPIO regardless of the mode the GPIO is configured to.


View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable

Hello sbs,

Have you studied the code in pwm_tones in the current SDK 2.0.1?

We have also posted sample code here:

IoT Hackathon Challenge

http://community.broadcom.com/servlet/JiveServlet/download/38-3008/hack_pwm_tones.c.zip

Several PWM posts are on the community - Search using PWM.

Let me know if this answers your questions.

Thanks

JT

0 Likes

Hi JT,

yes, I browsed thru all the sample code and searched in the discussions but without any luck.

I know how to configure PWM but I don't know if I can get the current state of the PWM signal of lets say PWM0 which gets routed to P26.

I need to sync an action in my firmware with the falling edge of the PWM signal once. To do this I need a way to check if P26 is 0 or 1.

I think I can use gpio_getPinInput(GPIO_PIN_26/16, GPIO_PIN_26%16) to retrieve the state of P26 but I am not sure if gpio_getPinInput() would return the current state if P26 is configured for PWM.


One solution would be to connect another GPIO to P26 and use this GPIO as an input but I want to avoid losing a valuable GPIO for this.


Another solution would be to use a PWM which is dual-bonded with another GPIO (like PWM2 which is available on P14 and is dual-bonded to P38) but this would mean changing the pin assignments on our hardware.

0 Likes

gpio_getPinInput() will not return the current output level of the GPIO when the output is being driven by PWM. You have to use another GPIO or one of the bonded pins.

0 Likes

Funny thing is: I tried it out today on a BCM92073X_LE_KIT and it *does* work.

I configured PWM0 @ GPIO P26 to output a 5kHz PWM signal with 50% duty cycle. So the PWM high and PWM low have the same period.

I configured P26 as output and P12 (which is dual-bonded to P26 via pin 32) as input.

Then I did a busy loop with 10 iteration which reads both P12 and P26 via gpio_getPinInput() and output it via ble_trace2().

Code:

int     i;

for (i=0;i<10;i++)

{

     BYTE          p12 = gpio_getPinInput(GPIO_PIN_12/16, GPIO_PIN_12%16);    

     BYTE          p26 = gpio_getPinInput(GPIO_PIN_26/16, GPIO_PIN_26%16);

     ble_trace2("P12:%d P26:%d\n", p12, p26);

}

Result:

P12:1 P26:1

P12:0 P26:0

P12:1 P26:1

P12:0 P26:0

P12:1 P26:1

P12:0 P26:0

P12:0 P26:0

P12:1 P26:1

P12:0 P26:0

P12:1 P26:1

So this indicates that gpio_getPinInput() does return the state of a GPIO regardless of the mode the GPIO is configured to.


0 Likes