Make the ADC trigger an
ADC result ready interrupt to wake up the CPU from sleep every time an
ADC result is ready by adding the following line to the adc_init():
/*Activate interrupt on Result ready to wake up from sleep*/
ADC0.INTCTRL = ADC_RESRDY_bm;
Change the following code
to adc_init() to enable the ADC to run in Standby sleep mode:
ADC0.CTRLA = ADC_ENABLE_bm | ADC_RUNSTDBY_bm; /*Enable the ADC and run in standby sleep mode*/
Change the adc_result_is_ready() to the following, so it
works with an interrupt based
ADC:
Info: When the ADC is in Series mode, each event triggers one single sample as
opposed to the Burst mode, where one event triggers all the samples needed
for one result, which means that the sampling frequency must be a lot higher
than the result frequency.
Tip: To control the result
frequency instead of the sampling frequency, define the sampling frequency
using the result frequency and the number of samples by writing:
Add the following code to
the end of the transmit_to_DV() in
data_streamer.c to make sure the device does not go to sleep
before the transmission is
complete:
while (!(USART0.STATUS & USART_TXCIF_bm)); /* Wait for all USART transmission to be finished */
USART0.STATUS |= USART_TXCIF_bm; /* Clear Tx complete flag */
Info: When the device does not go
to sleep, it uses 24 mW, while when it goes to Standby sleep mode, it uses
12 mW, so it can be seen that going to sleep between results can reduce the
power by up to 50%. The measurements were taken with a result frequency
of 20 Hz, 512 accumulated samples, without the blinking LED.
Verify that the solution builds with no
errors by selecting Build → Build Solution from the top menu bar in Microchip
Studio or pressing the F7 key.
Flash the device by selecting Debug →
Start without debugging for the top menu bar in Microchip Studio or pressing the Ctrl+Alt+F5 keys.
Plot the single ADC sample vs. the ADC average
result using the MPLAB Data Visualizer. Try different sampling
frequencies and change the force applied to the force sensor periodically.
Info: Due to the configured clock
frequency of the RTC, the highest sampling frequency is 32768 Hz. The result
frequency is dependent on the sampling frequency and the number of samples,
meaning that the maximum result frequency for 1024 samples is 32
Hz.
Result: Measuring the
analog signal from the Force click using the ADC in Series mode and using the RTC
and event system to continuously trigger the ADC sample. The device is in Standby
sleep mode between each result. When the sampling frequency is low, the result should
look similar to Figure 3-3, and
when it is high, it should look similar to Figure 3-4. See that, if the sampling frequency is
too low, the result becomes the average of the rapidly changing signal, and a lot of
information is lost. Figure 3-3. Assignment 2: 1 Hz Result
FrequencyFigure 3-4. Assignment 2: 64 Hz Result
Frequency
The online versions of the documents are provided as a courtesy. Verify all content and data in the device’s PDF documentation found on the device product page.