Hallo ich habe mir eine LED matrix zusammen gelötet und diese funktioniert auch sehr gut, jedoch möchte ich jetzt nicht nur an und aus haben sondern auch verscheidene helligkeiten. Hierzu habe ich einene LED würfel Code umgebaut. Verwendet wird ein Atmega32 mit 8mhz intern.
1 | ISR(TIMER2_COMP_vect) |
2 | { |
3 | PORTC = 0xFF; // Turn all cathode layers off. (all transistors off) |
4 | PORTA = 0x00;//Turn off output |
5 | PORTA = cube[current_layer]; //Load bytes unsigned char CUBE[8] |
6 | PORTC ^= (1 << current_layer); |
7 | |
8 | if (current_layer == 8) |
9 | { |
10 | current_layer = 0; |
11 | } |
12 | } |
13 | |
14 | |
15 | void ioinit (void) |
16 | { |
17 | DDRA = 0xff; // DATA bus output |
18 | DDRC = 0xff; // Layer select output |
19 | |
20 | PORTA = 0x00; // Set data bus off |
21 | PORTC = 0x00; // Set layer select off |
22 | |
23 | OCR2 = 10; // interrupt at counter = 10 |
24 | TCCR2 |= (1 << CS20) | (1 << CS22); // Prescaler = 128. |
25 | TCCR2 |= (1 << WGM21); // CTC mode. Reset counter when OCR2 is reached. |
26 | TCNT2 = 0x00; // initial counter value = 0; |
27 | TIMSK |= (1 << OCIE2); // Enable CTC interrupt |
28 | } |
jetztiges Fake pwm. Funktioniert aber nur bedingt und die leds sind trozdem noch relativ hell oder flakern.
1 | volatile unsigned char cubebrightness[CUBE_SIZE][CUBE_SIZE]; |
2 | volatile unsigned char cubebrightnesscount[CUBE_SIZE][CUBE_SIZE]; |
3 | |
4 | Im Timer interrupt: |
5 | |
6 | temp = cube[current_layer]; |
7 | for(i = 0;i<8;i++) |
8 | { |
9 | cubebrightnesscount[i][current_layer]++; |
10 | if(cubebrightnesscount[i][current_layer]<cubebrightness[i][current_layer]) |
11 | { |
12 | temp &= ~(1<<i); |
13 | |
14 | } |
15 | else |
16 | { |
17 | cubebrightnesscount[i][current_layer]=0; |
18 | } |
19 | } |
20 | PORTA = temp; |
Wie kann ich das hier besser machen?