PWM not working correctly

Recurrent H/W and software problems
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: PWM not working correctly

Post by BeanieBots »

Certainly something wrong with the circuit/transistor.
Assuming what you have is as per your diagram, with R2 lifted, R1=2k7 and R3=10k, you should see a good clean inversion of the signal (going in at R1) at the junction of R3 and the collector of Q1.
If that is not the case, then you have either a faulty Q1 or you have not built as shown in the diagram.
(I assume you don't have 50ohm load on your 'scope probe?).
Is R3 really 10k and not some order of magnitude higher or maybe open-circuit? The rise time (determined by R3 and capacitance of your probe) is VERY sloppy, suggesting OC R3.
ulli
Posts: 47
Joined: Tue Feb 09, 2021 9:48 am
Location: Monschau, Germany
Has thanked: 8 times
Been thanked: 2 times

Re: PWM not working correctly

Post by ulli »

Giving up for now, I can only restart my efforts on Sunday.

Tried this:
Replaced 2N2222A by a new one.
Added 2k7 resistor between base and ground.
Replaced 2N2222A by BS170 n-channel FET and 2k7 resistor between gate and ground by 27k for a pulse of 3V and quick gate discharge.

All to no avail. The pulse is clean directly at the processor and at the processor end of R1. It starts to deform at the base (or gate), the transistor end of R1, and becomes worse at the collector (or drain).

A capacitor of 47uF and 22nF between 10V power line and ground didn't change anything.

I'm absolutely clueless where this effect might come from.

Thanks for all your help.
The light at the end of the tunnel has been switched off for energy saving reasons.
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: PWM not working correctly

Post by BeanieBots »

The obvious at this point is that your circuit is not as drawn.
Double check the pinout of Q1 and that nothing else is connected to any pins other than what is shown in the diagram.
Leave out R2 until you get a good clean signal on R3/Q1 junction. (Inverse of GPIO pin and at 10v).

If your 'scope has two channels, can you post a pic of Ch1 on GPIO pin and ch2 on R3/Q1 junction?
It might shed some light on where the error is.
ulli
Posts: 47
Joined: Tue Feb 09, 2021 9:48 am
Location: Monschau, Germany
Has thanked: 8 times
Been thanked: 2 times

Re: PWM not working correctly

Post by ulli »

Made the circuit very simple for now: 2k7 resistor from port 27 of ESP connected to 27k resistor to ground. So just resistors involved.

I measured at port 27 (blue) and the joint of the resistors (yellow).

image.png

PWM frequency is 10kHz, PWM value is 1, resolution is 8 bits.
Looks like there is a hidden capacitor, but where? I checked the board (which is now almost not involved) and didn't find any shorts.
You do not have the required permissions to view the files attached to this post.
The light at the end of the tunnel has been switched off for energy saving reasons.
ulli
Posts: 47
Joined: Tue Feb 09, 2021 9:48 am
Location: Monschau, Germany
Has thanked: 8 times
Been thanked: 2 times

Re: PWM not working correctly

Post by ulli »

Solved! Phew!

The stray capacity is about 30 pF, so it appears to be a property of GPIO.

So I reduced R1 to 220 and R3 to 1k. Now it looks nice on a relevant time scale. If you spread the time axis by a factor of 40 or more you can still see the effect, but that's don't care.

image.png

Value = 1 of 255

image.png

Value = 51 of 255

Thanks again for all your time and efforts. For me it was the first time I had to fight hidden capacitors.
You do not have the required permissions to view the files attached to this post.
The light at the end of the tunnel has been switched off for energy saving reasons.
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: PWM not working correctly

Post by BeanieBots »

Glad you got it sorted.
30pF is around the capacitive loading of your 'scope probes!
Even long flying leads can contribute 10's of pF.
The trailing edge ringing is a bit odd though. The leading edge is classic damped ring, but the trailing edge builds up? Most odd.
Anyway, I'm seeing a friend in few weeks time and will borrow his 'scope to see if I can reproduce what you are seeing out of my own curiosity.
ulli
Posts: 47
Joined: Tue Feb 09, 2021 9:48 am
Location: Monschau, Germany
Has thanked: 8 times
Been thanked: 2 times

Re: PWM not working correctly

Post by ulli »

It was the trailing edge that made me investigate. It's still there, but now within reasonable limits, so it's ok for my purposes. Nevertheless, it would be great to see the reason, so I'm waiting for your results.

There are much higher PWM frequencies than my 15.3 kHz, so that the effect becomes even worse then. Highly interesting for PWM users outside the 50 Hz servo limit.
The light at the end of the tunnel has been switched off for energy saving reasons.
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: PWM not working correctly

Post by BeanieBots »

As mentioned earlier, I'm a few weeks away from getting my hands on a 'scope.
If nobody else chips in and you don't hear from me after a few weeks (I'm very forgetful), bump this post.
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: PWM not working correctly

Post by BeanieBots »

Finally managed to borrow a 'scope.
I was unable to reproduce your waveform. Mine were clean crisp squares both at the ESP and at the transistors.
I think it might be due to a grounding issue between your PSU and 'scope.
There is a significant underlying higher frequency in your trace which I do not see on mine. This may well be comming from a switching PSU.
ulli
Posts: 47
Joined: Tue Feb 09, 2021 9:48 am
Location: Monschau, Germany
Has thanked: 8 times
Been thanked: 2 times

Re: PWM not working correctly

Post by ulli »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Jun 17, 2023 3:28 pm Finally managed to borrow a 'scope.
I was unable to reproduce your waveform. Mine were clean crisp squares both at the ESP and at the transistors.
I think it might be due to a grounding issue between your PSU and 'scope.
There is a significant underlying higher frequency in your trace which I do not see on mine. This may well be comming from a switching PSU.
Thank you for your efforts and your valuable info. I don't currently have the time to investigate, but I'll come back to this issue later.
The fact that I found this strange waveform even on a resistors only circuit may well be a hint to a grounding issue.
The light at the end of the tunnel has been switched off for energy saving reasons.
Post Reply