|
|
@ -49,11 +49,11 @@ int main()
|
|
|
|
DDRB |= (1 << PORTB5); // Onboard-Led
|
|
|
|
DDRB |= (1 << PORTB5); // Onboard-Led
|
|
|
|
|
|
|
|
|
|
|
|
// Interrupts
|
|
|
|
// Interrupts
|
|
|
|
// for INT0 Pin-D2 High-voltage check
|
|
|
|
// for INT0 Pin-D2 - Counter-click
|
|
|
|
EICRA |= (0 << ISC01)|(1 << ISC00); // On at any edge [Code: 01]
|
|
|
|
EICRA |= (0 << ISC01)|(1 << ISC01); // On rising edge [Code: 01]
|
|
|
|
EIMSK |= (1 << INT0); // Activate Interrupt INT0
|
|
|
|
EIMSK |= (1 << INT0); // Activate Interrupt INT0
|
|
|
|
// for INT1 Pin-D3 Counter-click
|
|
|
|
// for INT1 Pin-D3 - High-voltage check
|
|
|
|
EICRA |= (1 << ISC11)|(1 << ISC10); // On rising edge [Code: 11]
|
|
|
|
EICRA |= (1 << ISC10)|(1 << ISC11); // On any edge [Code: 11]
|
|
|
|
EIMSK |= (1 <<INT1); // Activate Interrupt INT1
|
|
|
|
EIMSK |= (1 <<INT1); // Activate Interrupt INT1
|
|
|
|
|
|
|
|
|
|
|
|
// Init timer1
|
|
|
|
// Init timer1
|
|
|
@ -61,11 +61,11 @@ int main()
|
|
|
|
|
|
|
|
|
|
|
|
PORTB |= (boost_highVoltage_nextTick << PORTB5); // Onboard-Led
|
|
|
|
PORTB |= (boost_highVoltage_nextTick << PORTB5); // Onboard-Led
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sei(); // Activate global interrupts (after checks) [when an interrupt was fired, it will now be executed]
|
|
|
|
|
|
|
|
|
|
|
|
// Endless loop
|
|
|
|
// Endless loop
|
|
|
|
while (1)
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cli(); // Deactivate global interrupts (before checks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* HighVoltage boosting
|
|
|
|
* HighVoltage boosting
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -124,8 +124,6 @@ int main()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sei(); // Activate global interrupts (after checks) [when an interrupt was fired, it will now be executed]
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -133,7 +131,7 @@ int main()
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void timer1_init()
|
|
|
|
void timer1_init()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// set up timer with speed: cpu-clock / prescaler
|
|
|
|
// set up timer with speed = cpu-clock / prescaler
|
|
|
|
switch(timer1_prescaler){ // [CS12 CS11 CS10]
|
|
|
|
switch(timer1_prescaler){ // [CS12 CS11 CS10]
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
@ -167,9 +165,20 @@ void timer1_init()
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* ISR - Interrupt service routine
|
|
|
|
* ISR - Interrupt service routine
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
// Address: 0x001 INT0 - On any edge [Code: 01]
|
|
|
|
// Address: 0x001 INT0 - On rising edge [Code: 11]
|
|
|
|
// Handles: Over/Below working voltage
|
|
|
|
// Handles: Counter tube "click"
|
|
|
|
ISR(INT0_vect)
|
|
|
|
ISR(INT0_vect)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Tick detected, signalOutput
|
|
|
|
|
|
|
|
signalOutput_piezo_nextTick = TCNT1; // Run as soon as possible
|
|
|
|
|
|
|
|
signalOutput_led_nextTick = TCNT1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reti(); // Exit interrupt-handler
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Address: 0x002 INT1 - On any edge [Code: 01]
|
|
|
|
|
|
|
|
// Handles: Over/Below working voltage
|
|
|
|
|
|
|
|
ISR(INT1_vect)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!(PIND & (1 << PORTD2))) // Falling edge
|
|
|
|
if(!(PIND & (1 << PORTD2))) // Falling edge
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -188,18 +197,7 @@ ISR(INT0_vect)
|
|
|
|
|
|
|
|
|
|
|
|
// reset state
|
|
|
|
// reset state
|
|
|
|
PORTD |= (0 << PORTD4); // pin on low
|
|
|
|
PORTD |= (0 << PORTD4); // pin on low
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reti(); // Exit interrupt-handler
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Address: 0x002 INT1 - On rising edge [Code: 11]
|
|
|
|
|
|
|
|
// Handles: Counter tube "tick"
|
|
|
|
|
|
|
|
ISR(INT1_vect)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Tick detected, signalOutput
|
|
|
|
|
|
|
|
signalOutput_piezo_nextTick = TCNT1; // Run as soon as possible
|
|
|
|
|
|
|
|
signalOutput_led_nextTick = TCNT1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reti(); // Exit interrupt-handler
|
|
|
|
reti(); // Exit interrupt-handler
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|