Fixed issues with timer

This commit is contained in:
_N0x 2021-11-05 09:00:41 +01:00
parent 2bd2215ee9
commit 0eace5b6fe
3 changed files with 49 additions and 29 deletions

View File

@ -28,18 +28,20 @@
<ResetRule>0</ResetRule>
<eraseonlaunchrule>0</eraseonlaunchrule>
<EraseKey />
<avrtool>com.atmel.avrdbg.tool.simulator</avrtool>
<avrtool>com.atmel.avrdbg.tool.stk500</avrtool>
<avrtoolserialnumber />
<avrdeviceexpectedsignature>0x1E9705</avrdeviceexpectedsignature>
<com_atmel_avrdbg_tool_simulator>
<ToolOptions xmlns="">
<ToolOptions>
<InterfaceProperties>
</InterfaceProperties>
<InterfaceName>
</InterfaceName>
</ToolOptions>
<ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
<ToolNumber xmlns="">
<ToolType>com.atmel.avrdbg.tool.simulator</ToolType>
<ToolNumber>
</ToolNumber>
<ToolName xmlns="">Simulator</ToolName>
<ToolName>Simulator</ToolName>
</com_atmel_avrdbg_tool_simulator>
<AsfFrameworkConfig>
<framework-data xmlns="">
@ -53,6 +55,20 @@
</dependencies>
</framework-data>
</AsfFrameworkConfig>
<avrtoolinterface>ISP</avrtoolinterface>
<com_atmel_avrdbg_tool_stk500>
<ToolOptions>
<InterfaceProperties>
<IspClock>115200</IspClock>
</InterfaceProperties>
<InterfaceName>ISP</InterfaceName>
</ToolOptions>
<ToolType>com.atmel.avrdbg.tool.stk500</ToolType>
<ToolNumber>
</ToolNumber>
<ToolName>STK500</ToolName>
</com_atmel_avrdbg_tool_stk500>
<avrtoolinterfaceclock>115200</avrtoolinterfaceclock>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>

View File

@ -12,29 +12,27 @@ volatile uint16_t cntr = 0;
void
Timer_init (void){
TCCR0A |= (1<<1); /* Set WGM01 to high to enable CTC mode */
TCCR0B |= (1<<1); /* Set the clock select bit to pre-scaler 2
1MHz / 8 (pre-scaler 2) ==> 125KHz */
TCCR0A |= (1<<1); /* Set WGM01 to high to enable CTC mode */
TIMSK0 |= (1<<1); /* Set OCIE0A to high to rise an interrupt when the counter matches OCR0A */
OCR0A = 125; /* Set the Output Compare Register 0 A to 125 to trigger interrupt every 1ms
1MHz / 8 (pre-scaler 2) / 125 ==> 1KHz (1ms) */
}
uint16_t
Timer_getTick(void){
return cntr;
uint16_t tmp;
cli();
tmp = cntr;
sei();
return tmp;
}
ISR(TIMER0_COMPA_vect){
cntr++;
}
/*
ISR(TIMER0_OVF_vect){
cntr++;
}
//*/
}

View File

@ -21,6 +21,7 @@ void tast2 (void);
/* global variables */
volatile int g_counter = 0;
int ledStatus = 0;
uint16_t startMS;
/* functions */
int
@ -34,30 +35,35 @@ main (void)
Timer_init();
/* Run Task 1
while (1)
{
/* Run Task 1 */
//task1();
/* Run Task 2 */
task2();
}
task1();
}//*/
/* Run Task 2 */
startMS=Timer_getTick();
while (1)
{
task2();
}//*/
}
/* Task 2 (2021-10-28) */
void
task2 () {
if(Timer_getTick() % 1000 == 0){
if(Timer_getTick()-startMS >= 1000) { /* Wait 1000ms before switching LED1 */
startMS=Timer_getTick();
if(ledStatus % 2 == 0){
Led1_On();
} else {
Led1_Off();
}
ledStatus++;
}
if(ledStatus % 2 == 0){
Led1_On();
} else {
Led1_Off();
}
}