Variable value "Snap Shot"

Hello - I have an Arduino UNO and no code yet. I'm still in the white board state.

I'm looking for a coding solution to a project. I need to capture a "snap shot sample" of a variable (digital RPM input) into a new variable to be the "Target RPM" for a Governor output.

Is there a coding solution in the IDE that facilities this because I can't find it.

Cheers

You mean something like this?

TargetRPM = digitalRPMinput;

Since this moment the TargetRPM will keep the value independently of the digitalRPMinput.

Thanks for the reply!

I chose my words poorly in the post.

I have a int variable "RPM" that is the product of another function and is changing constantly (as expected). The "Governor" function needs a fixed number to base throttle adjustments against.

Regards

The value will be changing but you can take a copy at any time or an average over a period or number of samples. What sort of frequency is involved ?

The tach input freq would be around 1000-3000 Hz.

The Uno can easily cope with copying a variable at such a frequency

If you want someone to write code for you, post in the Gigs and Collaborations forum section. You may be asked to pay for the help.

Is there a coding solution in the IDE that facilities this because I can't find it.

PID?

dlloyd:
PID?

PID still needs a static target value to work with. I can't be the first to need this.
Someone smarter than me will use something involving Millis to pluck off a number from a data stream I suspect.

We’re a long way into a Programming topic, yet we seem to be short on program.

Just a dispassionate observation.

I need to capture a "snap shot sample" of a variable (digital RPM input)

To get a snapshot of RPM, use an interrupt and measure the pulse duration using micros (rather than count pulses over 1 sec). Much faster, more accurate ... search for examples here on the forum.

Keep in mind, that when you get what you want, you might want to save TargetRPM into EEPROM, so it's not lost the next time you power-cycle or reset the UNO.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.