In this use case, the Frequency Meter (FREQM) module is configured for:
- The FREQM peripheral will not be stopped in standby sleep mode.
This use case will read measurement data in interrupt mode repeatly. After reading specific size of buffer data, the board LED will be toggled.
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Copy-paste the following setup code to your user application:
{
config_freqm.ref_clock_circles = 255;
}
{
freqm_read_done = true;
}
{
}
Add to user application initialization (typically the start of main()
):
Workflow
- Create an FREQM device instance struct, which will be associated with an FREQM peripheral hardware instance.
- Note
- Device instance structures shall never go out of scope when in use.
- Create a new function
configure_freqm()
, which will be used to configure the overall FREQM peripheral.
- Create an FREQM peripheral configuration structure that will be filled out to set the module configuration.
- Fill the FREQM peripheral configuration structure with the default module configuration values.
config_freqm.ref_clock_circles = 255;
- Initialize the FREQM peripheral and associate it with the software instance structure that was defined previously.
- Create a new callback function.
{
freqm_read_done = true;
}
- Create a callback status software flag.
bool volatile freqm_read_done = false;
- Let the callback function set the flag to true when read job done.
- Create a new function
configure_freqm_callback()
, which will be used to configure the callbacks.
- Register callback function.
- Enable the callbacks.
- Enable the now initialized FREQM peripheral.
- Note
- This should not be done until after the FREQM is setup and ready to be used.
Implementation
Code
Copy-paste the following code to your user application:
uint32_t measure_result;
while (!freqm_read_done) {
}
switch(status) {
LED_On(LED_0_PIN);
while (true) {
}
while (true) {
LED_Toggle(LED_0_PIN);
volatile uint32_t delay = 50000;
while(delay--) {
}
}
default:
break;
}
Workflow
- Start an asynchronous FREQM read job, to store measurement data into the global buffer and generate a callback when complete.
- Wait until the asynchronous read job is complete.
while (!freqm_read_done) {
}
- The board LED on to indicate measurement data read.
LED_On(LED_0_PIN);
while (true) {
}
- The board LED toggled to indicate measurement overflow occous.
while (true) {
LED_Toggle(LED_0_PIN);
volatile uint32_t delay = 50000;
while(delay--) {
}
}