Hi
I am trying to measure the amplitude of a PWM signal using Ardunio. I know the duty cycle and the frequency of the signal. Can you please help me to figure this out?
Hi
I am trying to measure the amplitude of a PWM signal using Ardunio. I know the duty cycle and the frequency of the signal. Can you please help me to figure this out?
Hello
The PWM signal is a digital signal and has the amplitude of the used logic level.
Have a nice day and enjoy coding in C++.
Thanks a lot for the reply. But the signal I have is generated by a sensor and is an input to adrinuo. My main purpose is that to measure the amplitude using input pins instead of using a hardware RC filter
Basically that means nothing…
If you really want to move forward, I’d use an analog input and take continuous samples - averaging over time to figure out what voltage is being presented.
You could filter off the max and min values to get what ‘might’ be more useful readings.
The sensor's datasheet should give you its amplitude. It is usually 5v or 3.3v. It sounds like you will have to max out that sensor to get a steady stream of %100 duty cycle while connected to an analog pin (they measure 1024 at 5v, 0 at 0v). Unless the sensor is causing hardware issues, why are you attempting to read the amplitude and not the PWM? PWM is what typically conveys your data.
Hello
The sketch can count the zero to one transitions per time division to derive the "amplitude".
Thanks a lot. I have a variable resistive load that its resistance changes by current. I want to characterize this behavior basically by measuring its resistance. I am using a class D amplifier that switches between 0-5volts and I want to measure the voltage across the currents sensing resistor. So there is not data sheet per say
so in my sketch I want to measure the current going through the circuit for duty cycles of 10, 20,30, and 50%. As the voltage goes up, the total resistance changes.
Check out this tutorial. Scroll down a little past half way. It shows you to to measure current. You would have to combine this reading pulse durations to a digital line or use a pencil and paper if you can manually change the duty cycle and read the current from the serial monitor. The Arduino isn't natively set up to measure current.
Can you post the frequency? And tell us which Arduino you are using and the speed if like the Pro mini more than one speed is offered.
so in my sketch I want to measure the current going through the circuit for duty cycles of 10, 20,30, and 50%. As the voltage goes up, the total resistance changes.
Should we assume you can exercise the sensor to output these different dutycycles?
How close do you need the measurement to be?
it's 10KHz. I can change to 1KHz too on Ardunio Due. I want to be to around 1% of the current.
Hi John,
I am using Due. I am generating the PWM using Ardunio + class D amplifier (changed the PWM frequency from 1K to 10K in the Ardunio and confirmed it with oscilloscope). The process I am using is as below:
1- Start with duty cycle of 10% (for 12 bit resolution around 40 out of 4095)
2- Measure the voltage drop across the R_current_sense
3- increase the duty cycle t0 20%
4- Measure the voltage drop across the R_current_sense
.....
In which case the last thing you want to do is to apply a PWM signal to it.
What is it’s non linear thing?
What is the speed of response of this thing?
What current does this thing take?
If it responds rapidly then the binary logic signal will cause the resistance to track the value. You will still need to average a reading somewhere either in software or hardware.
The best way to do this is to provide a variable DC level from a D/A converter, then amplify it with a linear amplifier to get the voltage and current you need. Then measure across the current sensing resistor.
Note that the Due doesn’t have a rail to rail output on its D/A, so you will need your amplifier to also apply the appropriate DC level shift to compensate.
Curious why you cannot use the oscilloscope you used to verify the signal previously.
Then: (not really code but quasi code).
loop{
if(PWM ==1) {
Read A/D
Print raw value to serial monitor.
delay some number of seconds to keep serial output from going too fast.
}
}
The duty cycle IS the 'amplitude'.
The PWM signal is a digital signal that will be either 0 volts, or the maximum output voltage (presumable 5 volts). These should be the only voltages present on a PWM signal. The average voltage will vary, depending on the duty cycle of the PWM signal, 0 volts at 0% duty cycle, 5 volts at 100%, 2.5 volts at 50%, etc.
In the case of your circuit with the resistor, the current through the resistor would either be 0, when the PWM signal is at 0 volts, or (5 volts / total resistance) when the PWM signal is at 5 volts. There is no way to measure the current of a non-linear resistance at some intermediate voltage using a PWM signal, without filtering it and producing an analog voltage as an intermediate step.
I guess you need to better define what you are looking for. We don't know what you have but a typical Class D audio amplifier does not pass any PWM to the outputs. By the time the signal reaches the output the PWM has been filtered out, left is the average of the PWM signal.
It would also help us if you could describe the embodiment of your variable resistor that is a function of current. Is it also variable with temperature? If you are talking about some switching device then it is not purely resistive.
Thanks a lot @JohnRob and @david_2018 @Grumpy_Mike and @fedusenko and @paulpaulson for the input . Here is a better picture of what i want to do. I am using a Motor shield V3 which is a Full bridge amplifier. The current sense pin outputs a PWM which makes sense given my pure resistive load. when I connect current sense to the oscilloscope it shows a PWM that has amplitude different from the 9 Volt input of the shield which makes sense. I want to measure the amplitude of this PWM to find the resistance of my load.
Do you mean an official Arduino Motor Shield Rev3?
Are you using the built-in 0.15 Ohm ("0R15") current sense resistors?
Why does the diagram say "V= 5"?
Measuring the voltage across the current sense resistor will allow you to measure the current through the resistor which is the same as the current through the load. BY ITSELF THAT WILL NOT ALLOW YOU TO MEASURE THE RESISTANCE OF THE LOAD.
yes I am using the built in official Ardunio Motor shield Rev3. The 5 volts is typo, it should be the 9 volt DC adaptor I am using.
Yes, the idea here is to measure the current through the R_sense resistor which is equivalent to the current through my variable resistance. Then by dividing the input voltage of PWM (9 volts of DC adaptor) over this current, I can find the resistance of my load. Is it a right approach?