• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM signal to DC

Status
Not open for further replies.

Huttojb1

Member
Hey all

Need help with a PWM signal.

I have a PWM signal which when read on a DMM I see a RMS of 14v, 10v, 8v, 6v, 4v and 2v depending on input selection.

Unfortunately I am unable to measure the signal through my PICCO scope as it's not quick enough.

I'm looking to change the signal to a DC voltage dependant of the input selection. So I'm looking to have a voltage between 0v and 5v to read into my ADC. So I'll probable use a potential divider to drop the voltage by a third and looking at a low pass filter / RC Filter to smooth the PWM to a DC voltage and the DC voltage to vary in relation to the Duty cycle.

Problem is, I do not know the frequency of the PWM, I have asked to borrow my friends scope but is there anything I can do to achieve this without knowing the frequency

Jason.
 

alec_t

Well-Known Member
Most Helpful Member
Welcome to ETO.
Unless the duty cycle is changing rapidly you could guestimate the lowest possible PWM frequency and use a filter with an RC time constant of, say, at least 20 times the period of the PWM, depending on the accuracy you need.
 

Huttojb1

Member
Welcome to ETO.
Unless the duty cycle is changing rapidly you could guestimate the lowest possible PWM frequency and use a filter with an RC time constant of, say, at least 20 times the period of the PWM, depending on the accuracy you need.
Thanks Alec_t.

Thank you for the warm welcome, alittle background on me.. work in Aerospace electronics in Birmingham U.K. Previously worked in electric steering in automotive and CANbus communication.

No the duty Cycle isn't changing quickly, it's my gear selection on my kit car ECU, so for each gear on my car I have a different duty Cycle.

How can I guestimate a frequency? I don't need an accurate read, I just need to be able to know it has changed gear?

Jason.
 

alec_t

Well-Known Member
Most Helpful Member
How can I guestimate a frequency?
You could use the PWM source to clock a multi-stage counter such as a CD4020, and monitor the final stage (Q14) output.
 

MikeMl

Well-Known Member
Most Helpful Member
I showed how to filter PWM into a smoothed DC level in post #33 in this forum thread. You could do something similar.

It would be nice to know what the actual Pulse Rep rate is (it was 500Hz in the linked example). That will tell us how complex a low pass filter it will take to convert the various duty-cycles into a smooth signal. Once you know that, building a four step or five step window comparitor would allow you to display either a LED per gear, or even a seven-segement numeric readout.

It would take an oscilloscope to read the pulse rate, and the pulse-width corresponding to each gear.
 

Dr_Doggy

Well-Known Member
I once used some simple code to read the pwm of my RC helicopter ESC controller:

int resolution = 10;
long pos_counter = 0;
long neg_counter=0;
while (pin == 0){} // wait for starting edge
while (pin == 1){pos_counter++;delay_us(resolution );}
while (pin == 0){neg_counter++;delay_us(resolution );}

calculate_based_on_time_periods(pos_counter, neg_counter );
 

Tony Stewart

Well-Known Member
Most Helpful Member
If you can record the signal in your audio input, you can measure frequency exactly using Audacity and other tools.
 

Huttojb1

Member
Thanks for the replys, seems like I going to have to borrow my mates scope...

Let me explain the application, I have a kit car with a CBR1000 engine installed. Over the last few months I have been changing the dash, the old dash had a 12v LED installed to indicate neutral gear from the signal discussed above from the engine ECU (14v rms PWM duty Cycle)

I want to be able to identify all gears and display on a LCD.

Thanks MikeMI for your comments and it does seem like I need the frequency to build a valid RC filter, but I won't need a comparator because the DC voltage will go direct to my Microcontroller and I can read the voltage to know my gear selection. Don't need an amazing resolution as long as I can differentiate from the 6 gears it doesn't matter, I can also have a fair bit of ripple on the signal as long as the signals are separate and in a large enough window to see a change.

Tony, if I don't get the scope over the next few days I will be tapping you to discuss more about your idea. Thank you.

And Dr Doggy, thanks for your comments and I have been thinking in writing a quick capture program on my microcontroller to see frequency but didn't want to waste my time... if I cannot get the scope I will have to do something. I'm hoping to get the scope over the next few days so will be coming back here to discuss my filter cct.

Thanks all.

Jason.
 

Les Jones

Well-Known Member
Most Helpful Member
If the signal is going to a microcontroller why not just measure the length of the positive or negative part of the PWM signal ?

Les.
 

spec

Well-Known Member
Most Helpful Member
Hi Hutto,

Just put a 10K resistor in series with the PWM signal and connect a 100nF (0.1uF) ceramic capacitor from the free end of the 10K resistor to 0V.

