I need to delay a pwm input singal for up to a second and output that same signal.
but i have no clue how to go about doing that.
any advice/tips?
thanks in advance.
Welcome to the forum!
Start by posting a drawing of your circuit, and providing exact model numbers (and datasheet links, if possible) of all hardware components in your circuit.
If you have written any code (even code that doesn't work), please share that code, as well. Make sure to use the <CODE/> button in the toolbar of the forum's comment editor when posting code.
Thanks!
havent started on the code yet because i have no idea where to start(code isnt my strong suit)
hardware wise anything goes, its just a 5v pwm singal that needs to be delayed.
What is the frequency of the PWM signal ?
thats the one thing i sadly do not know yet (but lets say its low enough to be read and recreated by an arduino)
It is not reading and recreation that I was worried about, more how much storage might be needed
Store the values you read in a circular buffer.
Create the PWM values you write from the buffer N elements behind where you are writing.
Use a buffer sized at a power of 2 for convenience, you can use any N up to that size.
a7
Conceptually, it's pretty easy. But maybe not so easy in the real world. PWM is "messy" and not normally synchronized to anything.
Read the pulses coming-in. You might have to use interrupts and time the pulses because you can't read continuously and you probably don't know when to read.
Save them (to a "buffer"... probably an array'). If the PWM frequency is 450kHz, you can save 1 second of data in 450 bits. (I'm not sure the most efficient way to read, write, and store individual bits.)
Then after one second, read the 1st one, write it out, and overwrite it with a new value. Sequence through the buffer and when you get to the end, start-over at the beginning of the buffer which is now full of new data. (This is called a "circular buffer").
Or, an easier or less precise solution is to filter the PWM to analog and then write-out the analog values as PWM.
How many different pulse widths are you concerned about? Might be easier to determine which width you just received and give that a code and make an array of the codes. Then recreate the new PWM using the stored codes.
Why? What's the goal?
Depending on what "low enough" means and which Arduino you use, it may not even be feasible. So I see no point in wasting time on code that may not work.
I suggest you first find out the highest frequency, duty cycle range and required accuracy before you go any further.
Are you sure about that delay, given that you don't seem to know much about the signal?
There is undoubtedly a better solution to the real problem, which you haven't mentioned.
Unit error. To save 1s of data in 450 bits, your input waveform would be limited to 450Hz (no "k" !)
In reality, much less than that, because "PWM Frequency nHz", usually means m possible pulse lengths within each n period. To accurately record an Arduino's 1kHz 8bit PWM, you need to read bits at 256kHz (or more.)
If this is to delay a typical Remote Control/Servo PWM signal (pulses 0.5 to 1.5ms arriving a ~50Hz, that wouldn't be too difficult, but a better strategy might be to read each pulse and store it as an int, and ignore the in-between-time pulses.
I took a Software Project Management course some time ago. There was one point the (very experienced) instructor kept drilling into our heads, at least once every hour.
On the last day of class, he asked, "if there's one thing you've learned from me, what is it?"
Immediately, in unison, the entire class repeated, "failure to properly manage requirements is the most common cause of project failure."
So yeah, I agree with you
...and I'm pretty sure I've told that story here before