Would anyone know how (or if it is possible) I could use a Mega 2560 to take an AC 0-2 peak voltage with 4kHz. To a DC 0-5 volts? So that when the AC is 0, the DC will be 0 and when AC is 1, the DC will be 2.5 etc.
Can you have a go at explaining that again it seems to make no sense to me.
It would also help if you could explain what you are actually trying to do, rather than how you think you should do it.
Thanks for your time. I will try to explain it again.
I need to use an AC sin wave to control a DC output. I am given an AC voltage that will be between 0 and 2 volts and I have to have it output a 0 to 5 DC voltage that is depended on the AC input.
If your AC goes from 0-2V that means you have already applied an offset.
That's great, now all you need is an OpAmp to amplify it. Just about any rail to rail OpAmp will do, my choice would be an MCP6002 (as I have a bunch of those in my parts box). Cheaper, simpler, and with better results than you could dream of getting out of an Arduino.
I am given an AC voltage that will be between 0 and 2 volts
Do you mean the amplitude of the AC voltage ranges from 0 to 2V, with an average DC value of zero volts? If so, you cannot connect that to an Arduino input, as the inputs do not tolerate negative voltages.
What is the frequency of the AC signal?
output a 0 to 5 DC voltage that is depended on the AC input.
What is the dependent relationship?
Please explain what you are really trying to do. What you have said so far does not make sense.
Oh, I interpreted it as peak/peak value. OP mentioned 4 kHz, that should be the frequency.
OP could have 0-2V RMS as well, giving almost 3V peak, and almost 6V peak/peak.
Mmm... To measure such an AC voltage... thinking of a voltage divider + offset to bring the whole thing to the positive 0-5V level for starters. But then, 4 kHz is too high to reliably measure peaks with analogRead(). Or some kind of peak detection circuit, that doesn't use diodes for the diode drop is messing with the 0-2V signal.
OP: please be more clear in what the input signal is, and how you want to measure it. Frequency? Voltage?
Also what the output should be. A 0-5V analog voltage? PWM signal? Some kind of digital signal?
Dcounsellor:
I need to use an AC sin wave to control a DC output. I am given an AC voltage that will be between 0 and 2 volts and I have to have it output a 0 to 5 DC voltage that is depended on the AC input.
Sadly that does not explain what you want to do, and as the other posts illustrate there are a number of interpretations of your very ambiguous words.
Grumpy_Mike:
It would also help if you could explain what you are actually trying to do, rather than how you think you should do it.
We ask this because it might help to solve your poor choice of words.
I am given an AC voltage that will be between 0 and 2 volts
So is that RMS, Peak to peak or peak?
Is it that a description of the Sin wave or is it that your RMS, Peak to peak or peak amplitude of the wave can change from reading to reading.
In short WTF are you trying to make?
This is the exact assignment
"Objective
Convert a 4-kHz sinusoidal input signal, with variable amplitude from 0 – 2 Vp and no DC offset, to
a DC output. Assume one terminal of the signal source is connected to ground. The output voltage
should vary from 0 – 5 Vdc in direct proportion to the input peak voltage as it varies from 0.2 – 2
Vp. Assume a 12-V system with no negative supplies.
For a 0.2-Vp sine input, the circuit output should be < 0.3 V with < 100 mVpp ripple.
For a 2-Vp sine input, the circuit output should be 5 ± 0.2 V with < 200 mVpp ripple."
It doesn't have to be done with a Arduino, it was an idea of mine to see if it could be done.
NOTE: This is for a car so the only other power I have is 12v
That's likely easiest to do in hardware. Envelope detection to find the peak value of the AC signal, OpAmp to convert that to the required DC output value. Your biggest challenge is the 0.2V peak, so you need some kind of envelope detection that does not rely on a diode.
If you want to use an Arduino, the problem may be the high frequency. With lower frequency you'd apply an offset to the DC signal, connect it to an analog input, sample for some time to get the peak value, produce PWM output signal with duty cycle based on this, low pass filter to clean it up, optional OpAmp buffer if you need a low impedance output (no output impedance specified).
One note:
Dcounsellor:
Convert a 4-kHz sinusoidal input signal, with variable amplitude from 0 – 2 Vp and no DC offset, to
a DC output. Assume one terminal of the signal source is connected to ground.
This appears contradictory to me. If you have one terminal of the AC signal connected to GND you effectively apply a DC offset of Vp to the signal (i.e. a 0.2V Vp signal would go from 0-0.4V, not -0.2 to +0.2V as a 0.2V Vp AC signal should do). If this really is the case the whole thing may actually become easier as you can low pass filter the input signal (getting 0.4-4V as output), and turn that into a 0.2-5V output signal.
I would use an op amp, configured as a precision rectifier with gain of 2.5 (peak value).
Yeah, I'd make an envelope follower (a precision rectifier with an added capacitor). You can either build gain into the circuit, or add a 2nd amplification stage.
Assume a 12-V system with no negative supplies.
If I was building it, I'd prefer a bipolar power supply...
With no negative supply, you'll need a "rail-to-rail" op-amp (and it still may not go down to exactly zero-volts).
It doesn't have to be done with a Arduino, it was an idea of mine to see if it could be done.
The standard Arduino doesn't have a DAC and it can be damaged by negative inputs. But, it is possible to bias the input (very common for audio-related applications) and you can filter the PWM output.
This is the exact assignment
If this is a school assignment it should relate to whatever you are studying. i.e. If you are studying op-amps, a microcontroller wouldn't be an acceptable solution and vice-versa...
It is an "analog requirement" and in the real world it would be silly (and more expensive) to use a microcontroller.