I have a 0-12V PWM signal as my input and I want to modify the pulse width, calculate the frequency and then output the modified 12V pulse width.
I understand how to read the PWM signal with pulsein. Is there an easy way to calculate the frequency or do I have to read pulsein(high) and pulsein(low), add them and invert to get the frequency?
Writing the modified PWM signal seems too be best with digitalwrite with a delay that is set as the pulsein(high) plus or minus the modification and a digitalwrite with a delay that is set as the pulsein(low) minus or plus the modification since the frequency changes in step with the input frequency.
Also, my input and output voltage have to be 12V. Will a 12V PWM signal fry the Arduino? I can add a transistor in the output and feed it a 12V source so that shouldn't be a problem. If I have to drop the input voltage to 5V, what is the easiest way?
Sorry for the newbie questions, it's been many years since I struggled through circuits classes in college. If any of this sounds like a retarded way to do this, please correct me. This is my first Arduino project.
to drop the input voltage to 5V, what is the easiest way?
If it were me I would use a transistor, resistor to base to 12V PWM signal. Emitter ground, collector Arduino input pin with 3K3 pull up to 5V. Others might suggest resistors with catcher diodes to the rails
Writing the modified PWM signal
Does the frequency matter? if not use the analogWrite() function with the appropriate ratio.
If it were me I would use a transistor, resistor to base to 12V PWM signal. Emitter ground, collector Arduino input pin with 3K3 pull up to 5V. Others might suggest resistors with catcher diodes to the rails
OK, I understand that. That makes sense.
Does the frequency matter? if not use the analogWrite() function with the appropriate ratio.
Yes, the frequency matters. The PWM signal is driving a high speed solenoid. The goal is to use an existing PWM signal and modify the pulse width by multiplying it by a factor that is read from a table of frequency vs. a secondary 0-5v analog input from another sensor.
The frequency isn't too high ... <70Hz. Shouldn't be too complex, right?
I'll draw up a schematic and post it just in case I get it totally wrong. :