Hallo,
Ich will ein kleines Progi schreiben das auf einen Attiny85 drei PWM und
ein ADC - Pin steuert. Nun habe ich zwei kleine Progis geschriben die
einzeln einwandfrei funktionieren. Aber sobald ich sie zusammenfüge hab
reagier weder PWM noch ADC. Kann mir jemand sagen warum…
1 | /*
|
2 | * LED_PWM.c
|
3 | *
|
4 | * Created: 06.09.2013 13:13:37
|
5 | * Author: Mohan
|
6 | */
|
7 |
|
8 | #define F_CPU 1000000UL
|
9 |
|
10 | #include <avr/io.h>
|
11 | #include <util/delay.h>
|
12 | #include <avr/interrupt.h>
|
13 |
|
14 | int ADC_val;
|
15 |
|
16 | // re- / start interrupt
|
17 | void start_ADC(void)
|
18 | {
|
19 | ADCSRA |= (1 << ADSC);
|
20 | }
|
21 |
|
22 | int main(void)
|
23 | {
|
24 | // PORT init
|
25 | DDRB = (1 << DDB4) | (1 << DDB1) | (1 << DDB0);
|
26 | PORTB = 0x00;
|
27 |
|
28 | // set Bits for FPWM Timer0
|
29 | TCCR0A = (1 << COM0A1) | (1 << COM0B1) | (1 << WGM00) | (1 << WGM01);
|
30 |
|
31 | // set Bits for NPWM Timer1
|
32 | GTCCR = (1 << PWM1B) | (1<< COM1B0);
|
33 |
|
34 | // Set Timer0 interrupt Bit | Set Timer1 interrupt Bit
|
35 | TIMSK = (1 << TOIE0) | (1 << TOIE1);
|
36 |
|
37 | // FPWM VALUES
|
38 | OCR0A = 0;
|
39 | OCR0B = 0;
|
40 |
|
41 | DDRB = (1 << DDB4) | (1 << DDB1) | (1 << DDB0);
|
42 | PORTB = 0x13;
|
43 |
|
44 | // ADC init
|
45 | ADMUX = (1 << MUX0) | (1 << MUX1);
|
46 | ADCSRA = (1 << ADEN) | (1 << ADIE) | (1 << ADPS2) | (1 << ADPS0);
|
47 | DIDR0 = (1 << ADC3D);
|
48 |
|
49 | // NPWM VLUES
|
50 | OCR1B = 0;
|
51 | OCR1C = 255;
|
52 |
|
53 | // start Timers
|
54 | TCCR1 = (1 << CS10);
|
55 | TCCR0B = (1 << CS00);
|
56 |
|
57 | // start interrupts
|
58 | sei();
|
59 |
|
60 | start_ADC();
|
61 |
|
62 | while(1)
|
63 | {
|
64 |
|
65 | }
|
66 | }
|
67 |
|
68 | ISR(ADC_vect)
|
69 | {
|
70 | ADC_val = ADC;
|
71 | start_ADC();
|
72 | }
|
73 |
|
74 | // Timer1 interrupt
|
75 | ISR(TIMER1_OVF_vect)
|
76 | {
|
77 | OCR1B = 255; // grün
|
78 | }
|
79 |
|
80 | // Timer0 interrupt
|
81 | ISR(TIMER0_OVF_vect)
|
82 | {
|
83 | OCR0A = 255; // rot
|
84 | OCR0B = 255; // blau
|
85 | }
|