Tracking/Replicating a 16 bit PWM wave

Hello all,
I've got very little experience with the arduino, and I've got a project where I want to read in an incoming 16 bit PWM wave, track it, and then replicate it on an output pin. I think the answer lies in the input capture and output compare registers, but I'm not sure. They do have the bit resolution that I need. I also wrote a function that outputs a 16 bit PWM value on pins 9 and 10 (as apposed to the default 8 bits). What I'm not sure on, is if there is a way to effectively track the wave and duplicate it on an output pin. A hardware solution would be to just use an XOR gate and have one the inputs be low and the other be the PWM wave. I'm curious though if I can also implement this in software.

I don't see the need for the XOR gate, or any other hardware, if you don't want to modify the given PWM signal.

For tracking the signal an external interrupt can be used, that replicates the signal changes on some output pin.

I think you shuld to explain what you're trying to accomplish.... If you've got a PWM pulse train why do you need to "replicate" it?

What I'm not sure on, is if there is a way to effectively track the wave and duplicate it on an output pin.

Apparently, you've already got it on an output pin. And your software obviously "knows" the PWM value already.

A hardware solution would be to just use an XOR gate and have one the inputs be low and the other be the PWM wave.

If you want a hardware buffer, yes use a buffer (or a gate as a buffer). You don't need a micorocontroller & software for that...

I think you shuld to explain what you're trying to accomplish.... If you've got a PWM pulse train why do you need to "replicate" it?

Essentially, I'm trying to figure out if I can read in a PWM waveform, and then output the same waveform on an output pin of the Uno. I know you're probably thinking, why not just input the PWM wave directly to the device to be driven? Well in my case, the PWM waveform will be continuously running, and I want to be able to control when the Uno is actually tracking and outputting the waveform (via a push button or enable line). The PWM waveform will be 16 bits which I believe means the counter will count from 0-65535. After looking through the different Timer1 registers, I think the input capture and/or output compare registers might be key, but I'm not entirely sure.

Why not just use a logic AND gate control when the PWM is signal is allowed to pass? Much simpler.
Output a 1, the signal is allowed to pass. Output a 0, the signal is not.

rhumphrey:
Essentially, I'm trying to figure out if I can read in a PWM waveform,

What is producing the PWM waveform?

Can you post a picture/diagram showing what the waveform looks like?

...R

Robin2:
What is producing the PWM waveform?

LABVIEW is running a PID control loop that outputs a 16 bit PWM wave/value that'll be used to drive a heater to keep the temperature of the device being used at specified set point temperature. I had no part in that aspect of the project. The part I'm working on is attempting to read in and track the PWM value, and then also having some sort of switch that overrides the incoming waveform and causes the Arduino to output a 0, effectively turning the heater off (regardless of what the LABVIEW program is doing.

CrossRoads:
Why not just use a logic AND gate control when the PWM is signal is allowed to pass? Much simpler.
Output a 1, the signal is allowed to pass. Output a 0, the signal is not.

Isn't that same concept as the XOR gate implementation? The only difference being, the second input needs to be a 1 and not a 0 for the AND gate? I'm pretty sure either gate can be used to accomplish the same task just so long as the second input gets set appropriately. Or maybe I'm missing something.

If you want to learn more about programming timers, split your project into

  • computing the duty cycle (and frequency?) of a PWM input, and
  • make a timer (T1 for 16 bit) output a PWM signal of variable duty cycle.
    The latter eventually can be implemented using analogWrite, if the signals need not be in phase.

I would prefer not to use the Arduino to regenerate the PWM signal - I like the idea of using an external logic chip to block or enable it to pass through, because then you'd need to have a very accurate measurement of the duty cycle to get the exact value, and you could easily lose some accuracy at that step. There are a lot of possible options for this, make sure you get one that responds fast enough to not mangle the pwm signal.

Part of the problem is that the Arduino's based on the '328p only have one 16-bit timer - do you use it for input capture? Then how do you output the signal? The other timers can only do 8-bit pwm. Or you have it generating the output PWM signal, but then you don't have a way to do the input capture. The Mega2560 has more 16-bit timers (the attiny841 also has two 16-bit timers, and I think the atmega1284p does too - 1284p-based boards are readily available, and I sell attiny841 boards) - so those might be better suited if you had to re-generate the PWM signal. But I'd try to avoid having to do that.

DrDiettrich:
If you want to learn more about programming timers, split your project into

  • computing the duty cycle (and frequency?) of a PWM input, and

I understand how to use the input capture register to retrieve the frequency of the PWM wave. However, I'm not sure how I would use the input capture to retrieve the duty cycle of the waveform. I would need two time stamps - one for the rising edge and one for the falling edge. Referencing the datasheet though, it appears that the input capture can only be configured to take time stamps at just the rising edge or just the falling edge. That does allow me to measure the period/frequency of the waveform, but isn't helpful for duty cycle calculations, which is kind of a big issue, being that it is a PWM wave.

The part I'm working on is attempting to read in and track the PWM value,

Why not have the Arduino and the PC running Labview connected with USB have Labview tell the Arduino what duty cycle it is outputting. Why measure what is known.

a 16 bit PWM wave/value that'll be used to drive a heater to keep the temperature of the device being used at specified set point temperature. I had no part in that aspect of the project.

That's good, because I fail to see why 16 bits of output level control is useful for a heater application, or any PID control situation for that matter. Can Labview calculate and output 8,10, or 12 bit pwm control?

cattledog:
That's good, because I fail to see why 16 bits of output level control is useful for a heater application, or any PID control situation for that matter. Can Labview calculate and output 8,10, or 12 bit pwm control?

Look, I just got filled in on the project today, and I'm still getting my bearings. I was just asked to come up with a design that would track the PWM wave generated by LABVIEW as well as output a 0 upon the activation of a switch of some sort. To you, this may all seem trivial, but not to a beginner.

"16. 16-bit Timer/Counter1 and Timer/Counter3(1) with PWM
Note: 1. Timer/Counter3 is only available in ATmega1284/1284P"

Yes, two 16 bit timers on Atmega1284P.
Need a board? I offer them in a few form factors:
http://www.crossroadsfencing.com/BobuinoRev17/
This one is Uno-like (well, Duemilanove-like, with FTDI interface)

"Isn't that same concept as the XOR gate implementation? The only difference being, the second input needs to be a 1 and not a 0 for the AND gate?"

Look at their truth tables:
AND
C P O C = control, P = PWM, O = output
0 0 0 output forced low
0 1 0 output forced low
1 0 0 output allowed to follow P input
1 1 1 output allowed to follow P input

XOR
C P O
0 0 0 output allowed to follow P input
0 1 1 output allowed to follow P input
1 0 1 output is inverse of P input
1 1 0 output is inverse of P input

So XOR is not really what is wanted to gate a signal off & on.

rhumphrey:
Well in my case, the PWM waveform will be continuously running, and I want to be able to control when the Uno is actually tracking and outputting the waveform (via a push button or enable line). The PWM waveform will be 16 bits which I believe means the counter will count from 0-65535.

What is the PWM frequency?

Potential problem:
PWM Hz = 18.464 kHz
Duty resolution = 16-bit
Required timer clock frequency = 65535 x 18464 = 1.21GHz

Great Scott!

cattledog:
Why not have the Arduino and the PC running Labview connected with USB have Labview tell the Arduino what duty cycle it is outputting. Why measure what is known.

That seems to me to be by far the most sensible solution.

...R