[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Best practice for external variable (newbie-ish quest

From: David Kelly
Subject: Re: [avr-gcc-list] Best practice for external variable (newbie-ish question)
Date: Sun, 20 Nov 2005 20:01:38 -0600

On Nov 20, 2005, at 7:29 PM, Matthew Smith wrote:

Thanks for that; I do have everything in one file and I'm getting some
very, very odd and unpredictable actions.  The system is a pump
controller that reads pressure via an ADC and uses the AVR timer to
determine a minimum run time (unless a critical pressure is reached, in
which case the timer is ignored).

I've got an LED showing me when the timer is running and another on a
solid state relay showing what the pump is supposed to be doing.
Substituting a potentiometer for the pressure transducer, I've observed
it working as planned, but sometimes the timer never expires (or won't
start) and sometimes the "virtual" pump turns on, but never off.

Behaves with potentiometer but not with real sensor? Then I suggest studying the analog input circuit from the sensor and consider adding filtering.

One might debug the A/D by spitting the read values out a serial port but this consumes enough CPU cycles that it might affect the results. If using a debugger then one might modify the code to stash the last 128 samples in a circular buffer then when one observes misbehavior use the debugger to break and study the buffer contents.

#define BUFFER_SIZE (1<<7)        // must be a power of 2, (1<<7) is 128
uint8_t buffer_index = 0;       // global is easier for debugger to find
uint16_t buffer[BUFFER_SIZE];

void buffer_it( uint16_t value )
        buffer[buffer_index++] = value;
        buffer_index &= BUFFER_SIZE-1;

David Kelly N4HHE, address@hidden
Whom computers would destroy, they must first drive mad.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]