Digitalzähler

Für etliche meiner Versuche (z.B. im Bereich Radioaktivität) benötige ich einen digitalen Zähler. Mit dem MAX7219 lässt sich ein solcher sehr einfach mit insgesamt 8 digits umsetzen. Gezählt werden die Spannungspulse (steigende Flanke) mittels interrupt. Mittels 5V-Zenerdiode wird der Arduino-Eingang geschützt.

Ich habe die Schnelligkeit des Zählers mittels Funktionsgenerator überprüft. Demnach können Signale mit einer Frequenz von bis zu 140 kHz erfasst werden.


Arduino-Code:

#include "LedControl.h"
// Arduino Pin 7 to DIN, 6 to Clk, 5 to CS, no.of devices is 1
#include <Wire.h>

LedControl lc=LedControl(7,6,5,1);

volatile long pulse = 0;
int stelle[8];
const int buttonPin = 9;
int buttonState = 0;
const byte interruptPin = 2;



void setup()
   {
    Serial.begin(9600);

    pinMode(interruptPin, INPUT_PULLUP);
    pinMode(buttonPin, INPUT);

    attachInterrupt(digitalPinToInterrupt(interruptPin), Puls, RISING);
    
    // Initialize the MAX7219 device
    lc.shutdown(0,false);   // Enable display
    lc.setIntensity(0,3);  // Set brightness level (0 is min, 15 is max). Format: address, intensity
    lc.clearDisplay(0);     // Clear display register
   }

void loop()
   {
    buttonState = digitalRead(buttonPin);

    if (buttonState == LOW)    // Reset-Knopf gedrückt
       {
        pulse = 0;
       }
    
    //pulse = 87654321;
 
    stelle[7] = (pulse%100000000)/10000000;  
    stelle[6] = (pulse%10000000)/1000000;
    stelle[5] = (pulse%1000000)/100000;
    stelle[4] = (pulse%100000)/10000;  
    stelle[3] = (pulse%10000)/1000;
    stelle[2] = (pulse%1000)/100;
    stelle[1] = (pulse%100)/10;
    stelle[0] = pulse%10;   

    for(int i=0; i<8; i++)
       {
        lc.setDigit(0,i,stelle[i],false);
       }  
    
    //delay(1000);
   }


// ==============================
// =======   INTERRUPT  =========
// ==============================

void Puls()
   {
    pulse = pulse + 1;
   }