Hallo Leute
Ich würde gerne in einer Interrupt Routine (TIMER0_OVF) eine Software PWM generieren...
Das klappt nicht wie gewünscht... Bei "PWM0 = 2;" sind die Lampen ganz schwach an...
Gehe ich jetzt auf "PWM0= 10;" sind sie gleich auf volle Power... Was mache ich falsch ?
Ich würde gerne in einer Interrupt Routine (TIMER0_OVF) eine Software PWM generieren...
Das klappt nicht wie gewünscht... Bei "PWM0 = 2;" sind die Lampen ganz schwach an...
Gehe ich jetzt auf "PWM0= 10;" sind sie gleich auf volle Power... Was mache ich falsch ?
Code:
#define F_CPU 8000000 // Interner RC Oszillator. Frequenz = 8000000 Hz ( 4 ms. Einschwingzeit )
#define ABSCHALTZEIT 24000 // ABSCHALTZEIT der HighPowerLED´s ( Der TIMER0 läuft ca. jede 10ms in den Interrupt ) 24000
#define HELLIGKEIT 3000 // Wert für den Überlauf ( OCR1A )
#define AB_DIMM_ZEIT 120 // Geschwindigkeit für das ab dimmen der LED´s
#define key_SOS PD3 // Taste SOS
#define key_ON PD2 // Taste ON
#define key_UP PD1 // Taste UP
#define key_DOWN PD0 // Taste Down
#define TIMER_START TCCR1B |= ((1<<CS12) | (1<<CS11) | (1<<CS10));
#define TIMER_STOP TCCR1B &= ~ ((1<<CS12) | (1<<CS11) | (1<<CS10));
#define XPE_1_AN PORTB |= (1<<PB0) // HighPowerLED 1 an
#define XPE_2_AN PORTB |= (1<<PB1) // HighPowerLED 2 an
#define XPE_3_AN PORTB |= (1<<PB2) // HighPowerLED 3 an
#define XPE_4_AN PORTB |= (1<<PB3) // HighPowerLED 4 an
#define alle_AN PORTB |= (0b00001111)
#define alle_AUS PORTB &= ~(0b00001111)
#define XPE_1_AUS PORTB &= ~(1<<PB0) // HighPowerLED 1 aus
#define XPE_2_AUS PORTB &= ~(1<<PB1) // HighPowerLED 2 aus
#define XPE_3_AUS PORTB &= ~(1<<PB2) // HighPowerLED 3 aus
#define XPE_4_AUS PORTB &= ~(1<<PB3) // HighPowerLED 4 aus
#define ALARM_AN PORTB |= (1<<PB4) // Summer an
#define ALARM_AUS PORTB &= ~(1<<PB4) // Summer aus
#include <avr/io.h> // Library für die I/O (Ports)
#include <avr/sleep.h> // Library für den Schlaf Modus
#include <avr/interrupt.h> // Library für die Interrupts
#include <stdint.h> // Benötigt Library für Uint16_t Werte
volatile uint8_t PWM0 = 10;
uint8_t PWMStatus;
int main(void)
{
TCCR0B = (1<<CS00);
TIMSK = (1<<TOIE0);
sei(); // Interrupts global aktivieren
while(1)
{
}// Ende While
}// Ende Main
ISR(TIMER0_OVF_vect) // Schaltet nach jedem Überlauf ( Overflow ) die HighPowerLED´s an
{
static uint8_t counter = 0;
counter++;
if (counter >= 100)
{
counter = 0;
if (PWM0 > 0)
{
alle_AN;
}
else
{
alle_AUS;
}
}// Ende Master if
else
{
if (counter == PWM0)
{
alle_AUS;
}
}
} // Ende ISR (TIMER1_OVF_vect)