Added explicit conversion of timer to uint16_t (Timer shows signs of signed int_8)

master
Railz 6 years ago
parent 81030bade3
commit 6990bff184

@ -25,13 +25,15 @@ uint16_t boost_highVoltage_nextTick = 0;
uint8_t signalOutput_nextHigh = 1;
uint16_t signalOutput_nextTick = 0;
uint8_t timer1_prescaler = 256;
uint8_t timer1_prescaler = 1;
uint16_t test = 0;
int main()
{
// Inputs
DDRD &= (0 << PORTD2); // Activate input PD2
DDRD &= (0 << PORTD3); // Activate input PD3
DDRD &= (0 << PORTD3); // Activate input PD3
//PORTD |= (1 << PORTD2); // Enable pull-up-resistor D2
//PORTD |= (1 << PORTD3); // Enable pull-up-resistor D3
// Todo [CRITICAL]: External pull-down resistors 10kOhm
@ -60,7 +62,7 @@ int main()
/*
* HighVoltage boosting
*/
if(boost_highVoltage_nextTick > 0 && TCNT1 >= boost_highVoltage_nextTick) // If we are on or after the tick it should be executed
if(boost_highVoltage_nextTick > 0 && (uint16_t)TCNT1 >= boost_highVoltage_nextTick) // If we are on or after the tick it should be executed
{
// Set pin according to next exec
if(boost_highVoltage_nextHigh == 1)
@ -75,16 +77,16 @@ int main()
PORTD |= (0 << PORTD4);
boost_highVoltage_nextHigh = 1; // Next is high
}
// Calculate when next high/low should be set
boost_highVoltage_nextTick = 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
}
/*
* Signal output
*/
if(signalOutput_nextTick > 0 && TCNT1 >= signalOutput_nextTick) // If we are on or after the tick it should be executed
if(signalOutput_nextTick > 0 && (uint16_t)TCNT1 >= signalOutput_nextTick) // If we are on or after the tick it should be executed
{
// Set pin according to next exec
if(signalOutput_nextHigh == 1) // Set it high
@ -94,7 +96,7 @@ int main()
signalOutput_nextHigh = 0; // Next is low
// When the signal should stop
signalOutput_nextTick = TCNT1 + F_CPU/timer1_prescaler * signalOutput_time/1000; // nextTick is in signalOutput_time in ms
signalOutput_nextTick = (uint16_t)TCNT1 + F_CPU/timer1_prescaler * signalOutput_time/1000; // nextTick is in signalOutput_time in ms
if(signalOutput_nextTick == 0) signalOutput_nextTick++; // If its 0, it stops, we dont want that
}
else // Set it low
@ -141,7 +143,7 @@ void timer1_init()
}
// initialize counter
TCNT1 = 0;
TCNT1 = (uint16_t)0;
}

Loading…
Cancel
Save