# MIOS32_STOPWATCH

## Defines
#define | TIM_PERIPHERAL_FRQ (MIOS32_SYS_CPU_FREQUENCY/4)
#define | STOPWATCH_TIMER_BASE LPC_TIM3
#define | STOPWATCH_TIMER_BASE TIM6
#define | STOPWATCH_TIMER_RCC RCC_APB1Periph_TIM6
#define | TIM_PERIPHERAL_FRQ MIOS32_SYS_CPU_FREQUENCY
#define | STOPWATCH_TIMER_BASE TIM6
#define | STOPWATCH_TIMER_RCC RCC_APB1Periph_TIM6
#define | TIM_PERIPHERAL_FRQ (MIOS32_SYS_CPU_FREQUENCY/2)
## Functions
s32 | MIOS32_STOPWATCH_Init (u32 resolution)
s32 | MIOS32_STOPWATCH_Reset (void)
u32 | MIOS32_STOPWATCH_ValueGet (void)

## Detailed Description

Stopwatch functions for MIOS32

Allows to measure delays, which is especially useful for measuring the performance of a function, but also for user relevant features (e.g. Tap Tempo)

## Define Documentation

#define STOPWATCH_TIMER_BASE TIM6

#define STOPWATCH_TIMER_BASE LPC_TIM3

#define STOPWATCH_TIMER_RCC RCC_APB1Periph_TIM6

#define TIM_PERIPHERAL_FRQ (MIOS32_SYS_CPU_FREQUENCY/2)

#define TIM_PERIPHERAL_FRQ MIOS32_SYS_CPU_FREQUENCY

#define TIM_PERIPHERAL_FRQ (MIOS32_SYS_CPU_FREQUENCY/4)

## Function Documentation

s32 MIOS32_STOPWATCH_Init | ( | u32 | resolution | ) |

Initializes the 16bit stopwatch timer with the desired resolution:

- 1: 1 uS resolution, time measurement possible in the range of 0.001mS .. 65.535 mS
- 10: 10 uS resolution: 0.01 mS .. 655.35 mS
- 100: 100 uS resolution: 0.1 mS .. 6.5535 seconds
- 1000: 1 mS resolution: 1 mS .. 65.535 seconds
- other values should not be used!

         // initialize the stopwatch for 100 uS resolution
         // (only has to be done once, e.g. in APP_Init())
         MIOS32_STOPWATCH_Init(100);

         // reset stopwatch
         MIOS32_STOPWATCH_Reset();

         // execute function
         MyFunction();

         // send execution time via DEFAULT COM interface
         u32 delay = MIOS32_STOPWATCH_ValueGet();
         printf("Execution time of MyFunction: ");
         if( delay == 0xffffffff )
           printf("Overrun!\n\r");
         else
           printf("%d.%d mS\n\r", delay/10, delay%10);

  Note:
    : this function uses TIM4 on the STM32 chip
  Parameters:

    `[in]` | resolution | 1, 10, 100 or 1000

  Returns:
    < 0 on errors
  Initializes the 16bit stopwatch timer with the desired resolution:
  - 1: 1 uS resolution, time measurement possible in the range of 0.001mS .. 65.535 mS
  - 10: 10 uS resolution: 0.01 mS .. 655.35 mS
  - 100: 100 uS resolution: 0.1 mS .. 6.5535 seconds
  - 1000: 1 mS resolution: 1 mS .. 65.535 seconds
  - other values should not be used!

           // initialize the stopwatch for 100 uS resolution
           // (only has to be done once, e.g. in APP_Init())
           MIOS32_STOPWATCH_Init(100);

           // reset stopwatch
           MIOS32_STOPWATCH_Reset();

           // execute function
           MyFunction();

           // send execution time via DEFAULT COM interface
           u32 delay = MIOS32_STOPWATCH_ValueGet();
           printf("Execution time of MyFunction: ");
           if( delay == 0xffffffff )
             printf("Overrun!\n\r");
           else
             printf("%d.%d mS\n\r", delay/10, delay%10);

    Note:
      : this function uses TIM6 of the STM32 chip
    Parameters:

      `[in]` | resolution | 1, 10, 100 or 1000

    Returns:
      < 0 on errors
    Initializes the 16bit stopwatch timer with the desired resolution:
    - 1: 1 uS resolution, time measurement possible in the range of 0.001mS .. 65.535 mS
    - 10: 10 uS resolution: 0.01 mS .. 655.35 mS
    - 100: 100 uS resolution: 0.1 mS .. 6.5535 seconds
    - 1000: NOT SUPPORTED FOR STM32F4!!!
    - other values should not be used!

             // initialize the stopwatch for 100 uS resolution
             // (only has to be done once, e.g. in APP_Init())
             MIOS32_STOPWATCH_Init(100);

             // reset stopwatch
             MIOS32_STOPWATCH_Reset();

             // execute function
             MyFunction();

             // send execution time via DEFAULT COM interface
             u32 delay = MIOS32_STOPWATCH_ValueGet();
             printf("Execution time of MyFunction: ");
             if( delay == 0xffffffff )
               printf("Overrun!\n\r");
             else
               printf("%d.%d mS\n\r", delay/10, delay%10);

      Note:
        : this function uses TIM6 of the STM32 chip
      Parameters:

        `[in]` | resolution | 1, 10, 100 or 1000

      Returns:
        < 0 on errors

s32 MIOS32_STOPWATCH_Reset | ( | void |  | ) |

Resets the stopwatch

Returns:
  < 0 on errors

u32 MIOS32_STOPWATCH_ValueGet | ( | void |  | ) |

Returns current value of stopwatch

Returns:
  1..65535: valid stopwatch value
  0xffffffff: counter overrun