boost_highVoltage_nextTick=(uint16_t)TCNT1+F_CPU/timer1_prescaler*1/(boost_frequency/2);// Half of time it should be high/low
boost_highVoltage_nextTick=(uint16_t)TCNT1+F_CPU/timer1_prescaler*1/boost_frequency/2;// Half of time it should be high/low
if(boost_highVoltage_nextTick==0)boost_highVoltage_nextTick++;// If its 0, it stops, we dont want that
if(boost_highVoltage_nextTick==0)boost_highVoltage_nextTick++;// If its 0, it stops, we dont want that
}
}
}
}
@ -91,7 +91,7 @@ int main()
if((uint16_t)TCNT1>=signalOutput_piezo_nextTick&&((uint16_t)TCNT1-signalOutput_piezo_nextTick)<(timer1_overflow_value/2))// If we are on or after the tick it should be executed
if((uint16_t)TCNT1>=signalOutput_piezo_nextTick&&((uint16_t)TCNT1-signalOutput_piezo_nextTick)<(timer1_overflow_value/2))// If we are on or after the tick it should be executed
{
{
// Flip pin state
// Flip pin state
PORTD^=(1<<PORTD5);
PORTD^=(1<<PORTD5);
if(!(PIND&(1<<PORTD5)))
if(!(PIND&(1<<PORTD5)))
{
{
@ -174,7 +174,8 @@ ISR(INT0_vect)
if(!(PIND&(1<<PORTD2)))// Falling edge
if(!(PIND&(1<<PORTD2)))// Falling edge
{
{
// Below ~400V, activate booster
// Below ~400V, activate booster
boost_highVoltage_nextTick=1;// Run as soon as possible
boost_highVoltage_nextTick=TCNT1;// Run as soon as possible
PORTB|=(1<<PORTB5);// Onboard-Led
PORTB|=(1<<PORTB5);// Onboard-Led
PORTB|=(1<<PORTB5);// Onboard-Led
}
}
@ -183,10 +184,10 @@ ISR(INT0_vect)
// Reached ~400V, deactivate booster
// Reached ~400V, deactivate booster
boost_highVoltage_nextTick=0;
boost_highVoltage_nextTick=0;
PORTB|=(0<<PORTB5);// Onboard-Led
// reset state
// reset state
PORTD|=(0<<PORTD4);// pin on low
PORTD|=(0<<PORTD4);// pin on low
PORTB|=(0<<PORTB5);// Onboard-Led
}
}
reti();// Exit interrupt-handler
reti();// Exit interrupt-handler
@ -197,8 +198,8 @@ ISR(INT0_vect)
ISR(INT1_vect)
ISR(INT1_vect)
{
{
// Tick detected, signalOutput
// Tick detected, signalOutput
signalOutput_piezo_nextTick=1;// Run as soon as possible
signalOutput_piezo_nextTick=TCNT1;// Run as soon as possible