diff --git a/Geigerzaehler/main.c b/Geigerzaehler/main.c index 27d0238..1eed11b 100644 --- a/Geigerzaehler/main.c +++ b/Geigerzaehler/main.c @@ -8,7 +8,7 @@ * MController : AtMega328P * Board : Arduino Nano */ -#define F_CPU 16000000UL // Clock speed: 16 MHz - Maximum of AtMega328P +#define F_CPU 16000000UL // Clock speed: 16 MHz - Speed from onboard oscillator // Macros #define bit_get(p,m) ((p) & (m)) @@ -26,15 +26,15 @@ #include // Global variable declaration -uint32_t currTick = 0; // Todo: Method/Interrupt to get the current-tick +uint16_t boost_frequency = 2000; // 2kHz frequency -bool boost_enable = false; -bool boost_highVoltage_nextHigh = true; -uint32_t boost_highVoltage_nextTick = 0; +bool boost_enable = false; +bool boost_highVoltage_nextHigh = true; +clock_t boost_highVoltage_nextTick = 0; -bool signalOutput_enable = false; -bool signalOutput_nextHigh = true; -uint32_t signalOutput_nextTick = 0; +bool signalOutput_enable = false; +bool signalOutput_nextHigh = true; +clock_t signalOutput_nextTick = 0; int main() @@ -61,7 +61,7 @@ int main() // HighVoltage boosting if(boost_enable) { - if(currTick >= boost_highVoltage_nextTick) // If we are on or after the tick it should be executed + if(clock() >= 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) // Set it high @@ -76,7 +76,7 @@ int main() } // Calculate when next high/low should be set - boost_highVoltage_nextTick = currTick + 101 // Todo: Add calculation for pin high/low time + boost_highVoltage_nextTick = clock() + 1/(boost_frequency/2) // Half of time it should be high/low } }else { @@ -93,7 +93,7 @@ int main() // Signal output if(signalOutput_enable) { - if(currTick >= signalOutput_nextTick) // If we are on or after the tick it should be executed + if(clock() >= signalOutput_nextTick) // If we are on or after the tick it should be executed { // Set pin according to next exec if(signalOutput_nextHigh) // Set it high @@ -107,10 +107,12 @@ int main() bit_set(PD5, 0); bit_set(PD6, 0); signalOutput_nextHigh = true; // Next is high + + signalOutput_enable = false; // Disable signalOutput } // When the signal should stop - signalOutput_nextTick = currTick + 101 // Todo: Add calculation for signalOutput low time + signalOutput_nextTick = clock() + F_CPU * 0.2 // nextTick is in 0.2s } } }