Does 328P can generate sync data signal?

Hello

I have a problem for sync signal.
I need generate 3 kind of signals, there are Sclk, Sload and Sdao.

1.Sclk is the 100Hhz clock, that can provide sync clock to device.

2.Sload is the start signal, inform device the data will begin transfer. Sload is pull high when Sclk in high edge and low in next high edge of Sclk.

3.Sdao is status data signal, there are 12 bits: 011011011011.output low or high status when Sclk in high edge.

After Sdao end of data output, then Sload send high signal again.

I know how to use pwm or i2c to output 100Khz clock, but no idea how to sync Sclk with Sload and Sdao.

This is the IBPI signal, does the 328p can do this?

Thanks.

IBPI == this or one of the other several FLA's google finds?

Hello Riva

Yes, the IBPI is the RAID card sgpio signal.
I would like to simulator RAID card sgpio signal to backplane to verify LED frequency of backplane without RAID card.

Any idea? Thanks.

I assume the 100Hz is a typo in bullet point 1 of your initial reply?
This should be achievable if you hit the ports directly and don't use digitalWrite().
You will need level shifters unless you use a 3.3V arduino (or compatible) as the SFF-8485 spec says 3.3V.
If you have a scope of logic analyser then have a go at generating the signal and see how it looks.

Hello Riva

Sorry , The Sclk frequency is 100Khz not 100Hz, this is my mistake.

I has tried to use digitalWrite Low/High to simulate Sclk/Sload/Sdao (frequency is 67KHz max, duty cycle not 50%), there have one backplane can recognize Sclk/Sload/Sdao signal and work fine, it is very amazing, but there is very stupid.

have any suggest?

thanks,

Where is the code you have tried so we can see what your doing and how it can be improved.

Hello~ Rive

here is my sketch, but it is very…very stupid.

Sclk, Sload ,Sdo signals, you can refer to note : 1st 011 , 2nd 011 , 3rd 011, 4th 011

thank.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);

// external interrupt------------
const int interruptNumber = 0;
const int button = 2; 
volatile int buttonState;
//-----------------------

#define CLK 5  // <<<< define Sclk
#define SLOAD 3  // <<<< define SLOAD
#define SDO 4  /// <<<< define SDO
// #define button 0

// -------- Backplane LED frequency detect 
#define FAIL_PIN1 8
#define FAIL_PIN2 10
#define FAIL_PIN3 11
#define FAIL_PIN4 13
#define READ_DELAY 10


//  ------------------------------
static double duty;
static double freq1;
//static double FANspeed;
static long highTime = 0;
static long lowTime = 0;
static long tempPulse;
static long lastSeen;
// ---------------------------------------



void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print(" SGPIO LED TEST ");
  delay (2000);
  
  pinMode(button,INPUT);
  attachInterrupt(interruptNumber, buttonStateChanged, CHANGE); // seting interrupt mode to change
  
  // read backplane LED singal
  pinMode(FAIL_PIN1,INPUT);
  pinMode(FAIL_PIN2,INPUT);
  pinMode(FAIL_PIN3,INPUT);
  pinMode(FAIL_PIN4,INPUT);
  
  // IPBI signal output
  pinMode(CLK, OUTPUT);  
  pinMode(SLOAD, OUTPUT);  
  pinMode(SDO, OUTPUT);
  
 //  initialize IPBI signal to low when power on
  digitalWrite(CLK,LOW);
  digitalWrite(SLOAD,LOW);
  digitalWrite(SDO,LOW);
  pinMode(button, INPUT);           // set pin to input
  digitalWrite(button, HIGH);       // turn on pullup resistors
  
}


