Arduino Nano BLE 33

A couple of problems

NbTopsFan should be declared volatile

You need to turn off interrupts whilst doing the calculation using in loop() to prevent an interrupt occurring whilst the calculation using the multi byte variable takes place

If you haven't solved your issue yet, here is the datasheet for the nRF52840 SoC

> Bloco de Citação

If you want full control of the interruptions and peripherals actions, I suggest you read the datasheet. By importing the libraries <nrf.h> and <nrfx.h> you should be able to program the Arduino like any Nordic development platform.

First, do you have a pull up resistor on the signal line going to the interrupt pin? The hall sensor output typically is open collector switched to ground and requires a pull up. If the line is short, you can set the pin mode to INPUT_PULLUP and the internal resistance should be strong enough.

Second, while there are several issues with the code, as @UKHeliBob pointes out, but the most important to fix is to declare NbTopsFan as a volatile int.

As before, I have tested your code by jumpering an analogWrite() signal from pin 4 to pin 2. The pwm frequency on the Nano 33 BLE is 500Hz, so in the two second sampling period there are 1000 counts and a Q value of 1000/40 = 25. That is indeed what I see for Serial output. You most likely have a hardware issue.

int hallsensor= 2;        // PIN DIGITA
volatile int NbTopsFan;         // Nombre de tours d'hélices
float Calc;          // Calcul du volume
float Q;             // Calcul du débit
int tsampling = 2;

void rpm() {NbTopsFan++; }


void setup() {
  Serial.begin(9600);
  pinMode(hallsensor, INPUT_PULLUP); 
  attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING);
  analogWrite(4,32); //jumper pin 4 to pin 2  500Hz test Signal
  }
void loop() {
  NbTopsFan = 0;
  delay(1000 * tsampling);
  //Serial.println(digitalRead(hallsensor));
  Q = NbTopsFan/(20 * tsampling);
  Serial.println(Q);
  }

OUTPUT

07:15:17.700 -> 25.00
07:15:19.694 -> 25.00
07:15:21.689 -> 25.00
07:15:23.690 -> 25.00
07:15:25.681 -> 25.00
07:15:27.698 -> 25.00

I applied your solution it's workiiing great, thank youuu so so much.

I don't mean to annoy, but tell if you can help with a chronometer i am having a problem with?

I'm certain that this forum will be able to help. I suggest you start a new thread if the issue is unrelated to the rpm determination or previous BLE issues.

Okey I posted a topic, i hope someone can help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.