Comments inline. -- Rick Altherr
"He said he hadn't had a byte in three days. I had a short, so I split it with him."
On Nov 20, 2007, at 6:28 AM, "John" <[EMAIL PROTECTED]> wrote:
Many thanks for all the replies. My project is rolling along again for the moment. I went to a night class in C programming a few years ago but seam to have forgotten a few things. I am reading out values to a computer screen via serial link in the manner of largedemo by replacing "new" with whatever I want to read out. Even with error declared as unsigned uint16_t I had the same positive and negative readout as with error declared as int_16t. I will have to think why.
If you are using printf(), the format string includes a description of the type. I would bet that you are using %d which means signed integer of size int. %u means unsigned integer of size int. I would need to check what int16_t is on avr, but if it is not int (could be short for example) then you would also need a length modifier. I suggest reading the printf() manpage.
As for the volatile declaration I just used the idea from largedemo. Some of the variables there are declared as volatile. Looking up the meaning of volatile in C programming I am given :- "not stored in machine register" but where it is stored and what it means in terms of avr programming I really dont know.
It means exactly what it says. The value should not be cached in registers when it is used for multiple instructions. Normally a C compiler will optimize a sequence of instructions to leave a particular variable on a register since accessing a register is faster than other types of access. Volatile is a hint to the compiler that the variable is actually contained in a device that may change value independently of your thread of execution, so the compiler should access the variables permanent storage location everytime the value is referenced to avoid operating on stale values.
At the moment I am using two potentiometers to simulate real word inputs. I am buffering the internal 2.56V reference to supply the potentiometers and using same internal reference for adc. It is atmega8 with 10 bit converssion so my potentiometers read out 0-1023 and I dont have the overflow type of problem just at the moment.
If you are using the ADC, you won't run into the overflow problem. Just something to be aware of.
I am working towards a controller like PID descibed on Atmels site alternatively a fuzzy one. John _______________________________________________ AVR-chat mailing list AVR-chat@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-chat
_______________________________________________ AVR-chat mailing list AVR-chat@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-chat