7. Systick Timer
Práctica 11. Interrupción por TIMER:
#include "TM4C123.h" // Device header
#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010))
#define NVIC_ST_LOAD_R (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018))
void SysTick_Handler(void){
GPIOF->DATA ^= 0x04;
}
void GPIO_Handler(void);
void SysTick_Interrupt_Init(){
SysTick->CTRL = 0; // Disable the SysTick during configuration
SysTick->LOAD = 0x00FFFFFF; //Load the number of ticks.
SysTick->VAL = 0;
SysTick->CTRL = (0x1<<2)|(0x1<<1)|(0x1<<0); // 111 Select the clock system and enable the SysTick
}
int main()
{
SYSCTL->RCGC2|=(0x1<<5);// The clock of PORTF
GPIOF->DEN |= 0xFF; //PORTF is Digital enable now
GPIOF->DIR|=(0x1<<2)|(0x1<<3)|(0x1<<1);//LEDs are outputs
SysTick_Interrupt_Init();
while(1){
}
}
#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010))
#define NVIC_ST_LOAD_R (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018))
void SysTick_Handler(void){
GPIOF->DATA ^= 0x04;
}
void GPIO_Handler(void);
void SysTick_Interrupt_Init(){
SysTick->CTRL = 0; // Disable the SysTick during configuration
SysTick->LOAD = 0x00FFFFFF; //Load the number of ticks.
SysTick->VAL = 0;
SysTick->CTRL = (0x1<<2)|(0x1<<1)|(0x1<<0); // 111 Select the clock system and enable the SysTick
}
int main()
{
SYSCTL->RCGC2|=(0x1<<5);// The clock of PORTF
GPIOF->DEN |= 0xFF; //PORTF is Digital enable now
GPIOF->DIR|=(0x1<<2)|(0x1<<3)|(0x1<<1);//LEDs are outputs
SysTick_Interrupt_Init();
while(1){
}
}
De el codigo observe que se agregan las direcciones de 3 registros. Estos son los correspondientes a los registros que configuran el Timer. Apesar de que en esta práctica no se emplean, tengalos a presentes para los proximos programas.
Práctica 9. Uso del Systick Timer para generar retardos por hardware:
El siguiente codigo muestra como generar retardos por hardware sin emplear interrupciones. Por lo tanto se pueden genear delays más precisos a traves del Timer.
De dicho codigo es importante que observe la linea:
SysTick->CTRL = 0x00000005; // 101 Select the clock system and enable the SysTick
En esta se debe notar que no se activa el bit de interrpucion es por ello que se emplea un ciclo while que nos indique cuando se desborde el timer.
Como reto para el estudiante envie una corta explicacion de como funciona este codigo a:
[email protected]
El siguiente codigo muestra como generar retardos por hardware sin emplear interrupciones. Por lo tanto se pueden genear delays más precisos a traves del Timer.
De dicho codigo es importante que observe la linea:
SysTick->CTRL = 0x00000005; // 101 Select the clock system and enable the SysTick
En esta se debe notar que no se activa el bit de interrpucion es por ello que se emplea un ciclo while que nos indique cuando se desborde el timer.
Como reto para el estudiante envie una corta explicacion de como funciona este codigo a:
[email protected]
#include "TM4C123.h" // Device header
#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010))
#define NVIC_ST_LOAD_R (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018))
void SysTick_Delay(unsigned long delay)
{
SysTick->CTRL = 0; // Disable the SysTick during configuration
SysTick->LOAD = delay-1; //Load the number of ticks.
SysTick->VAL = 0;
SysTick->CTRL = 0x00000005; // 101 Select the clock system and enable the SysTick
while((SysTick->CTRL & 0x00010000) == 0); // waiting for COUNT flag.
}
int main()
{
SYSCTL->RCGC2|=(0x1<<5);// The clock of PORTF
GPIOF->DEN |= 0xFF; //PORTF is Digital enable now
GPIOF->DIR|=(0x1<<2)|(0x1<<3)|(0x1<<1);//LEDs are outputs
while(1){
GPIOF->DATA = 0x08;
SysTick_Delay(8000000);
GPIOF->DATA &= ~0x08;
SysTick_Delay(8000000);
}
}
#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010))
#define NVIC_ST_LOAD_R (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018))
void SysTick_Delay(unsigned long delay)
{
SysTick->CTRL = 0; // Disable the SysTick during configuration
SysTick->LOAD = delay-1; //Load the number of ticks.
SysTick->VAL = 0;
SysTick->CTRL = 0x00000005; // 101 Select the clock system and enable the SysTick
while((SysTick->CTRL & 0x00010000) == 0); // waiting for COUNT flag.
}
int main()
{
SYSCTL->RCGC2|=(0x1<<5);// The clock of PORTF
GPIOF->DEN |= 0xFF; //PORTF is Digital enable now
GPIOF->DIR|=(0x1<<2)|(0x1<<3)|(0x1<<1);//LEDs are outputs
while(1){
GPIOF->DATA = 0x08;
SysTick_Delay(8000000);
GPIOF->DATA &= ~0x08;
SysTick_Delay(8000000);
}
}