Simple Arduino Pulse Rate Counter
- Sesselmann
- Posts: 1378
- Joined: 27 Apr 2015, 11:40
- Location: Sydney
- Contact:
Simple Arduino Pulse Rate Counter
Hi Guys,
Some of you might be interested in this project..
I'm sending one of my Neutron detectors over to ANSTO (Australian Nuclear Science and Technology Organisation) for calibration and so they don't have to mess around with sound card software (my guess is they are hardcore NIM people), I quickly made up a simple Arduino C.P.M. rate meter or scaler.
The whole thing only cost me around $25 to make . I spent a few hours figuring out how to code it in java, and with a bit of help from my son Tom, it didn't take long to get it working.
Basically it's an Arduino UNO with a 7 segment 8 digit display, a 9V battery and a 3D printed enclosure, just connect the pulse signal to the BNC and turn it on to get counts per minute. The program sums counts per second over 30 seconds and doubles it, so you get the running average.
I can post the code if anyone is interested, but I'm sure it can be improved.
Steven
Some of you might be interested in this project..
I'm sending one of my Neutron detectors over to ANSTO (Australian Nuclear Science and Technology Organisation) for calibration and so they don't have to mess around with sound card software (my guess is they are hardcore NIM people), I quickly made up a simple Arduino C.P.M. rate meter or scaler.
The whole thing only cost me around $25 to make . I spent a few hours figuring out how to code it in java, and with a bit of help from my son Tom, it didn't take long to get it working.
Basically it's an Arduino UNO with a 7 segment 8 digit display, a 9V battery and a 3D printed enclosure, just connect the pulse signal to the BNC and turn it on to get counts per minute. The program sums counts per second over 30 seconds and doubles it, so you get the running average.
I can post the code if anyone is interested, but I'm sure it can be improved.
Steven
Steven Sesselmann | Sydney | Australia | https://gammaspectacular.com | https://beejewel.com.au | https://www.researchgate.net/profile/Steven-Sesselmann
Re: Simple Arduino Pulse Rate Counter
Nice little counter indeed. Isn't the Arduino coded with some modified C++?
Svilen
- Sesselmann
- Posts: 1378
- Joined: 27 Apr 2015, 11:40
- Location: Sydney
- Contact:
Re: Simple Arduino Pulse Rate Counter
Svilen,
The Arduino coding language is a form of Java, you download the free editor and it comes with a stack of examples that you can open and modify for your own purpose.
When you add on devices such as displays, you need to import a "Library" which is basically just some hidden code specific to that device.
Even if you know nothing about code you should be able to learn it in a few days.
https://www.arduino.cc/en/main/software
Steven
The Arduino coding language is a form of Java, you download the free editor and it comes with a stack of examples that you can open and modify for your own purpose.
When you add on devices such as displays, you need to import a "Library" which is basically just some hidden code specific to that device.
Even if you know nothing about code you should be able to learn it in a few days.
https://www.arduino.cc/en/main/software
Steven
Steven Sesselmann | Sydney | Australia | https://gammaspectacular.com | https://beejewel.com.au | https://www.researchgate.net/profile/Steven-Sesselmann
Re: Simple Arduino Pulse Rate Counter
Yes, I know that about it, but thought the language is based on C not Java. Thanks Steven.
Svilen
- Sesselmann
- Posts: 1378
- Joined: 27 Apr 2015, 11:40
- Location: Sydney
- Contact:
Re: Simple Arduino Pulse Rate Counter
There seems to be some confusion as to weather it is java or C++
Here is my simple program, so maybe some hyper-polyglot can identify it :D
Steven
Here is my simple program, so maybe some hyper-polyglot can identify it :D
Steven
Code: Select all
*/ this code is obsolete, see further down the thread
Steven Sesselmann | Sydney | Australia | https://gammaspectacular.com | https://beejewel.com.au | https://www.researchgate.net/profile/Steven-Sesselmann
Re: Simple Arduino Pulse Rate Counter
Hi Steven,
Maybe you can use something like this, to shorten the summing of all these array elements:
Maybe you can use something like this, to shorten the summing of all these array elements:
Code: Select all
for(i=0; i<30; i++)
{
sum = sum + cps[i];
}Svilen
- Sesselmann
- Posts: 1378
- Joined: 27 Apr 2015, 11:40
- Location: Sydney
- Contact:
Re: Simple Arduino Pulse Rate Counter
Svilen,
Thanks, that's exactly what I wanted but didn't know exactly how to do it.
This will also allow me to add a mode button, for changing the integration time.
So in the end what do we call it, java or C++ ?
Steven
Thanks, that's exactly what I wanted but didn't know exactly how to do it.
This will also allow me to add a mode button, for changing the integration time.
So in the end what do we call it, java or C++ ?
Steven
Steven Sesselmann | Sydney | Australia | https://gammaspectacular.com | https://beejewel.com.au | https://www.researchgate.net/profile/Steven-Sesselmann
Re: Simple Arduino Pulse Rate Counter
I think just Arduinos's C++ syntax is extremly similar with Java's, and maybe therefore the confusion. But it is C++, even the first line of your program imports a C-header file that contains C function declarations ;) I'm not an expert, but I guess a JVM will also fill Arduino's memory several times.
Svilen
Re: Simple Arduino Pulse Rate Counter
It's a subset of C++. There are different boards though, I guess you are using the most common one (Arduino Uno). It has an 8-bit Atmega MCU and is actually rather limited in terms of resources, memory included. Not sure if there exists a JVM for that. But there are other arduino boards that have a "real" 32-bit CPU like cortex-m0 or esp32 and more memory. They should be perfectly capable to run a JVM.
Regards,
Milen Rangelov
Milen Rangelov
- Sesselmann
- Posts: 1378
- Joined: 27 Apr 2015, 11:40
- Location: Sydney
- Contact:
Re: Simple Arduino Pulse Rate Counter
Svilen,
I ran into a few issues with your suggestion for the array, but I think Tom and I have found a relatively elegant and fast solution. I tested it up to 30,000 cpm without any issues.
This code runs on Arduino Uno with 8 digit 7 segment display with MAX7219 chip.
Steven
I ran into a few issues with your suggestion for the array, but I think Tom and I have found a relatively elegant and fast solution. I tested it up to 30,000 cpm without any issues.
This code runs on Arduino Uno with 8 digit 7 segment display with MAX7219 chip.
Steven
Code: Select all
#include "DigitLedDisplay.h" // Library for 7 segment display
#define GPIO2_PREFER_SPEED 1 //who knows what this is ?
#include <DIO2.h> // include the fast I/O 2 functions
DigitLedDisplay ld = DigitLedDisplay(7, 6, 5); // connect to pins DIN-7, CS-6, CLK-5
const int pin2 = 2; //define input pin to be 2
const int buzz = A5; //optional analog output for buzzer
const int t = 30; //define count integral in seconds
unsigned long secondCounter = 0; //define variable
unsigned long counts = 0; //define variable
void test_inputs_pullup(void); //god only knows what this does?
void test_inputs_no_pullup(void); //god only knows what this does?
void pulse (){counts = counts + 1;} //calculation adds 1 to counts on pulse
int countArray[t]; //define array size to be t
int cpm = 0; //define counts per minute
void setup() {
ld.setBright(10); //set display brightness
ld.setDigitLimit(8); //define number of digits on display
Serial.begin(9600); //start serial connection
pinMode(pin2, INPUT); //initialize input
attachInterrupt(digitalPinToInterrupt(2), pulse, RISING); //who knows?
ld.printDigit(0); //just so the disp;lay light up at start
analogWrite(buzz, 1023); //buzzer on start
delay(100); //buzzer sounds for 100 ms
analogWrite(buzz, 0); //buzzer stops
}
void loop() {
if ( millis() > ((secondCounter + 1) * 1000) ) { //counts seconds from start
countArray[secondCounter % t] = counts; //puts last seconds counts into array
counts = 0; // resets counts
secondCounter++; // increases secondCounter by 1.
int arraySum = 0; //define variable
int arraySize = min(secondCounter, t); //only relevant at startup
for (int i = 0; i < arraySize; i++) {
arraySum += countArray[i]; // sum counts in array.
}
cpm = arraySum * 60/t;
ld.clear(); //clear led display
ld.printDigit(cpm); //print average to led display
}
}Steven Sesselmann | Sydney | Australia | https://gammaspectacular.com | https://beejewel.com.au | https://www.researchgate.net/profile/Steven-Sesselmann
Who is online
Users browsing this forum: No registered users and 33 guests