Go Down

Topic: Application: Basic; Stopwatch, More; DAQ (Read 2 times) previous topic - next topic

atmh

Yeah.

The important part is to keep output function limited, since it takes cpu cycles to update the screen, and for the most accurate measurement you want to be "listening" for the signal as much as possible.

As far as an on-board data acquisition system goes... it would be a lot trickier, we never undertook that aspect of the project, but I'm sure it could be done... to an extent.  You'd need a place to store all the data though.

Worked great as a lap timer!  Took a lot of time/energy/effort though, and first designs always have numerous bugs and issues that pop up.

Graynomad

#11
Jun 12, 2010, 02:38 am Last Edit: Jun 12, 2010, 03:02 am by graynomad Reason: 1
Quote
The important part is to keep output function limited, since it takes cpu cycles to update the screen, and for the most accurate measurement you want to be "listening" for the signal as much as possible.


Your timing capture should be interrupt driven, that way it doesn't matter how long the display and other functions take (within reason) they will have no affect on the timing. That way the listening and counting is done by the CPU hardware, you just have to accumulate the count and display the results at the end of the period.

EDIT: I just noticed this is a 2-year-old thread, are you still working on the project?
Rob Gray aka the GRAYnomad www.robgray.com

atmh

heh, no.  I was just answering the previous question.

I am aware of interrupt driven detection.  There was some reason that wouldn't work for us, I don't remember the details though :-/

It could have been that we are crappy programmers, haha :)

Newtonn2

Thank for the quick answer.  Any change you could post or send me the code you used?  I'm just starting with arduino. I know a bit of programming but never did program in C. I would like to use the magnet sensor to activate the stopwatch and show the laps.

Thank you in advance.  

Graynomad

newtonn2

Not sure if you were talking to me or atmh, but here's some code from a speedo I did a while back.

Code: [Select]
#include <avr/io.h>      
#include <avr/interrupt.h>

uint16_t timer_value = 0;
uint8_t new_pulse = 0;

ISR(TIMER1_OVF_vect) {
     // handle timer overflow here if neccessary
}

ISR(TIMER1_CAPT_vect) {
     timer_value = TCNT1;      // get counter value for main loop
     TCNT1 = 0;             // reset counter
     new_pulse = 1;            // set flag for main loop
}

int main(void) {

     TCCR1B = (1<<CS10)|(1<<CS12)|       // Timer clock = system clock / 1024
           (1<<ICES1)|            // rising edge detect
           (1<<ICNC1);            // noise canceller
     TIFR = 1<<ICF1;             // Clear any ICF1 pending interrupts
     TIMSK = (1<<TICIE1)|            // Enable Timer1 Capture
           (1<<TOIE1);             // and overflow interrupts      
     
     sei();
     while(1) {

           if (new_pulse == 1) {
                 new_pulse = 0;
                 // timer_value = the count from the timer ie. time between pulses
                 do_something_with_value(timer_value);
           }
     }
}


NOTES:
  • Not tested, relevant parts hacked from a much larger program.
  • Also the timer constants (TCCR1V etc) may be different for the processor you are using.
  • This is AVR GCC code, I'm not sure how that maps to an Arduino but I think it should work.
Rob Gray aka the GRAYnomad www.robgray.com

Go Up