Revision 616
Troubleshooting orb driver code on new charge stations. Currently unable to write to pins.
orb.c | ||
---|---|---|
35 | 35 |
#include <avr/io.h> |
36 | 36 |
#include "orb.h" |
37 | 37 |
|
38 |
int orb_init (void); |
|
39 |
int set_orb (int red, int green, int blue); |
|
40 | 38 |
|
39 |
int main (void){ |
|
40 |
|
|
41 |
DDRB = _BV(DDB4); |
|
42 |
DDRD = _BV(DDD4)|_BV(DDD6); |
|
43 |
|
|
44 |
PORTB = 0b01010000; |
|
45 |
PORTD = 0b00010000; |
|
46 |
|
|
47 |
//orb_init(); |
|
48 |
//set_orb(100, 100, 100); |
|
49 |
while(1); |
|
50 |
return 0; |
|
51 |
} |
|
52 |
|
|
41 | 53 |
/** |
42 | 54 |
* @defgroup orbs Orbs |
43 | 55 |
* @brief Functions for controlling the color of the orbs. |
... | ... | |
54 | 66 |
int orb_init (void) |
55 | 67 |
{ |
56 | 68 |
/*data direction registers, blue, green (bit 7) and red (bit 5)*/ |
57 |
DDRB = _BV(DDB3);
|
|
58 |
DDRD = _BV(DDD7)|_BV(DDD5);
|
|
69 |
DDRB = _BV(DDB4);
|
|
70 |
DDRD = _BV(DDD4)|_BV(DDD6);
|
|
59 | 71 |
|
60 | 72 |
|
61 | 73 |
/*blue is here. it goes on timer 0*/ |
62 | 74 |
/*timer counter control registers for timer 0*/ |
63 |
TCCR0A = _BV(COM0A1)|_BV(COM0A0)|_BV(WGM01)|_BV(WGM00);
|
|
75 |
TCCR0A = _BV(COM0B1)|_BV(COM0B0)|_BV(WGM01)|_BV(WGM00);
|
|
64 | 76 |
TCCR0B = _BV(CS00); |
65 |
OCR0A = 0;
|
|
77 |
OCR0B = 0;
|
|
66 | 78 |
|
67 | 79 |
/*green is here. it goes on timer 2*/ |
68 |
TCCR2A = _BV(COM2A1)|_BV(COM2A0)|_BV(WGM21)|_BV(WGM20);
|
|
80 |
TCCR2A = _BV(COM2B1)|_BV(COM2B0)|_BV(WGM21)|_BV(WGM20);
|
|
69 | 81 |
TCCR2B = _BV(CS20); |
70 |
OCR2A = 0;
|
|
82 |
OCR2B = 0;
|
|
71 | 83 |
|
72 | 84 |
|
73 | 85 |
/*red is here. it goes on timer 1 which counts to the value in ICR1 instead of 8 bits*/ |
74 |
TCCR1A = _BV(COM1A1)|_BV(COM1A0)|_BV(WGM11);
|
|
86 |
TCCR1A = _BV(COM1B1)|_BV(COM1B0)|_BV(WGM11);
|
|
75 | 87 |
TCCR1B = _BV(WGM13)|_BV(WGM12)|_BV(CS10); |
76 | 88 |
ICR1 = 0x9C40; |
77 |
OCR1A = 0;
|
|
89 |
OCR1B = 0;
|
|
78 | 90 |
|
79 | 91 |
return 0; |
80 | 92 |
} |
... | ... | |
93 | 105 |
int set_orb(int red, int green, int blue){ |
94 | 106 |
/*blue is here. it goes on timer 0*/ |
95 | 107 |
blue = blue%256; |
96 |
OCR0A = blue;
|
|
108 |
OCR0B = blue;
|
|
97 | 109 |
|
98 | 110 |
/*green is here. it goes on timer 2*/ |
99 | 111 |
green = green%256; |
100 |
OCR2A = green;
|
|
112 |
OCR2B = green;
|
|
101 | 113 |
|
102 | 114 |
|
103 | 115 |
/*red is here. it goes on timer 1*/ |
104 | 116 |
red = red%256; |
105 | 117 |
red *= (int)(ICR1/256); |
106 |
OCR1A = red;
|
|
118 |
OCR1B = red;
|
|
107 | 119 |
|
108 | 120 |
return 0; |
109 | 121 |
} |
Also available in: Unified diff