void loop() {
lcd.clear();
 
  
// start read backplane LED signal , there have four signal from backplane

readPWM(FAIL_PIN1);
  lcd.setCursor(0,0);
  lcd.print("FQ1=");
  lcd.print(freq1);
  //lcd.print(" Hz");
  lcd.setCursor(10,0);
  lcd.print(" DT=");
  lcd.print(duty);
  //lcd.print(" %");


  readPWM(FAIL_PIN2);
  lcd.setCursor(0,1);
  lcd.print("FQ2=");
  lcd.print(freq1);
  //lcd.print(" Hz");
  lcd.setCursor(10,1);
  lcd.print(" DT=");
  lcd.print(duty);
  //lcd.print(" %");


  readPWM(FAIL_PIN3);
  lcd.setCursor(0,2);
  lcd.print("FQ3=");
  lcd.print(freq1);
  //lcd.print(" Hz");
  lcd.setCursor(10,2);
  lcd.print(" DT=");
  lcd.print(duty);
  //lcd.print(" %");


  readPWM(FAIL_PIN4);
  lcd.setCursor(0,3);
  lcd.print("FQ4=");
  lcd.print(freq1);
  //lcd.print(" Hz");
  lcd.setCursor(10,3);
  lcd.print(" DT=");
  lcd.print(duty);
  //lcd.print(" %");
  delay (800);


}
// ----------------------Delay  //
void freq()
{
    delayMicroseconds(100);
}
//----------------------------
// ----------------------Delay  //



// SDO 011 rebuild //
void rebuild()
{
  
  //START SLOAD BIT
  freq();
  digitalWrite(CLK,HIGH);
  digitalWrite(SLOAD,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);
  digitalWrite(SLOAD,LOW);
  // END SLOAD
  // -----------------1st SD0 011
  digitalWrite(SDO,LOW); [color=red]// SDO 1st 0[/color]
  freq(); 
  digitalWrite(CLK,LOW);
 
  
  freq();
  digitalWrite(CLK,HIGH);
  digitalWrite(SDO,HIGH); 
  freq();
  digitalWrite(CLK,LOW);
  
  
  freq();
  digitalWrite(CLK,HIGH);
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  
//-------------------- [color=red]2nd 011[/color]
freq();
  digitalWrite(CLK,HIGH);//SDO 2nd 0
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 2nd 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 1st 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  
// -------------- [color=red]3rd 011  [/color]
  freq();
  digitalWrite(CLK,HIGH);//SDO 3rd 0
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 3rd 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 3rd 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  freq();
  
  // --------------[color=red] 4th 011[/color]  
  digitalWrite(CLK,HIGH);//SDO 4th 0
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 4th 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 4th 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
}
  
// ------- Locate   副程式 -----------------
void locate()
{
  
  //START SLOAD BIT
  freq();
  digitalWrite(CLK,HIGH);
  digitalWrite(SLOAD,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);
  digitalWrite(SLOAD,LOW);
  // END SLOAD
  // -----------------1st SD0 011
  digitalWrite(SDO,LOW); // SDO 1st 0
  freq(); 
  digitalWrite(CLK,LOW);
 
  
  freq();
  digitalWrite(CLK,HIGH);
  digitalWrite(SDO,HIGH); 
  freq();
  digitalWrite(CLK,LOW);
  
  
  freq();
  digitalWrite(CLK,HIGH);
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  
  
//-------------------- 2nd 011
freq();
  digitalWrite(CLK,HIGH);//SDO 2nd 0
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 2nd 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 1st 1
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  
  
// -------------- 3rd 011  
  freq();
  digitalWrite(CLK,HIGH);//SDO 3rd 0
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 3rd 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 3rd 1
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  freq();
  
  // -------------- 4th 011  
  digitalWrite(CLK,HIGH);//SDO 4th 0
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 4th 1
  digitalWrite(SDO,HIGH);
  freq();
  digitalWrite(CLK,LOW);
  
  freq();
  digitalWrite(CLK,HIGH);//SDO 4th 1
  digitalWrite(SDO,LOW);
  freq();
  digitalWrite(CLK,LOW);
}
  
  
// ---------------------------------------------
//Takes in reading pins and outputs pwm frequency and duty cycle.
void readPWM(int readPin)
{
  highTime = 0;
  lowTime = 0;
  lastSeen = millis();
  while((millis()-lastSeen)<READ_DELAY)
  {
    tempPulse = pulseIn(readPin,HIGH,2000000);

    if(tempPulse>highTime){
      highTime = tempPulse;
    }
  }
  lastSeen = millis();
  while((millis()-lastSeen)<READ_DELAY)
  {
    tempPulse = pulseIn(readPin,LOW,2000000);

    if(tempPulse>lowTime){
      lowTime = tempPulse;
    }
  }
  freq1 = ((double) 1000000)/(double (lowTime+highTime));
  duty = (100*(highTime/(double (lowTime+highTime))));

}

  
  