A DC signal, proportional to the PWM mark-to-space ratio, will be across the capacitor.

If that does not get the result that you want, just place more capacitors across the 100nF capacitor (but keep the ceramic capacitor connected): 220uF (0.22uF), 470nF (0.47uF), 1uF, 2.2uF, 4.7uF, 10uF, 22uF, 47uF, 100uF, 220uF, 470uF.

When the DC voltage is sorted, post what the DC voltage readings are and we can work out a suitable attenuator, if necessary, to get the voltages you need for your processor.

spec
 

Tony Stewart

Well-Known Member
Most Helpful Member
Thanks for the replys, seems like I going to have to borrow my mates scope...

Let me explain the application, I have a kit car with a CBR1000 engine installed. Over the last few months I have been changing the dash, the old dash had a 12v LED installed to indicate neutral gear from the signal discussed above from the engine ECU (14v rms PWM duty Cycle)

I want to be able to identify all gears and display on a LCD.

Thanks MikeMI for your comments and it does seem like I need the frequency to build a valid RC filter, but I won't need a comparator because the DC voltage will go direct to my Microcontroller and I can read the voltage to know my gear selection. Don't need an amazing resolution as long as I can differentiate from the 6 gears it doesn't matter, I can also have a fair bit of ripple on the signal as long as the signals are separate and in a large enough window to see a change.

Tony, if I don't get the scope over the next few days I will be tapping you to discuss more about your idea. Thank you.

And Dr Doggy, thanks for your comments and I have been thinking in writing a quick capture program on my microcontroller to see frequency but didn't want to waste my time... if I cannot get the scope I will have to do something. I'm hoping to get the scope over the next few days so will be coming back here to discuss my filter cct.

Thanks all.

Jason.
I'll decide depending on what you determine with frequency...

But an AUX audio PC input should be able to hear it and see it on PC with free AUDACITY ( like a scope and spectrum analyzer) . not sure why Pico would not.

YOU MUST you use twisted pair signal/gnd when wire is more than a couple feet. and sometimes more than 3 inches depending on slew rate.

There are several methods to logically detect PWM, Integrate and hold, trailing edge Sample & Hold on a sawtooth sync'd to PWM frequency to get a stable voltage on 1st pulse and every pulse.,, LPF then 6 cascaded window comparator detectors ( like a 3 bit flash ADC )



RMS of 14v, 10v, 8v, 6v, 4v and 2v
 
Last edited:

Huttojb1

Member
If the signal is going to a microcontroller why not just measure the length of the positive or negative part of the PWM signal ?

Les.
Les - I agree, but I only have 2 Capture and 3 timers on my microcontroller and I need the timers to monitor the RPM and Speed sensor. Because the Gear selection can be sampled very slowly this is why I thought of turning the PWM to a DC voltage so i can use one of my 10 ADC channels.

Hi Hutto,

Just put a 10K resistor in series with the PWM signal and connect a 100nF (0.1uF) ceramic capacitor from the free end of the 10K resistor to 0V.

A DC signal, proportional to the PWM mark-to-space ratio, will be across the capacitor.

If that does not get the result that you want, just place more capacitors across the 100nF capacitor (but keep the ceramic capacitor connected): 220uF (0.22uF), 470nF (0.47uF), 1uF, 2.2uF, 4.7uF, 10uF, 22uF, 47uF, 100uF, 220uF, 470uF.

When the DC voltage is sorted, post what the DC voltage readings are and we can work out a suitable attenuator, if necessary, to get the voltages you need for your processor.

spec
Thanks Spec, this is what I wanted, I don't mind a trial and error session until I get the correct value. I just didn't know what capacitors values to use.... I will be trying these tomorrow, but I can also fetch my mates scope tomorrow..... so I might just get his Scope and see the frequency.


I'll decide depending on what you determine with frequency...

But an AUX audio PC input should be able to hear it and see it on PC with free AUDACITY ( like a scope and spectrum analyzer) . not sure why Pico would not.

YOU MUST you use twisted pair signal/gnd when wire is more than a couple feet. and sometimes more than 3 inches depending on slew rate.

There are several methods to logically detect PWM, Integrate and hold, trailing edge Sample & Hold on a sawtooth sync'd to PWM frequency to get a stable voltage on 1st pulse and every pulse.,, LPF then 6 cascaded window comparator detectors ( like a 3 bit flash ADC )

RMS of 14v, 10v, 8v, 6v, 4v and 2v
Tony, I think my Pico didn't monitor the signal correctly due to the speed of the signal, hopfully with my mates scope I will be able to see whats going on by the end of play tomorrow.

Thanks all for your help

Jason
 

atferrari

Well-Known Member
You Pico scope isn't it able to show 20 KHz?
 

