Use of system beats

Source: Internet
Author: User
Tags file info

When we use Systick, we first need to determine the clock cycle before we can use it.

The maximum count value for Systick is: 2^24 (2 of 24)

Exceeding this value, the system automatically resets 0.

If this value is exceeded at the time of configuration, Systick is not started.

#define SYSTICK_MAXCOUNT ((1<<24)-1)/* SYSTICK MAXCOUNT */

#if (__vendor_systickconfig = = 0)

/** \brief System Tick Configuration

This function initialises the system tick timer and its interrupt and start the system tick timer.
Counter is on free running mode to generate periodical interrupts.

\param [in] ticks number of ticks between, interrupts
\return 0 Function Succeeded
\return 1 Function failed
*/
Static __inline uint32_t systick_config (uint32_t ticks)
{
if (Ticks > Systick_load_reload_msk) return (1); /* Reload value impossible */
if (Ticks > Systick_maxcount) return (1); /* Reload value impossible */
Systick->load = (Ticks & Systick_load_reload_msk)-1; /* Set Reload Register */
Nvic_setpriority (SYSTICK_IRQN, (1<<__nvic_prio_bits)-1); /* Set priority for CORTEX-M0 System interrupts */
Systick->val = 0; /* Load the SysTick Counter Value */
Systick->ctrl = Systick_ctrl_clksource_msk |
Systick_ctrl_tickint_msk |
Systick_ctrl_enable_msk; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function Successful */
}

#endif

/*@} End of Cmsis_core_systickfunctions */

Note that there is no "SYSTICK_MAXCOUNT" macro defined in Cmsis V2.02.

There are 2 things we need to do before we use this function:

1. Initializing the system clock

Systemcoreclockupdate ();

2. Determine the 50US clock value

#define PCLK (SYSTEMCORECLOCK/4)
#define Pclk_benchmark (pclk/1000)
#define PCLK_50US (Pclk_benchmark * 2)

Main program:

/****************************************copyright (c) ****************************************************
* * TDTC Tech Dev
* * HRB
* *--------------File Info---------------------------------------------------------------------------------
* * File NAME:MAIN.C
* * Last modified Date:
* * Last Version:
* * Descriptions:
**
**--------------------------------------------------------------------------------------------------------
* * Created BY:TDTC
* * Created date:2015-07-09
* * version:v0.01
* * Descriptions:uart Send
**
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
#include "LPC17xx.h"
#include "Uart.h"

#define     led          1UL << 2                                  /* p2.2        */
#define     led_init ()    lpc_gpio2->fiodir |= led                 /* LED init   */
#define     Led_off ()     lpc_gpio2->fioset |= led                 /* LED off    */
#define      led_on ()      lpc_gpio2->fioclr |= led                 /* LED on     */

#define PCLK (SYSTEMCORECLOCK/4)
#define Pclk_benchmark (pclk/1000)
#define PCLK_50US (Pclk_benchmark * 2)

void Systick_handler (void)
{
Static uint32_t count=0;
count++;
if (count%2) {
Led_on ();
} else {
Led_off ();
}
}

int main (void)
{
Systemcoreclockupdate ();
Uartinit (0, 19200);
Led_init ();
Led_off ();
Systick_config (PCLK_50US * 2); 1ms


while (1) {
;
}
}

We activate the waveform by flashing lights in the system beat Interrupt (Systick_handler).

Waveform diagram in Saleae logic Analyzer

Use of system beats

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.