void buttonStateChanged() {
buttonState = digitalRead(button);
if (buttonState == HIGH) {locate();} else {rebuild();}


}

Any one have good idea? I can try any thing, thanks.

Suggest you go to blink without delay style code.
This nearly 1 second delay:

delay (800);

can't be good for performance.

Also, all the digitalWrites take time.
You can convert those all to direct port manipulation for much better speed.
Say you wanted to write the CLK pin high & low, and it is on PortD, bit 5:
To make it high without changing anything else:
PORTD = PORTD | 0b00100000; // bit 5 high

and for low:
PORTD = PORTD & 0b11011111; // bit 5 low

leave your pinMode settings as they are.

Hello~ CrossRoads

thank for your help, but I tried to use your suggestion, if I only controll PORTD, the high/low frequence can higher to 200Khz.

But when I add "lcd.clear() , the PORTD bit5 output is not sequence(reference to attachment), then I add readPWM(FAIL_PINx), the PORTD bit5 is no output any signal.

I guess there is command delay to causing this issue.

The total function:
328P generate and output Sclk, Sload, Sdao signal to inform backplane then read LED frequency from backplane and display frequency on 20*4 LCM.

Have any suggest?

I had reduced the sketch, the sketch function only have Sclk, Sload, Sdao, there are use PORTD, but now have 2 issues occur:

  1. Sclk(pin5) has a delay time, when rebuid() (subroutine) retuen to loop().
  2. Sclk(pin5) has a unknow delay about 7 Sload clock.
    please reference attachment file.

I know this sketch is not well, but I don’t know how to SYNC these signal, how can I improve the sketch?

#define CLK 5  // <<<< define Sclk
#define SLOAD 4  // <<<< define SLOAD
#define SDO 3  /// <<<< define SDO

void setup() {


  // IPBI signal output
  pinMode(CLK, OUTPUT);  
  pinMode(SLOAD, OUTPUT);  
  pinMode(SDO, OUTPUT);

  //  initialize IPBI signal to low when power on
  PORTD = PORTD | 0b00000000;

}


void loop() {

  rebuild();
}



// ----------------------Delay start //
void freq() 
{ 
  delayMicroseconds(5); 
}
// ----------------------Delay end //



// SDO 011 rebuild //
void rebuild()
{

  //START SLOAD BIT AND 1st 011
  freq();
  PORTD =  0b00110000;  // clk=H , SLOAD=H 
  freq();
  PORTD =  0b00010000 ; // clk=L , SLOAD=H

  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=L(0)
  freq(); 
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=L(0)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)



  //-------------------- 2nd 011
  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=L(0)
  freq(); 
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=L(0)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  //-----------------------------3rd 011
  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=L(0)
  freq(); 
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=L(0)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  // --------------------4th 011
  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=L(0)
  freq(); 
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=L(0)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)
}

