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/30 14:38] – rharrison1971 | code:ground_control [2008/11/13 09:50] (current) – laurenceb | ||
---|---|---|---|
Line 4: | Line 4: | ||
==== Header ==== | ==== Header ==== | ||
<code c> | <code c> | ||
- | # | + | void enable_ground_control(); //enables the input capture interrupt |
- | # | + | void disable_ground_control(); |
+ | # | ||
+ | #define PULSE_MAX (s16)(0.002*(float)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=== | ||
<code c> | <code c> | ||
- | extern volatile u08 counter; //globals | + | #ifdef GROUND |
- | extern volatile | + | #include " |
- | + | extern volatile u08 counter; //globals | |
+ | extern volatile | ||
+ | |||
+ | |||
ISR(TIMER1_CAPT_vect) | ISR(TIMER1_CAPT_vect) | ||
{ | { | ||
static u16 start; | static u16 start; | ||
- | if(TCCR1B|0x40) // | + | if(TCCR1B&0x40) // |
{ | { | ||
TCCR1B& | TCCR1B& | ||
- | start=ICP1; //record start of the pulse | + | start=ICR1; //record start of the pulse |
} | } | ||
else | else | ||
{ | { | ||
TCCR1B|=0x40; | TCCR1B|=0x40; | ||
- | if(!counter& | + | if(!(counter& |
{ | { | ||
- | diff=ICP1-start; //set the global volatile | + | diff=ICR1; //set the global volatile |
- | if(start> | + | if(start> |
{ | { | ||
diff+=TOP_COUNT; | diff+=TOP_COUNT; | ||
} | } | ||
+ | diff-=start; | ||
if(diff> | if(diff> | ||
{ | { | ||
- | if(counter& | + | if((counter& |
{ | { | ||
- | counter+=3; | + | counter+=3; |
} | } | ||
} | } | ||
else | else | ||
{ | { | ||
- | counter& | + | counter& |
} | } | ||
} | } | ||
} | } | ||
} | } | ||
+ | |||
+ | 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 | ||
</ | </ | ||
code/ground_control.1225377492.txt.gz · Last modified: 2008/10/30 14:38 by rharrison1971