Hi all,
I have this analog sensor: Xicoy Electronica SL
With this sensor I want to measure the rpm of a turbine, which can reach approximately 120k RPM.
I did some tests already and from these tests I concluded that the sensor only reads RPM-values until ~27000 RPM.
This is my Arduino code:
// --SETUP--
int hall_pin = 0; // Analog input pin sensor
int switch_max = 640; // Maximum value (incl. some safety margin)
int switch_min = 50; // Minimum value (incl. some safety margin)
int hall_thresh = 200; // Number of hall trips for RPM reading
// Variables in loop
float hall_count, hall_read, rpm_val, time_passed;
unsigned long start, end_time, cut_off_start, cut_off_end, RPM_motor;
bool maximum = false;
void setup() {
Serial.begin(9600);
// MOTOR RPM SETUP:
pinMode(hall_pin, INPUT);// Make the hall pin an input
}
void loop() {
// MOTOR RPM SETUP
hall_count = 0;
cut_off_start = millis();
start = micros();
// counting number of times the hall sensor is tripped
// but without double counting during the same trip
while(true){
hall_read = analogRead(hall_pin); // Current state of hall input
if (hall_read>=switch_max){
if (maximum == false){
maximum = true;
hall_count+=1; // Variable in loop for period counter
}
}
else if(hall_read<=switch_min){
maximum = false;
}
if (hall_count>=hall_thresh){
break;
}
cut_off_end = millis();
if (cut_off_end-cut_off_start >= 1000){
// If the counter time is bigger than 1 sec, the while loop will stop
break;
}
}
// information about Time and RPM
end_time = micros();
time_passed = ((end_time-start)/1000000.0);
rpm_val = (hall_count/time_passed)*60.0;
RPM_motor= (unsigned long) rpm_val;
}
}
Hopefully someone can help me further.
Thanks in advance!
Do you have the datasheet for the device?
Why is hall_count not an integer?
Why analogRead?
TheMemberFormerlyKnownAsAWOL:
Do you have the datasheet for the device?
Unfortunately, I do not have the datasheet for this sensor.
TheMemberFormerlyKnownAsAWOL:
Why is hall_count not an integer?
You are completely right on this, this should be an integer of course!
TheMemberFormerlyKnownAsAWOL:
Why analogRead?
I use analogRead to read the output value of the hall sensor. This results in a sinusoidal waveform, with a maximum value and a minimum value. I know that a rotation starts when the sinusoidal wave has a maximum value, the next time the value is maximum again I increase the hall_count by 1. However, I can imagine that this procedure is maybe to slow for RPM values higher than ~27000RPM. But, I am completely new to Arduino, so if someone has suggestions to improve this, do not hesitate to post them.
An analogRead() call takes about 110 µs, so up to just under 10,000 samples a second. That's pretty slow for a 2,000 Hz signal.
Is that hall effect sensor of yours fast enough to follow a 2000 Hz signal? (the datasheet will tell you how fast it reacts).
More sense makes a hall effect switch, which simply gives a digital high/low signal, much quicker & easier to sample. Also you don't need to count right at the start of a rotation; you just have to count rotations. You can probably use digitalRead() as well for your sensor, as long as the voltage goes over 3V (for a 5V Arduino) it will read as a logic HIGH, below 1.5V as a logic LOW.
wvmarle:
An analogRead() call takes about 110 µs, so up to just under 10,000 samples a second. That's pretty slow for a 2,000 Hz signal.
Is that hall effect sensor of yours fast enough to follow a 2000 Hz signal? (the datasheet will tell you how fast it reacts).
More sense makes a hall effect switch, which simply gives a digital high/low signal, much quicker & easier to sample. Also you don't need to count right at the start of a rotation; you just have to count rotations. You can probably use digitalRead() as well for your sensor, as long as the voltage goes over 3V (for a 5V Arduino) it will read as a logic HIGH, below 1.5V as a logic LOW.
Thank you for your response. First of all, the hall effect sensor unfortunately has no datasheet which tells me the reaction time. However, it is designed for this purpose, so I assume this would not be the problem.
I tried to use the sensor with digitalRead, and i see that especially when I rotate faster that the output voltage is high enough to read a logic HIGH. However, testing the setup by rotating just slowly (such that I can count the rotations myself) the output stays LOW. Can I conclude from this that connecting the sensor to the digital input will not work?
Note: in the attachment I added the exact application, to make to whole story more clear
hallsein.pdf (81.5 KB)
A link to the data sheet of your sensor would have been more useful.