// ------- Locate   副程式  010-----------------
void locate()
{
  //START SLOAD BIT AND 1st 010
  freq();
  PORTD = 0b00110000;  // clk=H , SLOAD=H 
  freq();
  PORTD = 0b00010000 ; // clk=L , SLOAD=H

  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=L(0)
  freq(); 
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=L(0)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=H(0) 
  freq();
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=H(0)



  //-------------------- 2nd 010
  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=L(0)
  freq(); 
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=L(0)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=H(0) 
  freq();
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=H(0)

  //-----------------------------3rd 010
  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=L(0)
  freq(); 
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=L(0)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=H(0) 
  freq();
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=H(0)

  // --------------------4th 010
  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=L(0)
  freq(); 
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=L(0)

  freq();
  PORTD =  0b00101000 ; // clk=H , SLOAD=L , SD0=H(1) 
  freq();
  PORTD =  0b00001000 ; // clk=L , SLOAD=L , SD0=H(1)

  freq();
  PORTD =  0b00100000 ; // clk=H , SLOAD=L , SD0=H(0) 
  freq();
  PORTD =  0b00000000 ; // clk=L , SLOAD=L , SD0=H(0)

}

Sorry for the late reply. This post must have moved of the first page on the forum.

Alas I’m at work now so cannot test/check my code but try the below and see how you get on.
You will need to adjust CLK_SPEED and maybe the Timer pre-scale to suit your needs.

#include <avr/interrupt.h>   

// defines for setting and clearing register bits
#ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

// Timer2 clock speed (the lower the slower)
#define CLK_SPEED 100  
#define sampleCount 12                                      // 12 bits to clock out

#define SClock 8                                            // Clock pin (TIMER2 will need changing if you move this pin. PB0)
#define SLoad 9                                             // SLoad (TIMER2 will need changing if you move this pin. PB1)
#define SDataOut 10                                         // SDataOut (TIMER2 will need changing if you move this pin. PB2)

unsigned int samplePos = 0;                                 // Used by ISR to track sample bit position
unsigned int sampleData = 0xDB6;                            // Data to clock out in reverse order (0xDB6 = 110110110110)

//Timer2 overflow interrupt vector handler
ISR(TIMER2_OVF_vect) {
  //reset timer
  TCNT2 = CLK_SPEED;                                        // Reload timer
  if (PINB & _BV(0)) {                                      // Is CLK pin currently high or low?
    cbi(PORTB,0);                                           // High so set CLK pin LOW
  }
  else 
  {
    sbi(PORTB,0);                                           // Low so set CLK pin HIGH
    
    if (samplePos == 0){                                    // First bit?
      cbi(PORTB,1);                                         // Clear SLoad
    }
    if (sampleData | ( 1 << samplePos) == 0){
      cbi(PORTB,2);                                         // Clear SDataOut
    }
    else
    {
      sbi(PORTB,2);                                         // Set SDataOut
    }
    samplePos++;                                            // Increment pointer
    if (samplePos >= sampleCount - 1) {                     // Last bit?
      sbi(PORTB,1);                                         // Set SLoad
      samplePos = 0;                                        // Reset pointer
    }
  }
  cbi(TIFR2,TOV2);                                          // Clear TIMER2 overflow interrupt flag
};  

void setup() {
  Serial.begin(115200);                                     // Fast serial
  pinMode(SClock,OUTPUT);                                   // Clock
  pinMode(SLoad,OUTPUT);                                    // SLoad
  pinMode(SDataOut,OUTPUT);                                 // SDataOut
  
  //Timer2 Settings: Timer Prescaler /8
  TCCR2A = 0;                                               // Timer2 Settings: WGM mode 0
  cbi(TCCR2B,CS20);                                         // Turn off CS20 bit
  sbi(TCCR2B,CS21);                                         // Turn on CS21 bit
  cbi(TCCR2B,CS22);                                         // Turn off CS22 bit
  sbi(TIMSK2,TOIE2);                                        // Timer2 Overflow Interrupt Enable   
  TCNT2 = CLK_SPEED;                                        // Reset timer
  
  delay(500);                                               // Allow things to settle
}

void loop() {
}

Hello~ Riva

I will try new setch and update result after test .

thanks for your help.

Hello~ Riva

update test result.

