yet another issue, really sorry PWM related.

Post here all questions related to LibMaple core if you can't find a relevant section!
User avatar
Mangy_Dog
Posts: 90
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

yet another issue, really sorry PWM related.

Post by Mangy_Dog »

Ok same project as before but a new strange unexpected behavior issue happening.

So I have some leds being ground sunk through the mcu for control.

Using PWM to control brightness. My green and blue leds on pins
PB1 PB4 PB5 seem to behave as expected in that full DUTY turns them off and low duty turns them on...
The leds are being provided by 3.3v

However I have two red leds on pins PA11 and PA15. Again being ground sunk through the MCU.

These arent behaving correctly. but in a strange way im struggling to understand.

Firstly analogue write converts 8 bit to 16 bit duty, so If i get to 255, this should turn off the LED... But it doesnt, the led is still on be it dimmer.

I tried pwmWrite at 65535 and that does nothing...

If i digitalWrite HIGH on its own the Led turns off as expected, but if i use analogWrite before it stays stuck in its PWM state.

I did just notice that pinMode PWM is set, this is a new one for me... I guess ill need to swap between pinMode PWM and OUTPUT when I want to turn the led off?

Or is there something wrong with PWM mode if its not turning the led off?
Just a dogs body developer, mostly making props and stuff...
User avatar
Mangy_Dog
Posts: 90
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: yet another issue, really sorry PWM related.

Post by Mangy_Dog »

ok current fix is just a function that sets OUTPUT in pin mode when pwm is 65535 and sets the pin high, and sets it into PWM mode for everything else...

Short term fix
Just a dogs body developer, mostly making props and stuff...
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: yet another issue, really sorry PWM related.

Post by stevestrong »

So you say PB1,4 and 5 works correctly and PA11 and 15 do not?
Strange.
It maybe has to do with the fact that PA11 was remapped if I remember correctly?
Still F103C8 generic + libmaple?
Please always mention your environment to make us easier to follow your issue.
User avatar
Mangy_Dog
Posts: 90
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: yet another issue, really sorry PWM related.

Post by Mangy_Dog »

Sorry yes F103C generic Libmaple Rogers core.

PB1 4 5 work correctly, those are on Green and blue leds, PA11 PA15 are on red. It might be that the leakage voltage is just enough to keep the reds lit and the green and blue not lit....

I dunno... or its just those pins.

Like i say as a short term fix ive implemented switching between OUTPUT mode and PWM mode so i can still get greyscale but turn the led off as well... Might not be the most efficient way of controlling an led on the mcu but should work ok...
Just a dogs body developer, mostly making props and stuff...
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: yet another issue, really sorry PWM related.

Post by mrburnette »

Mangy_Dog wrote: Sun Oct 25, 2020 12:21 pm ...
PB1 4 5 work correctly, those are on Green and blue leds, PA11 PA15 are on red. It might be that the leakage voltage is just enough to keep the reds lit and the green and blue not lit....
...
I dunno... or its just those pins.
LED Vf.jpg
LED Vf.jpg (22.94 KiB) Viewed 4175 times
Normally, I use the output port pin to "sink" the LED with each LED having a different resistor value to +3.3 Volts to account for different Vd across the LED junction. PWM still requires the current limiting resistors, so actually complicates things a bit unless variable brightness is a requirement.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: yet another issue, really sorry PWM related.

Post by stevestrong »

I would not implement workarounds unless the problem is understood and you know for sure that there is no other solution.
You should check the PA15 PWM on a bpluepill.
User avatar
Mangy_Dog
Posts: 90
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: yet another issue, really sorry PWM related.

Post by Mangy_Dog »

I already scoped PA15 and at 65535 there is still a slight drop at the end of the cycle. But its soooooooo short my scope is having trouble catching it so it jitters around a bit.

Off hand check on the calculator its going to be 0.2ns 1000000ms/550hz/65535 bits But that small dip was enough to keep the led dimly on
Just a dogs body developer, mostly making props and stuff...
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: yet another issue, really sorry PWM related.

Post by stevestrong »

And how is the output on PBx pins compared to PA15? Same?
User avatar
Mangy_Dog
Posts: 90
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: yet another issue, really sorry PWM related.

Post by Mangy_Dog »

They scope the same. But because its such a small amount and theyre not red, thats why they dont light up.
I also could manually latch on by reducing the time scale...
Image This seems to be happening at the end of each pwm cycle. the PWM control is in the setup portion of the sketch not the loop, so its not like its being retriggered each loop causing this dip
Just a dogs body developer, mostly making props and stuff...
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: yet another issue, really sorry PWM related.

Post by stevestrong »

This behavior is normal according to the reference manual.

There are two ways to solve your issue:
1 - your workaround
2 - choose an update value of 65535 for the timers. In this case, when the compare value is greater than or equal the update value, the output will be a clean "1", without a glitch.
Post Reply

Return to “General discussion”