Huttojb1

Member
You Pico scope isn't it able to show 20 KHz?
The spec on the PC Based scope is

upload_2016-12-20_22-50-55.png

When i tried to monitor the signal it was all over the place and just looked like noise.... My ground was ok, so I presumed that the PWM frequency was quicker then I could monitor.

I will know more when I get the better scope tomorrow

Jason
 

KeepItSimpleStupid

Well-Known Member
Most Helpful Member
Basically your RC filter will be slow to respond if RC is too high. If RC is too low, you won't see a change. You want about 5 time constants to be within 99%. So emperically you would want the filter to be at 99% quickly. So switch gears and watch the RMS voltage of the voltage before the filter, but your voltmeter may not respond to that frequency.

So, the RMS voltage of the input shoud track the filtered voltage quickly. Note the freq response of the RMS meter and
the integration time
 

Huttojb1

Member
Hey all

Ok, I have managed to monitor my "PWM" signal, as you can see in image IMG_4097.
IMG_4097.JPG
Now, to my surprise it's not PWMing. The signal I saw on my pico scope was the same as above but I thought I was missing something.

I'll explain what I have done, I have a kit car which I have removed the dash and trying to re-do the dash "my way". So the signal I am monitoring is the original dash LED connections which illuminate a led when neutral was selected.

I anticipated that the signal would drop below 12v to indicate other gears but because it was only a 12v LED this would only illuminate when neutral was selected.

Now back to today. The signal I am monitoring is a 12v source but ground reference from my gear selection wire. After monitoring the 2 original signals I can see a switching interference, so I did the same test but using a direct 12v from the battery and ground ref by my gear select wire.

In image IMG_4097
IMG_4099.JPG
You can see me selecting first from neutral and then back to neutral.

When selecting 2nd and 3rd the signal doesn't change. I'm not sure if I'm selecting the gears in the parked state, so probable need to drive the car whilst monitoring which I'm gonna do later today.

I am now worried that you can only see neutral or a gear from the signal giving me no way to tell what gear I'm in.

The time base on the scopes are very high and I do have a lot of noise on the signals which I'll look into later.

Jason.
 

Les Jones

Well-Known Member
Most Helpful Member
Hi Jason,
The waveform does not look like a PWM signal. Both edges should be a fairly fast transition. Your waveform looks like it is being loaded with a capacitor. the fact that the loading effect is only seen the falling edge looks like it is driven with active pull up but only a resistor to ground. It would be interesting to see af adding a resistor to ground improves the falling edge. I would suggest starting with a 10 K resistor. When you say "You can see me selecting first from neutral and then back to neutral." I do not know which two traces we are comparing.

Les.
 

Huttojb1

Member
Hi Jason,
The waveform does not look like a PWM signal. Both edges should be a fairly fast transition. Your waveform looks like it is being loaded with a capacitor. the fact that the loading effect is only seen the falling edge looks like it is driven with active pull up but only a resistor to ground. It would be interesting to see af adding a resistor to ground improves the falling edge. I would suggest starting with a 10 K resistor. When you say "You can see me selecting first from neutral and then back to neutral." I do not know which two traces we are comparing.

Les.
Thanks les. I agree, in IMG_4097 at around 7 seconds into the trace when the signal starts to fall this is where I'm changing gear to 1st.

At 16 seconds on the same image I'm changing back to neutral.

I think I presumed it was a PWM with the data I had, but it looks like I'm wrong.

I'm hoping that it decrease with the other gears.

Jason.
 

Les Jones

Well-Known Member
Most Helpful Member
Hi Jason,
I had miss read the timebase scale as 2 mS instead of 2 seconds so I assumed that we were looking at the same waveform but with a different timbase scale. (2 mS per div and 20 mS per div.) Are we looking at the raw PWM waveform or the output of the low pass filter ?

Les.
 

Huttojb1

Member
Hi Jason,
I had miss read the timebase scale as 2 mS instead of 2 seconds so I assumed that we were looking at the same waveform but with a different timbase scale. (2 mS per div and 20 mS per div.) Are we looking at the raw PWM waveform or the output of the low pass filter ?

Les.
Hey Les, thanks for your support but it looks like I got it incorrect, I presumed it was a PWM signal but as you can see it's not. When I measured it with my PICO scope and saw the switching (scope trace IMG4097) I took this as PWM but PICO not capturing it correctly.

When measured properly and used a better scope which I can trust I have seen it's not a PWM signal. But infact a earth reference signal (Not sure of correct name). So my + signal is direct to a 12v battery and my - reference is my gear selection wire).

It started to rain here so was unable to get the car out today but gonna try and get it out tomorrow and see response to all gears.

Jason.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top