Faster frequency measurement

xhr0428:
Hi Mark,

I'm trying to use SN74LV8154 to count two sequences of pulses. It seems you are the only one using this chip in the forum. Do you still have the schematic? I don't know how I should connect the RCLK pin.

BTW, in another post, you mentioned "What you don't do is reset the counters - that will lose counts, you take successive readings from each counter and subtract the previous reading to get the new count." In that case what if the counter reaches its limit? Will it roll back to 0 automatically?

Thanks

Hello,

I doubt this is still an issue for you, given the age of this thread. But i also had some trouble reading the SN74LV8154 counter.

Got it to work eventualy and here is the code, hope it saves someone some time if they stuble upon this post.

#include "SPI.h";

bool done = false;

// Counter pins (SN74LV8154)
const int cclr = 8;
const int clka = 9;
const int gal = 7;
const int gau = 6;
const int gbl = 5;
const int gbu = 4;
const int rclk = 3;
// all other non-Y pins pulled to GND

// Shift register pins (SN74HC165)
const int shLd = 2;
const int clk = 13;  // not used in code, pre-defined SPI pin in arduino UNO/Nano for clock signal
const int qh = 12;   // not used in code, pre-defined SPI pin in arduino UNO/Nano for data
// all other A-H pins to output of counter Y0 -> A, Y1 -> B, Y2 -> C etc...

void setup() 
{
  // Counter pins
  pinMode(cclr, OUTPUT);
  pinMode(clka, OUTPUT);
  pinMode(gal, OUTPUT);
  pinMode(gau, OUTPUT);
  pinMode(gbl, OUTPUT);
  pinMode(gbu, OUTPUT);
  pinMode(rclk, OUTPUT);
  digitalWrite(gal, HIGH);
  digitalWrite(gau, HIGH);
  digitalWrite(gbl, HIGH);
  digitalWrite(gbu, HIGH);
  digitalWrite(cclr, LOW);
  digitalWrite(clka, LOW);
  digitalWrite(rclk, LOW);
  
  // Shift register pins (others are handled by SPI lib)
  pinMode(shLd, OUTPUT);
  
  Serial.begin(115200);
  SPI.begin();
}

void pulse(int pin, int value)
{
  digitalWrite(pin, value);
  digitalWrite(pin, !value);
}

void loop() 
{
  if(!done)
  {
    Serial.println("start");

    // Clear counter
    pulse(cclr, LOW);

    // Some test clock cycles, 513 = 10 00000001
    for(int i = 0; i < 513; i++)
    {
      pulse(clka, HIGH);
    }
    
    // Transfer data from the counter to the register
    pulse(rclk, HIGH);

    // NOTE: counter can continue counting now, it will not effect the value in the register

    // Read low byte of register A
    digitalWrite(gal, LOW);    // Set low byte of register A to outputs
    pulse(shLd, LOW);          // Sample outputs data with shift register
    byte bl = SPI.transfer(0); // Read data from shift register
    
    // Read upper byte of register A
    digitalWrite(gal, HIGH);   // Prevent invalid state, only one ga_ may be LOW at any given time
    digitalWrite(gau, LOW);    // Set upper byte of register A to outputs
    pulse(shLd, LOW);          // Sample outputs data with shift register
    byte bu = SPI.transfer(0); // Read data from shift register
    
    Serial.println(bl);  // should be 1
    Serial.println(bu);  // should be 2
    int val = (bu << 8) + bl;
    Serial.println(val);  // should be 513
    Serial.println("end");
    done = true;
  }
}