Update: I previously had measured (incorrectly) a conversion rate of 4MHz – on moving to better instrumentation this proved to be incorrect. The maximum stable conversion rate comes out just below 2MHz. This example runs the system at 1MHz.
The STM32L432KC Nucleo board is a low cost board (approx €13) in the same form factor as an Arduino Nano. The onboard CPU is based on an ARM Cortex M4F running at 80MHz. It features a very fast ADC and 2 DAC output as well as a number of timers, serial interfaces and so on.
I was curious to see how fast the ADC could be read using a timer as a trigger so I put together a simple program that reads an analogue input and writes this value back out to the DAC. The graph above shows two traces: the output is green and is overlaid on top of the input (yellow). The input signal is a 20kHz sine wave (DC shifted to 1.5V). The system is reading the input signal and updating the output at 1MHz. An interrupt service routine (ISR) is called at each ADC conversion which consists of the following code:
void ADC_ISR() { // The green LED output is used to measure the execution time of the ISR GPIOB_ODR |= BIT3; // Turn on green led ADC1_ISR = BIT3; // clear ADC interrupt flag GPIOB_ODR |= BIT3; // Toggle green led ADCValue = ADC1_DR; // Read latest value from ADC conversion writeDAC(ADCValue); // Write new output to DAC GPIOB_ODR &= ~BIT3; // Turn off green led }
The onboard LED is driven high at the beginning of the ISR and low again on exit. This allows a measurement to be made of CPU usage inside the ISR. I used an oscilloscope to monitor the behaviour of the LED pin and this is shown in the trace below
As can be seen, the CPU is loaded to around 25%
Source code for this example and others is available over here on Github
Compiling should be pretty straightforward:
(1) Run the build script (batch file) on Linux/Windows/Mac.
(2) Plug the nucleo board in to your computer and it should appear as disk
(3) Copy “main.bin” to this new “disk”
This should program the board and start the program running.