Added init for timer1 (TCMT1) with cpu-clock/256
Changed clock() to timer1 (TCNT1)
This commit is contained in:
parent
850421e3cc
commit
64280423fa
@ -20,10 +20,10 @@
|
|||||||
<OverrideVtor>false</OverrideVtor>
|
<OverrideVtor>false</OverrideVtor>
|
||||||
<CacheFlash>true</CacheFlash>
|
<CacheFlash>true</CacheFlash>
|
||||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||||
<RamSnippetAddress />
|
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||||
<UncachedRange />
|
<UncachedRange />
|
||||||
<preserveEEPROM>true</preserveEEPROM>
|
<preserveEEPROM>true</preserveEEPROM>
|
||||||
<OverrideVtorValue />
|
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||||
<BootSegment>2</BootSegment>
|
<BootSegment>2</BootSegment>
|
||||||
<ResetRule>0</ResetRule>
|
<ResetRule>0</ResetRule>
|
||||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||||
@ -40,6 +40,19 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
</framework-data>
|
</framework-data>
|
||||||
</AsfFrameworkConfig>
|
</AsfFrameworkConfig>
|
||||||
|
<avrtool>com.atmel.avrdbg.tool.simulator</avrtool>
|
||||||
|
<avrtoolserialnumber />
|
||||||
|
<avrdeviceexpectedsignature>0x1E950F</avrdeviceexpectedsignature>
|
||||||
|
<com_atmel_avrdbg_tool_simulator>
|
||||||
|
<ToolOptions xmlns="">
|
||||||
|
<InterfaceProperties>
|
||||||
|
</InterfaceProperties>
|
||||||
|
</ToolOptions>
|
||||||
|
<ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
|
||||||
|
<ToolNumber xmlns="">
|
||||||
|
</ToolNumber>
|
||||||
|
<ToolName xmlns="">Simulator</ToolName>
|
||||||
|
</com_atmel_avrdbg_tool_simulator>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<ToolchainSettings>
|
<ToolchainSettings>
|
||||||
|
@ -20,13 +20,13 @@ uint16_t boost_frequency = 2000; // 2kHz frequency
|
|||||||
|
|
||||||
uint8_t boost_enable = 0;
|
uint8_t boost_enable = 0;
|
||||||
uint8_t boost_highVoltage_nextHigh = 1;
|
uint8_t boost_highVoltage_nextHigh = 1;
|
||||||
clock_t boost_highVoltage_nextTick = 0;
|
uint16_t boost_highVoltage_nextTick = 0;
|
||||||
|
|
||||||
// Todo [CRITICAL]: Clock does not exist! Use timer.
|
// Todo [CRITICAL]: Clock does not exist! Use timer.
|
||||||
|
|
||||||
uint8_t signalOutput_enable = 0;
|
uint8_t signalOutput_enable = 0;
|
||||||
uint8_t signalOutput_nextHigh = 1;
|
uint8_t signalOutput_nextHigh = 1;
|
||||||
clock_t signalOutput_nextTick = 0;
|
uint16_t signalOutput_nextTick = 0;
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -51,6 +51,9 @@ int main()
|
|||||||
EICRA |= (1 << ISC11)|(1 << ISC10); // On rising edge [Code: 11]
|
EICRA |= (1 << ISC11)|(1 << ISC10); // On rising edge [Code: 11]
|
||||||
EIMSK |= (1 <<INT1); // Activate Interrupt INT1
|
EIMSK |= (1 <<INT1); // Activate Interrupt INT1
|
||||||
|
|
||||||
|
// Init timer1
|
||||||
|
timer1_init();
|
||||||
|
|
||||||
sei(); // Activate global interrupts
|
sei(); // Activate global interrupts
|
||||||
|
|
||||||
// Endless loop
|
// Endless loop
|
||||||
@ -59,7 +62,7 @@ int main()
|
|||||||
// HighVoltage boosting
|
// HighVoltage boosting
|
||||||
if(boost_enable == 1)
|
if(boost_enable == 1)
|
||||||
{
|
{
|
||||||
if(clock() >= boost_highVoltage_nextTick) // If we are on or after the tick it should be executed
|
if(TCNT1 >= 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 == 1) // Set it high
|
if(boost_highVoltage_nextHigh == 1) // Set it high
|
||||||
@ -74,7 +77,7 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate when next high/low should be set
|
// Calculate when next high/low should be set
|
||||||
boost_highVoltage_nextTick = clock() + F_CPU * 1/(boost_frequency/2); // Half of time it should be high/low
|
boost_highVoltage_nextTick = TCNT1 + F_CPU/256 * 1/(boost_frequency/2); // Half of time it should be high/low
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
@ -91,7 +94,7 @@ int main()
|
|||||||
// Signal output
|
// Signal output
|
||||||
if(signalOutput_enable)
|
if(signalOutput_enable)
|
||||||
{
|
{
|
||||||
if(clock() >= signalOutput_nextTick) // If we are on or after the tick it should be executed
|
if(TCNT1 >= 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 == 1) // Set it high
|
if(signalOutput_nextHigh == 1) // Set it high
|
||||||
@ -110,12 +113,34 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When the signal should stop
|
// When the signal should stop
|
||||||
signalOutput_nextTick = clock() + F_CPU * 0.2; // nextTick is in 0.2s
|
signalOutput_nextTick = TCNT1 + F_CPU/256 * 0.2; // nextTick is in 0.2s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void timer1_init()
|
||||||
|
{
|
||||||
|
// set up timer with prescaler = 256
|
||||||
|
TCCR1B |= (1 << CS12);
|
||||||
|
|
||||||
|
// initialize counter
|
||||||
|
TCNT1 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(TIMER1_COMPA_vect){
|
||||||
|
|
||||||
|
//Code Kanal A Timer 1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(TIMER1_COMPB_vect){
|
||||||
|
|
||||||
|
//Code Kanal B Timer 1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Interrupt-handler
|
* Interrupt-handler
|
||||||
* ISR - Interrupt service routine
|
* ISR - Interrupt service routine
|
||||||
|
Loading…
x
Reference in New Issue
Block a user