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/11/13 00:39] – 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(); |
+ | # | ||
+ | #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(); | ||
+ | </code> | ||
- | #define PULSE_MIN 0.001*F_CPU/ | ||
- | #define PULSE_MAX 0.002*F_CPU/ | ||
- | </ | ||
====Main code=== | ====Main code=== | ||
Line 19: | Line 21: | ||
#include " | #include " | ||
extern volatile u08 counter; | extern volatile u08 counter; | ||
- | extern volatile | + | extern volatile |
Line 35: | Line 37: | ||
if(!(counter& | if(!(counter& | ||
{ | { | ||
- | diff=(s16)(ICR1>> | + | diff=ICR1; |
- | if(start> | + | if(start> |
{ | { | ||
- | diff+=(s16)(TOP_COUNT>>1); | + | diff+=TOP_COUNT; |
} | } | ||
+ | diff-=start; | ||
if(diff> | if(diff> | ||
{ | { | ||
Line 60: | Line 63: | ||
{ | { | ||
counter|=0x80; | counter|=0x80; | ||
- | OCR1B=((u16)diff)<<1; | + | OCR1B=diff; |
counter& | counter& | ||
GROUND_LED_ON; | GROUND_LED_ON; |
code/ground_control.1226536757.txt.gz · Last modified: 2008/11/13 00:39 by laurenceb