RPM Meter With STM32

by Fernando Koyanagi in Circuits > Microcontrollers

10749 Views, 3 Favorites, 0 Comments

RPM Meter With STM32

Medidor de RPM com STM32
1.png

Although it is somewhat of a nuisance to buy (because it is not available in many internet stores), I find it necessary to discuss STM32 L432KC. This chip deserves special affection, as it is ULTRA LOW POWER. However, for those who do not own the STM32, it can be replaced in this project by the Arduino Uno. To do this, simply change the pin of the Interrupt input.

Let's then create an RPM meter using the STM32 L432KC and an infrared sensor. This same program can also be used to measure wind speed. The low-power feature of this microcontroller is perfect for IOT.

Modules

3.1.png
3.2.png

For our project today, we use the 8-digit MAX7219CWG, as well as the Infrared Module.

STM32 NUCLEO-L432KC

4.png

Demonstration

demo.png

In our assembly, we have the STM32, the 8-digit display, and the pulse input. The infrared card has a phototransistor and a LED that catches the light by bouncing off a white ribbon. This tape is attached to a wheel and, at each turn, will generate a pulse, which will be captured by the STM32 interrupt.

We have a diode and a capacitor in the assembly that were used to prevent the noise of the tape reading signal from reaching the STM32, which would make it interpret the on and off.

The demonstration shows our project, as well as the Minipa meter (both in operation).

Assembly

9.2.png

Program

We will do a program in which the infrared module will trigger an interrupt in the STM32 L432KC every "turn," and we will do the calculations to display the RPM on the display.

Libraries

11.png

Add the following "DigitLedDisplay" library.

Simply access "Sketch >> Include Libraries >> Manage Libraries ..."

Source Code

Libraries and Variables

Let's start the source code including the DigitLedDisplay library. We’ll show the display object. I set the interrupt pin, which will be 12. Also, I enter a volatile operator for both the RPM counter and time in order to avoid any collision problems.

/* Include DigitLedDisplay Library */
#include "DigitLedDisplay.h" /* Arduino Pin to Display Pin 7 to DIN, 6 to CS, 5 to CLK */ //DigitLedDisplay ld = DigitLedDisplay(7, 6, 5); //arduino DigitLedDisplay ld = DigitLedDisplay(4, 2, 3); //STM32 L432KC int pin = 12; //pino de interrupção (módulo IR) volatile unsigned int rpm; //contador de rpm volatile unsigned long timeold; //tempo

Setup

In the Setup, we configure the display operation, as well as configure the interruption as Rising.

void setup() {
Serial.begin(115200); /* Set the brightness min:1, max:15 */ ld.setBright(10); /* Set the digit count */ ld.setDigitLimit(8); ld.printDigit(0); attachInterrupt(digitalPinToInterrupt(pin), interruptPin, RISING); rpm = 0; timeold = millis(); }

Loop

Finally, we determine the interval of 1 in 1 minute to update the display. After cleaning the screen, we print the RPM. We perform the function that the interrupt will call. We calculate RPM and update time.

void loop() {
delay(1000); ld.clear(); ld.printDigit(rpm); } void interruptPin() { rpm = 60*1000/(millis() - timeold); timeold = millis(); }

Files

Download the files:

PDF

INO