code:ground_control
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
code:ground_control [2008/10/31 00:14] – laurenceb | code:ground_control [2008/11/13 09:50] (current) – laurenceb | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Input capture based version ===== | ===== Input capture based version ===== | ||
This uses the input capture function on timer1 (atmega168). The ICNC1 bit in the TCCR1B register need to be set to enable oversampling to give more noise tolerance. A second function running approx every 20ms is needed to decrement counter by two and check if counter> | This uses the input capture function on timer1 (atmega168). The ICNC1 bit in the TCCR1B register need to be set to enable oversampling to give more noise tolerance. A second function running approx every 20ms is needed to decrement counter by two and check if counter> | ||
- | |||
- | |||
==== Header ==== | ==== Header ==== | ||
<code c> | <code c> | ||
- | # | + | void enable_ground_control(); //enables the input capture interrupt |
- | # | + | void disable_ground_control(); //disables input capture interrupt |
- | + | #define PULSE_MIN | |
- | #define PULSE_MIN 0.001*F_CPU/ | + | #define PULSE_MAX |
- | #define PULSE_MAX 0.002*F_CPU/ | + | #define GROUND_LED_ON PORTD|=(1<< |
+ | #define GROUND_LED_OFF PORTD& | ||
+ | #define GROUND_LED_SET PORTD& | ||
+ | void run_ground_control(); | ||
</ | </ | ||
+ | |||
====Main code=== | ====Main code=== | ||
Line 19: | Line 21: | ||
#include " | #include " | ||
extern volatile u08 counter; | extern volatile u08 counter; | ||
- | extern volatile | + | extern volatile |
Line 25: | Line 27: | ||
{ | { | ||
static u16 start; | static u16 start; | ||
- | if(TCCR1B|0x40) // | + | if(TCCR1B&0x40) // |
{ | { | ||
TCCR1B& | TCCR1B& | ||
Line 33: | Line 35: | ||
{ | { | ||
TCCR1B|=0x40; | TCCR1B|=0x40; | ||
- | if(!counter& | + | if(!(counter& |
{ | { | ||
- | diff=ICR1-start; //set the global volatile | + | diff=ICR1; |
- | if(start> | + | if(start> |
{ | { | ||
diff+=TOP_COUNT; | diff+=TOP_COUNT; | ||
} | } | ||
+ | diff-=start; | ||
if(diff> | if(diff> | ||
{ | { | ||
Line 53: | Line 56: | ||
} | } | ||
} | } | ||
+ | } | ||
+ | |||
+ | void run_ground_control() | ||
+ | { | ||
+ | if((~0x80& | ||
+ | { | ||
+ | counter|=0x80; | ||
+ | OCR1B=diff; | ||
+ | counter& | ||
+ | GROUND_LED_ON; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | GROUND_LED_OFF; | ||
+ | } | ||
+ | if(counter& | ||
+ | counter-=2; | ||
+ | } | ||
+ | |||
+ | void enable_ground_control() | ||
+ | { | ||
+ | TIMSK1|=(1<< | ||
+ | counter=0; | ||
+ | } | ||
+ | |||
+ | void disable_ground_control() | ||
+ | { | ||
+ | TIMSK1& | ||
+ | GROUND_LED_OFF; | ||
+ | counter=0; | ||
+ | diff=0; | ||
} | } | ||
#endif | #endif |
code/ground_control.1225412096.txt.gz · Last modified: 2008/10/31 00:14 by laurenceb