cancel
Showing results for 
Search instead for 
Did you mean: 

Smart Bluetooth

Anonymous
Not applicable

I would like to disengage PWM and use the pin as a GPIO - input/output.

How do I do that ?

Functions:

     void pwm_disableChannel(UINT32 mask);

     void pwm_setReset(UINT32 mask, BOOL32 resetEnable);

only stop the PWM locking the output on high or low level.

The pwm_tones sample app conveniently disables the gpio output with:

     // In state 4, disable output and the PWM entirely and insert an internal pull-down on the GPIO.

     gpio_configurePin((TONES_LED1_GPIO) / 16, (TONES_LED1_GPIO) % 16, GPIO_OUTPUT_DISABLE | GPIO_PULL_DOWN, 0);

but that is not what I want. I want to reuse this GPIO, not disable it.

You can try to configure the pin back as gpio output with:

gpio_configurePin

but then when you try to set the level the output may get inverted depending on what level the PWM stopped at.

So if PWM stopped at high level later when you set 0 you will get 1, when you set 1 you will get 0.

When PWM stops at low level everything is normal.

Any idea how to properly reconfigure the pin from PWM to gpio ?

0 Likes
1 Solution
Anonymous
Not applicable

When you disable GPIO then you cannot see what PWM's level is since its output is not connected to the pin.

Try to start/disable PWM until it outputs HIGH level on GPIO - if the duty cycle is 50% you have 50% chances to do that each time.

Then you can disable GPIO, enable it again and the level will be HIGH on GPIO even if you enable it as LOW.

View solution in original post

8 Replies
Anonymous
Not applicable

BTW, I think in pwm_tones.c there is a bug:

  // Disable the channel.

  pwm_setReset(PWM3, 1);

I think it should be:

  // Disable the channel.

  pwm_setReset( pwmIdToMask(PWM3), 1);

0 Likes
MichaelF_56
Moderator
Moderator

I'll ask one of the developers to respond Lukasz. It may take a couple of days.

0 Likes
JaWa_2142591
New Contributor II

Your assumption looks right to me. The parameter mask of pwm_setReset() should be used with bit mask instead of a value.

0 Likes
JaWa_2142591
New Contributor II

For setting the pin from PWM to GPIO, you can call gpio_configurePin() after pwm reset like below.

// In state 4, disable output and the PWM entirely and insert an internal pull-down on the GPIO.
gpio_configurePin((TONES_LED1_GPIO) / 16, (TONES_LED1_GPIO) % 16, GPIO_OUTPUT_DISABLE | GPIO_PULL_DOWN, 0);

// Disable the channel.

pwm_setReset(pwmIdToMask(PWM3), 1);

gpio_configurePin((TONES_LED1_GPIO) / 16, (TONES_LED1_GPIO) % 16, GPIO_OUTPUT_ENABLE, 0);

I tried this on 20737 tag board. I can see it correctly outputs high or low according to the value from gpio_configurePin().

Can you please try above and let me know if it works for you?

Anonymous
Not applicable

There is nothing new in the code above besides fixing the issue with pwm_setReset.

I will post some code to reproduce the issue soon.

0 Likes
Anonymous
Not applicable

When you disable the GPIO and setup the GPIO pulldown - are you seeing that the PWM still stops at high?

Anonymous
Not applicable

When you disable GPIO then you cannot see what PWM's level is since its output is not connected to the pin.

Try to start/disable PWM until it outputs HIGH level on GPIO - if the duty cycle is 50% you have 50% chances to do that each time.

Then you can disable GPIO, enable it again and the level will be HIGH on GPIO even if you enable it as LOW.

View solution in original post

Anonymous
Not applicable

I'm also facing same issue.

If somebody resolves this, please tell me the way.

0 Likes