The Sclk frequency is 6.3Khz, Sdao(pin10) no signal output.

attachment files for your reference.

thanks.

Hi knee266,

Am off work today and just started debugging the code. As stated above the code was not tested and now I have a logic analyser on it I can instantly see a couple of bugs. I will do further testing then get back to you.

EDIT
Testing over and below is the best I can do.
There were a couple of errors in the first code. First I had used | (or) instead of & (and) so no data was clocked out and second the last bit check I had got wrong so only 11 bits sent instead of 12.
I have added a couple of lines of code to test how long I’m in the ISR for (CH4 on the image) and from this have altered the timer prescale from /8 to /1 so it runs faster (42.463KHz) but the problem may be that you don’t have time to do much else in loop().

#include <avr/interrupt.h>   

// defines for setting and clearing register bits
#ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

// Timer2 clock speed (the lower the slower)
#define CLK_SPEED 100                                       // 100 = 42.463KHz  
#define sampleCount 12                                      // 12 bits to clock out

#define SClock 8                                            // Clock pin (TIMER2 will need changing if you move this pin. PB0)
#define SLoad 9                                             // SLoad (TIMER2 will need changing if you move this pin. PB1)
#define SDataOut 10                                         // SDataOut (TIMER2 will need changing if you move this pin. PB2)

unsigned int samplePos = 0;                                 // Used by ISR to track sample bit position
unsigned int sampleData = 0xDB6;                            // Data to clock out in reverse order (0xDB6 = 110110110110)

//Timer2 overflow interrupt vector handler
ISR(TIMER2_OVF_vect) {
  sbi(PORTB,5);                                             // Test signal
  //reset timer
  TCNT2 = CLK_SPEED;                                        // Reload timer
  if (PINB & _BV(0)) {                                      // Is CLK pin currently high or low?
    cbi(PORTB,0);                                           // High so set CLK pin LOW
  }
  else 
  {
    sbi(PORTB,0);                                           // Low so set CLK pin HIGH
    
    if (samplePos == 0){                                    // First bit?
      cbi(PORTB,1);                                         // Clear SLoad
    }
    if (sampleData & ( 1 << samplePos)){
      sbi(PORTB,2);                                         // Clear SDataOut
    }
    else
    {
      cbi(PORTB,2);                                         // Set SDataOut
    }
    samplePos++;                                            // Increment pointer
    if (samplePos >= sampleCount) {                         // Last bit?
      sbi(PORTB,1);                                         // Set SLoad
      samplePos = 0;                                        // Reset pointer
    }
  }
  cbi(TIFR2,TOV2);                                          // Clear TIMER2 overflow interrupt flag
  cbi(PORTB,5);                                             // Test signal
};  

void setup() {
  Serial.begin(115200);                                     // Fast serial
  pinMode(13,OUTPUT);                                       // For test signal
  pinMode(SClock,OUTPUT);                                   // Clock
  pinMode(SLoad,OUTPUT);                                    // SLoad
  pinMode(SDataOut,OUTPUT);                                 // SDataOut
  
  //Timer2 Settings: Timer Prescaler /1
  TCCR2A = 0;                                               // Timer2 Settings: WGM mode 0
  sbi(TCCR2B,CS20);                                         // Turn on CS20 bit
  cbi(TCCR2B,CS21);                                         // Turn off CS21 bit
  cbi(TCCR2B,CS22);                                         // Turn off CS22 bit
  sbi(TIMSK2,TOIE2);                                        // Timer2 Overflow Interrupt Enable   
  TCNT2 = CLK_SPEED;                                        // Reset timer
  
  delay(500);                                               // Allow things to settle
}

void loop() {
}

Hello~ Riva

Sorry for late , I prepare a business vacation lately, I will test your sketch soon.
thanks for your help.

update:

after sketch test, the function is ok, but you are right, there is no CPU time to do loop();
I decided to use 328P x2pcs , one for SGPIO signal another for frequency display.
thank you very much.