This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
code:ground_control [2008/11/13 00:40] laurenceb |
code:ground_control [2008/11/13 09:50] (current) laurenceb |
||
---|---|---|---|
Line 13: | Line 13: | ||
void run_ground_control(); | void run_ground_control(); | ||
</code> | </code> | ||
+ | |||
====Main code=== | ====Main code=== | ||
Line 20: | Line 21: | ||
#include "main.h" | #include "main.h" | ||
extern volatile u08 counter; //globals | extern volatile u08 counter; //globals | ||
- | extern volatile s16 diff; | + | extern volatile u16 diff; |
Line 36: | Line 37: | ||
if(!(counter&0x80)) //the lock bit isn't set, so we are free to run | if(!(counter&0x80)) //the lock bit isn't set, so we are free to run | ||
{ | { | ||
- | diff=(s16)(ICR1>>1)-(s16)(start>>1); //set the global volatile s16 diff | + | diff=ICR1; //set the global volatile s16 diff |
- | if(start>ICR1) //our pwm pulse spans a timer overflow | + | if(start>diff) //our pwm pulse spans a timer overflow |
{ | { | ||
- | diff+=(s16)(TOP_COUNT>>1); | + | diff+=TOP_COUNT; |
} | } | ||
+ | diff-=start; | ||
if(diff>PULSE_MIN && diff<PULSE_MAX) //test against criterion | if(diff>PULSE_MIN && diff<PULSE_MAX) //test against criterion | ||
{ | { | ||
Line 61: | Line 63: | ||
{ | { | ||
counter|=0x80; //lock the diff variable using the counter flag bit | counter|=0x80; //lock the diff variable using the counter flag bit | ||
- | OCR1B=((u16)diff)<<1; | + | OCR1B=diff; |
counter&=~0x80; | counter&=~0x80; | ||
GROUND_LED_ON; | GROUND_LED_ON; |