MPBES Lab 6
MPBES Lab 6
MPBES Lab 6
LABORATORY SESSION # 6
Hardware Delay Using STM32F100xx Timers
6.1 OBJECTIVES
38
Laboratory Manual EE-07310: MP Based Embedded Systems
6.5 PROCEDURE
- Create new project with the name ‘Lab6’, following the steps in Lab Session 1.
- In the ‘main.c’ file, write the code for implementing delay function using hardware timer,
as skeleton shown below.
...
//Configure and start the timer
void Cyclic_Start(const unsigned short PERIOD)
{
RCC_APB1ENR |= 0x00000001; //Timer 2 clock enables
TIM2_CR1 = 0; //Counter Register-Counter disabled (stopped)
TIM2_CNT = 0; //Counter value reset to 0
TIM2_PSC = 7999; //Pre-scaler value calculated for 1ms delay
if(PERIOD > 1)
{
TIM2_ARR = (PERIOD-1);
}
/* If value in PERIOD is given ‘1’, ARR will be 0. ARR is the value up to
which counter increments */
else
{
TIM2_ARR = 1; //When PERIOD is 1ms
}
TIM2_CR1 = 0x0001; //Timer counter enabled (time starts)
}
//Wait for the set time to pass
void Cyclic_Wait(void)
{
while((TIM2_SR & 0x00000001)==0)
{
} //Wait until counter counts up to ARR value
/* Value of register SR is 0 if counter value is <ARR value and value of
register SR is 1 if the counter value is >ARR value */
39
Laboratory Manual EE-07310: MP Based Embedded Systems
- Complete the ‘main.c’ such that the LED blinks at 1Hz when the switch is pressed once.
- Successfully create the HEX file.
- Open the debugger session and start the simulation after opening the Timer 2, GPIOA and
GPIOC peripherals.
- Burn the program and test the results on hardware by connecting the hardware with
oscilloscope.
- Turn on the ‘measure’ window on oscilloscope and verify the frequency of LED toggling.
Students are required to provide the following components in their lab reports.
- Complete ‘main.c’ code developed
- HEX file created successfully in Keil µVision 4
- Software tested in Debugger
- Software tested on the hardware
40