Revision 728
Changed bom_init and bom_on so that only bom_init needs the type argument. At the moment trying to debug some strange issue where PC4 and PC5 do not turn off.
branches/autonomous_recharging/code/projects/libbayboard/lbom.h | ||
---|---|---|
37 | 37 |
|
38 | 38 |
#ifndef _LBOM_H |
39 | 39 |
#define _LBOM_H |
40 |
#include "serial.h" |
|
41 |
#define BOM_ALL_ON 0xF |
|
42 |
#define BOM 0 |
|
43 |
#define BOM1_5 1 |
|
44 |
#define RBOM 2 |
|
45 |
#define BOM0 PC4 |
|
46 |
#define BOM1 PC5 |
|
47 |
#define BOM2 PC6 |
|
48 |
#define BOM3 PC7 |
|
40 | 49 |
|
41 | 50 |
/** |
42 | 51 |
* @addtogroup lbom |
branches/autonomous_recharging/code/projects/libbayboard/lbom.c | ||
---|---|---|
37 | 37 |
#include <avr/io.h> |
38 | 38 |
#include "lbom.h" |
39 | 39 |
|
40 |
#define ALL_ON 0b1111 |
|
41 |
#define BOM 0 |
|
42 |
#define BOM1_5 1 |
|
43 |
#define RBOM 2 |
|
44 |
#define BOM0 DDC4 |
|
45 |
#define BOM1 DDC5 |
|
46 |
#define BOM2 DDC6 |
|
47 |
#define BOM3 DDC7 |
|
48 |
|
|
49 | 40 |
static char bom_mode; |
41 |
static char led_mask; |
|
50 | 42 |
|
51 | 43 |
/** |
52 | 44 |
* @defgroup lbom LBOM (Bearing and Orientation Module) |
... | ... | |
65 | 57 |
|
66 | 58 |
/** @brief Sets up the LBOM to be used. **/ |
67 | 59 |
void bom_init(char type){ |
68 |
//set_leds(ALL_ON);
|
|
60 |
set_leds(BOM_ALL_ON);
|
|
69 | 61 |
DDRC |= _BV(BOM0)|_BV(BOM1)|_BV(BOM2)|_BV(BOM3); |
70 |
PORTC |= 0b11110000; |
|
71 | 62 |
DDRD |= _BV(DDD7); //sets bom carrier to write |
72 | 63 |
bom_mode = type; |
73 |
bom_on(type); |
|
74 |
} |
|
75 |
/** @brief Turns the LBOM on. **/ |
|
76 |
void bom_on(void){ |
|
77 |
//start timer 2 if not already started |
|
78 |
TCCR2A = _BV(COM2A1)|_BV(COM2A0)|_BV(WGM21)|_BV(WGM20); |
|
79 |
TCCR2B = _BV(CS20); |
|
80 |
switch(bom_mode){ |
|
64 |
usb_puti(DDRC); |
|
65 |
switch(bom_mode){ |
|
66 |
case RBOM: |
|
67 |
//set the carrier to produce a 31kHz 50% duty cycle signal |
|
68 |
TCCR2A = _BV(COM2A1)|_BV(COM2A0)|_BV(WGM21)|_BV(WGM20); |
|
69 |
TCCR2B = _BV(CS20); |
|
70 |
OCR2A = 127; |
|
81 | 71 |
case BOM: |
82 |
OCR2A = 1; |
|
83 | 72 |
case BOM1_5: |
84 |
OCR2A = 1; |
|
85 |
case RBOM: |
|
86 |
OCR2A = 127; |
|
87 | 73 |
default: |
88 |
OCR2A = 1;
|
|
74 |
PORTD |= _BV(PD7);
|
|
89 | 75 |
} |
90 | 76 |
} |
77 |
/** @brief Turns the LBOM on. **/ |
|
78 |
void bom_on(void){ |
|
79 |
PORTC |= led_mask; |
|
80 |
usb_putc('N'); |
|
81 |
usb_puti(PORTC); |
|
82 |
} |
|
91 | 83 |
/** @brief Turns the LBOM off. **/ |
92 | 84 |
void bom_off(void){ |
93 |
OCR2A = 0; |
|
85 |
PORTC &= ~led_mask; |
|
86 |
usb_putc('F'); |
|
87 |
usb_puti(PORTC); |
|
94 | 88 |
} |
95 | 89 |
/** @brief Sets which emitters are in use. **/ |
96 | 90 |
void set_leds(int bit_field){ |
97 |
DDRC |= (bit_field << 4); |
|
91 |
led_mask = ((bit_field&BOM_ALL_ON) << 4); |
|
92 |
usb_puti(led_mask); |
|
98 | 93 |
} |
99 | 94 |
|
100 | 95 |
/** @} **/ //end group |
Also available in: Unified diff