Open Sint  3.4-2
Functions | Variables
davis.c File Reference

These routines are used to read the wind speed and direction, do media etc. More...

#include <inttypes.h>
#include <avr/interrupt.h>
#include "davis.h"
Include dependency graph for davis.c:

Functions

 ISR (TIMER1_CAPT_vect)
 
 ISR (TIMER1_OVF_vect)
 calulate wind speed with collected pulse value. Any time the system trigger an overflow interrupt. The wind pointer must be present as global variables. wind flag is a boolean flag we enable to signal to main that there is a time to be elaborated. Once the main take care of the new value, it switch off the flag, so if we find the flag on, it means that the main didn't take care of the last value (maybe it was too busy) so we simply do nothing. Wind->direction is supposed to be a media, not a single shot, this is why it will not be converted in here. More...
 
void davis_timer_setup (void)
 setup counters and timers. Time ellapsed every cycle is 4.19424 sec. 4Mhz / 256 = 15625 Hz (clock pre-scaled of 256) or 1Mhz / 64 = 15625 Hz (clock pre-scaled of 64) 1/15625 Hz = 0.000064 sec (every counter's step) Number of step per cycle is 65535 (16bit) 0.000064 sec * 65535 = 4.19424 sec every cycle. More...
 
void davis_init (void)
 initialize the davis anemometer.
 
uint8_t davis_adjust (void)
 anemometer value fine tuning and error correction. Any time the main find it has a wind speed flag active, it means we have a tick per cycle to elaborate. This routine is used to trasform ticks per cycle in (?? m/s) (?? km/h). More...
 

Variables

volatile int loop
 

Detailed Description

These routines are used to read the wind speed and direction, do media etc.

Note
the wind struct is global.

Function Documentation

◆ davis_adjust()

uint8_t davis_adjust ( void  )

anemometer value fine tuning and error correction. Any time the main find it has a wind speed flag active, it means we have a tick per cycle to elaborate. This routine is used to trasform ticks per cycle in (?? m/s) (?? km/h).

Note
clear media_rt the first time (init).
speed_rt and angle_rt are set by interrupt routine.
Todo:
This routine should also check the validity of these value someway.
Returns
TRUE - ok the value has been corrected, FALSE - error.
Bug:
return is always TRUE, please fix.

Adjust wind speed, these value are hardware dependant. See spreadsheet.

◆ davis_timer_setup()

void davis_timer_setup ( void  )

setup counters and timers. Time ellapsed every cycle is 4.19424 sec. 4Mhz / 256 = 15625 Hz (clock pre-scaled of 256) or 1Mhz / 64 = 15625 Hz (clock pre-scaled of 64) 1/15625 Hz = 0.000064 sec (every counter's step) Number of step per cycle is 65535 (16bit) 0.000064 sec * 65535 = 4.19424 sec every cycle.

Note
this example is based on 4Mhz cpu clock. Adjust the prescaler to your settings.

The counter is: prescaler/256 (4Mhz) CS12 prescaler/64 (1Mhz) CS11 and CS10 noise canceller is enable and the trigger edge is on positive.

enable interrupt on timer 0 event and overflow.

◆ ISR() [1/2]

ISR ( TIMER1_CAPT_vect  )

only to implement low pass filter

◆ ISR() [2/2]

ISR ( TIMER1_OVF_vect  )

calulate wind speed with collected pulse value. Any time the system trigger an overflow interrupt. The wind pointer must be present as global variables. wind flag is a boolean flag we enable to signal to main that there is a time to be elaborated. Once the main take care of the new value, it switch off the flag, so if we find the flag on, it means that the main didn't take care of the last value (maybe it was too busy) so we simply do nothing. Wind->direction is supposed to be a media, not a single shot, this is why it will not be converted in here.

Note
the wind struct is global.

Variable Documentation

◆ loop

volatile int loop

Global variable and pointer to be used inside the ISR routine