You can use fixed point math. For example, treat a 32 bit number as 24.8 bits. You can work through the math to get the rules: add and subtract numbers. Right shift 8 when you want the results. Fixed point routines can be faster than floating point, but the real gain is in potential accuracy and resolution. For lots of pointers/examples Google "fixed point binary math". OTOH, if getting quick low NRE results is the goal, switch to GCC and use it's very impressive floating point library. The cycle count for doing floating point operations is roughly equivalent to 32 bit math mult/div operations. Naturally, transcendental functions take longer... It doesn't even cost much in code space ~1kb. One still needs to keep in mind the limitations of FP to make sure you don't build in errors into your calculations. For the AVR I estimate ~1.6 kflops/mhz for general purpose stuff (add/mul). -----Original Message----- From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf Of kernels_nz Sent: Wednesday, October 10, 2007 4:51 AM To: AVR-Chat@yahoogroups.com Subject: [AVR-Chat] Re: Weigh - Scale Firmware Hi Rob, Wow, I see to be generating a bit of interest with what I viewed as a pretty simple problem. Firstly, in practice, every trade-approved weigh-scale that ive seen so far has used at least a 24-bit A2D converter. The load-cells are completely passive, they are merely a wheatstone bridge made up of four strain guages. Thus, to get 10 000 divisions from a 3mv/v load-cell with 5v excitation (15mv full scale) output, you need 15mv / 10000 = 1.5uv resolution in your measurement system. In reality im only looking for 3000 divisions (for trade approved weighing), but as you stated, I need some head-room. I would imagine that weighing systems get around the thermocouple junction effects by running a low impedance system, load-cells are only 300 OHM impedance. Im not sure what the reason is, but I worked in the weighing industry for a couple of years and never had any problem with "junctions". The 15mv can be measured at the input to the ADC chip, most good digital weight indicators dont use any amplification of the signal anywhere, I guess the more amplification you have along the way the more likely you are to introduce noise. Yes, the number of noise free bits required would be way less if my full-scale output voltage was closer to the reference voltage, but in all of the scale circuits ive studied, the excitation voltage for the load-cell is fed straight into the reference of the ADC, this then compensates the ADC for any changes in excitation voltage. This also means a reference voltage of 5V with a full scale signal of around 15-20mv! The Class 3 test weights used for weights and measures tests are accurate to 10mg in 1kg, thats way more than 0.25%, I think a weights-and-measures inspector would laugh at me if I suggested he used 0.25% test weights to check our equipment. Im not even sure 0.25% weights could be sold, thats 2.5g in 1kg, ridiculous. But alas, designing the analogue part of this system will merely be a copy and paste operation from earlier model weigh-scales - no problem. The bit thats got me thinking is what the best way is to do the software calibration on a 8-bit micro controller. The one currently used is 32 bit with a proper floating point module, and deals with the math no-problem. I was really fishing for some integer-math-only way of doing the calibration code and luckily one guy on the Atmel ARM forum has given me some good pointers, so it looks like it should be possible. The other option of course is biting the bullet and just doing the floating point math! Cheers Hein B Auckland, New Zealand --- In AVR-Chat@yahoogroups.com, "Roy E. Burrage" <RBurrage@...> wrote: > > We do a little bit with measurement here, Hein. > > www.measuretech-tn.com > > My experience has been that a scale, most mechanical measuring devices > for that matter, aren't very accurate below 10% to 20% of their full > scale range. A set of ANSI Class 1 calibration weights is only accurate > to something on the order of 0.25%, so how many bits does that equate > to? Transfer accuracy is, at best, 2:1 with 4:1 recommended...and 10:1 > optimum. So where does that leave your bit resolution to accuracy > ratio? 10 bit accuracy is better than this 0.25% and averaging can > easily give you 12 to 14 bits of resolution if your A/D converter is > linear enough. > > You may be trying to resolve a couple of microvolts, but that certainly > is only going to be right at the load cell. Most load cell outputs are > something on the order of 10mv to 20mV. I suspect your 5 volt signal is > after amplification local to the load cell to prevent thermal emfs from > swamping out load cell output changes. Look at the mV/degree change of > a type T (copper/constantan, constantan being a copper alloy) > thermocouple some time. How many thermocouple junctions would you have > from a load cell, a 20 foot run of cable, then some electronics? Don't > miscount your junctions or get dissimilar metals in there. > > Make sure you aren't confusing resolution and stability with accuracy. > There is a big difference in the 2. > > > REB > > > > > kernels_nz wrote: > > >Hi Roy, generally you don't need a particularly accurate reference, > >just one that doesn't vary with time and environmental factors. All > >measurement is done relative to a "calibrated test weight", so scales > >are calibrated and do not rely on the accuracy of the reference. > > > >In practice the weigh scale manufacturers are trying to look at 1.5uV > >changes in strain-bridge output with a 5V reference, so unfortunately > >you do require around 3 million counts or 22 bits. > > > >At low sample rates (10 s/s) and good analogue design 22 bits is not > >too hard to achieve, it's all about using the right parts for the job. > > > >All that stuff is comparatively easy, the bit thats got me a bit > >worried is migrating the code from the existing 32-bit processor to a > >baby AVR. I was hoping someone had done something similar and could > >give me some advice on how to do the calibration routines without > >using floating point math! > > > >Cheers > >Hein B > >Auckland, New Zealand. > > > >--- In AVR-Chat@yahoogroups.com, "Roy E. Burrage" <RBurrage@> wrote: > > > > > >>Is it 24 bit accuracy or 24 bit resolution? At 24 bits, 1 part in > >>almost 17 million...where do we get a reference that accurate with a > >>reasonable cost suitable for a weigh scale product? > >> > >>I suspect 12 bit accuracy would be plenty accurate for your application > >>and you wouldn't have the thermal emf problems as with 24 bits. Just > >>throw the lower bits away after you average them into your equations. > >> > >>On a regular basis here, we take data points and store them in a moving > >>average filter. There's a very good application note both from Atmel > >>and at AVRFreaks which describes the process. If it were me I'd use > >> > >> > >the > > > > > >>upper 16 bits of your A/D converter, store those in 2 8 bit registers, > >>add that to the 2 registers you have already set up for your averaging > >>filter, add the overflow bit to another register set up for that > >>purpose, and then after your predetermined number of sample points take > >>an average. It's as simple as that. > >> > >>You'll also have to adjust the limits of your filter to allow for wind > >>gusts or other vibration sources so they don't drive your gizmo wild. > >> > >> > >>REB > >> > >>kernels_nz wrote: > >> > >> > >> > >>>Hi there, this one is out of left field a bit (Baseball phrase ???) > >>>but im working on a weigh-scale project that uses a 24-bit ADC and I > >>>was just wondering whether anyone had ever written a weigh-scale > >>>module for a 8-bit micro controller. > >>> > >>>Im just interested to see how all the calibration etc. for finding the > >>>actual displayed weight from having 32 bit numbers representing the > >>>Calibration Zero and Span values and the current ADC value. Is there a > >>>way to do all the calculations without using floating point math? > >>> > >>>Cheers for any information! > >>>Hein B - Auckland, New Zealand > >>> > > > [Non-text portions of this message have been removed] > Yahoo! Groups Links
Message
RE: [AVR-Chat] Re: Weigh - Scale Firmware
2007-10-10 by larry barello
Attachments
- No local attachments were found for this message.