I am writing a PID controller using the PID library.
In the end I obtain a value that is a double and I want to feed this value to a 8 bit DAC that will drive a piezo actuator.
Is there any command that gives me an easy way to write the double value in the 8 bit output pins?
I am writing a PID controller using the PID library.
In the end I obtain a value that is a double and I want to feed this value to a 8 bit DAC that will drive a piezo actuator.
Is there any command that gives me an easy way to write the double value in the 8 bit output pins?
Is there any command that gives me an easy way to write the double value in the 8 bit output pins?
You can write an 8bit value in the 8bit output pins. http://www.arduino.cc/en/Reference/PortManipulation
So you have limit your value to 8bits - for example by shifting it right, or with map() function, etc..
Sorry I am a newbie.
I would like to know if there is a command to write the double variable directly in the output.
Or a command to convert the double in 8 binaries bit that I can digitalwrite in the PD0...PD7 output.
Because at the moment I don't know how to deal with it.
I am trying to realize a self stabilized interferometer.
It is a system where the intensity of light is fluctuating, and in order to keep this intensity fixed to a desired values is possible to control it and compensate the fluctuations using a piezo actuator.
To generate the control signal I am going to use an arduino 2009 board that has in Input an analog signal coming from a detector and in output is connected to a DAC and an amplifier that drive the piezo actuator.
So the Arduino reads the intensity, generate a correction, and apply it through the DAC and actuator.
The double that I want to put in the output is the value of the correction, obtained using a PID algorithm (Proportional Integrative Derivative)PID controller - Wikipedia.
Why do you think is unlikely that the corrections goes through the full range?
Because a correction of 3.4028235E+38 seems highly unlikely. I think you really should print out the values that you are actually seeing. Perhaps just truncating the double as a byte would be sufficient. If the range of ACTUAL values is 0 to 255, truncation is sufficient. If the value is greater than 255, division is necessary before truncation.
On the other hand, the correction factor may actually need to be scaled up to fit the allowable range. But, with no idea of what the actual range is, we can't help you.
Ok,
thank you very much.
I'll check in the lab and I will let you know.
But I will try with the truncation for a first test.
Can you give me some information on how apply the truncation on 8 bit for a double?
Or just how to extract the single bits from the 32 bit word of the double?
Or just how to extract the single bits from the 32 bit word of the double?
Be careful with that "definition".
A "double" may be 64 bits, and usually is,
Also, an IEEE 754 format floating point number wouldn't normally be subject to individual bit manipulation.
Can you give me some information on how apply the truncation on 8 bit for a double?
Or just how to extract the single bits from the 32 bit word of the double?
On the Arduino, floats and doubles are exactly the same. So, get over the hangup with doubles.
Try looking at a basic C book for the rules regarding what happens when you assign a larger type to a smaller type, and what happens when you assign a float to an int.
float f = 14.2;
int i = f; // i will be 14
byte b = f; // b will also be 14
float ff = 123456789.32;
int ii = ff; // overflow; ii will be garbage
byte bb = ff; // overflow; bb will be garbage