Changed some comments

Added clock()
Added stop for signalOutput
Added calculation for booster and signalOutput for nextTick
master
Railz 6 years ago
parent aa6be9199c
commit fb7fafa4be

@ -8,7 +8,7 @@
* MController : AtMega328P * MController : AtMega328P
* Board : Arduino Nano * 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 // Macros
#define bit_get(p,m) ((p) & (m)) #define bit_get(p,m) ((p) & (m))
@ -26,15 +26,15 @@
#include <time.h> #include <time.h>
// Global variable declaration // 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_enable = false;
bool boost_highVoltage_nextHigh = true; bool boost_highVoltage_nextHigh = true;
uint32_t boost_highVoltage_nextTick = 0; clock_t boost_highVoltage_nextTick = 0;
bool signalOutput_enable = false; bool signalOutput_enable = false;
bool signalOutput_nextHigh = true; bool signalOutput_nextHigh = true;
uint32_t signalOutput_nextTick = 0; clock_t signalOutput_nextTick = 0;
int main() int main()
@ -61,7 +61,7 @@ int main()
// HighVoltage boosting // HighVoltage boosting
if(boost_enable) 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 // Set pin according to next exec
if(boost_highVoltage_nextHigh) // Set it high if(boost_highVoltage_nextHigh) // Set it high
@ -76,7 +76,7 @@ int main()
} }
// Calculate when next high/low should be set // 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 }else
{ {
@ -93,7 +93,7 @@ int main()
// Signal output // Signal output
if(signalOutput_enable) 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 // Set pin according to next exec
if(signalOutput_nextHigh) // Set it high if(signalOutput_nextHigh) // Set it high
@ -107,10 +107,12 @@ int main()
bit_set(PD5, 0); bit_set(PD5, 0);
bit_set(PD6, 0); bit_set(PD6, 0);
signalOutput_nextHigh = true; // Next is high signalOutput_nextHigh = true; // Next is high
signalOutput_enable = false; // Disable signalOutput
} }
// When the signal should stop // 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
} }
} }
} }

Loading…
Cancel
Save