HI liebe Leute,
Ich möchte eine PWM-Signal mit Attiny 26 mit intern Oszillator von 8Mhz
generieren, dabei soll ich das dusty cycle zw. 0% bis 100% einstellen
könne und die Frequenz des PWM-Signal sollte immer 100Khz betragen,
jetzt kann ich mit dem bisherigen Programm nur zwischen PWM-Signa mit
dusty cycle von 65% bis 100% generieren, wenn ich ein Signal mit dusty
cycle unter 65% einstellen will, kriege ich gar kein PWM mehr ( am
Oszilloskope)
Wo könnte das Problem liegen ?? Bitte Hilfe hier mein Code
1 | #include <avr/io.h>
|
2 | #include <avr/interrupt.h>
|
3 |
|
4 |
|
5 | void pwm_init()
|
6 | {
|
7 | TCCR1A |= ((1<<COM1B1)|(1<<PWM1B)); //clear OCR1B on compare macht and pwm mode enable
|
8 | TCCR1B |= ((1<<CTC1)|(1<<CS10)); // CTC mode enable (clear timer on compare match OCR1C OCR1A gibt den dutycycle an) and clock the timer withough prescaller (so we can have enough levels for the duty cycle)
|
9 | TCNT1 = 0;
|
10 | OCR1B = 50; // controliert die dusty (ab 30 2.5 Mittelwert.)
|
11 | OCR1C = 79; // controliert die Frequenz
|
12 | TIMSK|= (1<<OCIE1B); // Timer/counter output compare match with OCR1B interrupt enable
|
13 | sei(); // Timer/counter global interrupt enable
|
14 | }
|
15 |
|
16 |
|
17 | int main(void)
|
18 | {
|
19 | pwm_init();
|
20 |
|
21 | DDRB |= (1<<PB3); // als Ausgang gesetzt das ist der OC1B PIN für PWM
|
22 |
|
23 |
|
24 |
|
25 | while(1)
|
26 | {
|
27 |
|
28 | }
|
29 | }
|