RST pin action - code cleanup

Hi folks!

I'm a newbie here, and need your help for my very first sketch.
I need some configuration pins to have an action,
and a reset pin that is set OFF by default (HIGH).

Each time the configuration takes place, the RST pin should be active (LOW),
when configuration done, it should return and remain OFF (HIGH).

All pins work perfectly, and stay fixed in their condition,
except for the RST pin, where I get a pulsed waveform.

I know there is a simple fix for this.
Can you help me?

Thanks in advance.

// PA
// Default state 44.1, RST off (HIGH)
// First touch: 48
// Second touch: 88.2
// Third touch: led 96
// Fourth touch: led 176.4

const int  LEDA = 13;       // LED A connected to digital pin 13, 44.1kHz
const int  LEDB = 12;         // LED B digipin 12,        48  kHz
const int  LEDC = 11;         // LED C digital pin 11:    88.2kHz
const int  LEDD = 10;       // LED D Digital Pin 10       96  kHz
const int  LEDE = 9;          // LED E digital pin 9      176.4kHz
const int  LEDF = 8;          // LED pin digitale 8       192.0kHz

//MasterClock select
const int YA = 7;         //Y1 digital pin 7 (PD7)    22.5792MHz
const int YB = 6;         //Y2 digital Pin 6 (PD6)    24.576 MHz

//button input and reset
const int BUTTON = 5;   // Button connected to Input DigitalPin 5 PD5
const int RST = 2;      //Reset control digital pin 2, PD2

const int fsA = 4;       //FS0 digitalPin 4         PD4
const int fsB = 3;      //FS1 pin digitale 3        PD3
const int HWCK0 = 0;    //HWCK0 Digital Pin 0       PD0
const int HWCK1 = 1;    //HWCK1 Digital Pin 1       PD1

/* 
 * Global variables (all integers) 
 */
int statoButton     = 0;      // button state (initially not depressed)
int lastStatoButton = 0;      // last state of the button (actually not depressed)
int countButton     = 0;      // Button Count

// App start
void setup()
{
  pinMode(LEDA, OUTPUT);       // sets the digital pin as an output
  pinMode(LEDB, OUTPUT);
  pinMode(LEDC, OUTPUT);
  pinMode(LEDD, OUTPUT);
  pinMode(LEDE, OUTPUT);
  pinMode(LEDF, OUTPUT);
  pinMode(YA, OUTPUT);
  pinMode(YB, OUTPUT);
  pinMode(RST, OUTPUT);
  pinMode(fsA, OUTPUT);
  pinMode(fsB, OUTPUT);
  pinMode(HWCK0, OUTPUT);
  pinMode(HWCK1, OUTPUT);
  pinMode(RST, OUTPUT);
  
  pinMode(BUTTON, INPUT);     // sets the digital pin as an input
 
}

// Loop start 
void loop()
{
   
  // Verify if user has depressed the button
  if(digitalRead(BUTTON))
  {
    // Wait for 250ms to let the finger release
    delay(250);
    // Change the last state of the button
    if(lastStatoButton==0) lastStatoButton=1;
    else lastStatoButton=0;
    // Increase button count
    if(countButton<=5) countButton=countButton+1;
    else countButton=0;
  }

  // Based on button state choose the action
  switch (countButton)
  {
    // 48 kHz
  case 1:
    digitalWrite(RST, HIGH);     // reset in default state
    digitalWrite(LEDA, LOW);
    digitalWrite(LEDB, HIGH);   // LED 48 on
    digitalWrite(fsA, LOW);     //  FS0 = 0
    digitalWrite(fsB, LOW);     //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, HIGH);  //HWCK1 = 1
    digitalWrite(YA, LOW);    
    digitalWrite(YB, HIGH);     // 24.576MHz MCK active
    break;

    // 88.2 kHz double speed mode
  case 2:
    digitalWrite(RST, HIGH);   // reset off
    digitalWrite(LEDB, LOW);  // off LED     48
    digitalWrite(LEDC, HIGH); // on LED 88.2
    digitalWrite(fsA, HIGH);   //  FS0 = 1
    digitalWrite(fsB, LOW);    //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, HIGH);    // 22.5792 On
    digitalWrite(YB, LOW);     //off 24.576MHz MCK
    break;

    // 96 kHz double speed mode
  case 3:
    digitalWrite(RST, HIGH);   //off reset
    digitalWrite(LEDC, LOW);  // off il LED 88.2
    digitalWrite(LEDD, HIGH); // on LED 96
    digitalWrite(fsA, HIGH);   //  FS0 = 1
    digitalWrite(fsB, LOW);    //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, LOW);    // 22.5792 Off
    digitalWrite(YB, HIGH);   // on 24.576MHz MCK
    //delay(500);              // wait for a second
    break;

    // 176.4 kHz quad speed mode
  case 4:
    digitalWrite(RST, HIGH);   // off reset
    digitalWrite(LEDD, LOW);   // off LED 96 
    digitalWrite(LEDE, HIGH);  //on LED 176.4
    digitalWrite(fsA, LOW);     //  FS0 = 0
    digitalWrite(fsB, HIGH);    //  FS1 = 1
    digitalWrite(HWCK0, HIGH);  //HWCK0 = 1
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, HIGH);    // 22.5792 On
    digitalWrite(YB, LOW);     // off 24.576MHz MCK
    //delay(500);              // wait for a second
    break;

    // 192 kHz quad speed mode
  case 5:             
    digitalWrite(RST, HIGH);
    digitalWrite(LEDE, LOW);  // off LED 176.4 
    digitalWrite(LEDF, HIGH); // on LED 192
    digitalWrite(fsA, LOW);   //  FS0 = 0
    digitalWrite(fsB, HIGH);  //  FS1 = 1
    digitalWrite(HWCK0, HIGH);  //HWCK0 = 1
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, LOW);    // 22.5792 Off
    digitalWrite(YB, HIGH);     // on 24.576MHz MCK
    //delay(500);              // wait for a second
    break;

    // 44.1 kHz
  case 0:
    digitalWrite(RST, HIGH);
    digitalWrite(LEDF, LOW);    // off LED 176.4
    digitalWrite(LEDA, HIGH);  // on LED 44.1
    digitalWrite(fsA, LOW);   //  FS0 = 0
    digitalWrite(fsB, LOW);   //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, HIGH);  //HWCK1 = 1
    digitalWrite(YA, HIGH);    // 22.5792 MCK ON
    digitalWrite(YB, LOW);     //off 24.576MHz MCK
    digitalWrite(RST, LOW);     //reset on
    delay(500);
    digitalWrite(RST, HIGH);    //reset off
    break;

  }
}

The only place that that pin's getting set low is in case 0 - if it hasn't read a button, it will be driving RST low, then briefly releasing it and then reasserting it. Is that the behavior you're expecting?

Also - I assume that RST pin is the reset pin on some other device you're interfacing with, right? You're not connecting that to the Arduino's reset pin to generate a software reset, or something are you? That doesn't work, and the datasheet specifically warns against it... (we get a lot of posts from people who want to do that)

This doesn't do what the comments imply you're trying to do.

  if(digitalRead(BUTTON))
  {
    // Wait for 250ms to let the finger release
    delay(250);
    // Change the last state of the button
    if(lastStatoButton==0) lastStatoButton=1;
    else lastStatoButton=0;
    // Increase button count
    if(countButton<=5) countButton=countButton+1;
    else countButton=0;
  }

Is the button wired correctly, for that matter? ie, do you have a pulldown resistor on it? If you don't, it will randomly register presses when it's not pressed, because the input side will be floating. (what most people do, and what's recommended, for buttons - you put the pinMode to INPUT_PULLUP, and then connect the other side of the button to ground, so the pin reads 0 when pressed and 1 when not pressed, and you don't need an external resistor). There's a lot of information about using buttons properly.

Hi DrAzzy,

Thanks for the quick reply!
I was lazy to recopy the code, that is why the RST is only on case 0,
but either way it doesn't work.
All the other pins behave correctly, and remain in their state.
RST is pulsed (the only one!!!)

and yes it resets hardware.
So waht would be the correct way to do it?

what I'm trying to achieve, the RST resets the hardware as long as the configuration takes places,
at default (case 0) or each time I press the button.

FWIW the button is connected from +5V and through a 10K pulldown to GND.
It works fine for all the configuration tasks.

The only thing that doesn't work is the RST pin as I intend it to work.
It must always stay HIGH (OFF), and go LOW (ON) when the configuration pins go in their intended state.

Do you have any suggestion, or code change?

TIA.

DrAzzy:
The only place that that pin's getting set low is in case 0 - if it hasn't read a button, it will be driving RST low, then briefly releasing it and then reasserting it. Is that the behavior you're expecting?

Also - I assume that RST pin is the reset pin on some other device you're interfacing with, right? You're not connecting that to the Arduino's reset pin to generate a software reset, or something are you? That doesn't work, and the datasheet specifically warns against it... (we get a lot of posts from people who want to do that)

This doesn't do what the comments imply you're trying to do.

  if(digitalRead(BUTTON))

{
    // Wait for 250ms to let the finger release
    delay(250);
    // Change the last state of the button
    if(lastStatoButton==0) lastStatoButton=1;
    else lastStatoButton=0;
    // Increase button count
    if(countButton<=5) countButton=countButton+1;
    else countButton=0;
  }




Is the button wired correctly, for that matter? ie, do you have a pulldown resistor on it? If you don't, it will randomly register presses when it's not pressed, because the input side will be floating. (what most people do, and what's recommended, for buttons - you put the pinMode to INPUT_PULLUP, and then connect the other side of the button to ground, so the pin reads 0 when pressed and 1 when not pressed, and you don't need an external resistor). There's a lot of information about using buttons properly.

So pin 2 (RST) is connected to the reset pin on the Arduino, or is it connected to the reset pin of another device?

If it's connected to another device, that's okay.

If it's the reset pin on the Arduino - A) you aren't guaranteed that that will reset the board, per datasheet, don't do that; use watchdog reset if you need to reset the Arduino from within the software and B) what do you expect it to do when countButton starts at 0? It would get to case:0 and reset the board every time it starts!

Yes, it is connected to reset an external IC.

I'm expecting that the RST is OFF (HIGH) for all the time, except when there is configuration going on.

and also when configuration on case 0, it should output a little pulse LOW to keep the IC (which
is an A-D converter) in its reset condition.
Just as long as configuration takes place. Then return to its default condition (HIGH - OFF).

So all of the time, the RST should be off (HIGH), and remain high constantly.
Just as all the other pins behave!!!

In my code, all the pins, once configured, remain stable in their state,
the RST is the only one to output a pulse waveform (a sort of square wave, but 1-2% duty cycle, just to be clear).

Anyone?

Did I choose the wrong forum section to post?

Please help.

The first thing I noticed is that this:-

if(countButton<=5)
    countButton=countButton+1;
else countButton=0;

counts to 6, not to 5.
Then your 'switch case' statement only handles values up to 5.
Is that what you wanted?

And as DrAzzy already pointed out, the whole time that countButton is 0, the RST pin will be pulsed.
If you only want the code in 'case 0' to execute once, you could set a boolean flag the first time that code is executed so that it doesn't execute a second time.
For example, declare a global flag called "configDone", initialise it to 'false', then set it to 'true' the first time the 'case 0' is executed.
Then wrap the code in 'case 0' with an 'if(!configDone)', to ensure it only happens once. (You set 'configDone' to true at the end.):-

case 0:
    if (!configDone)
    {
        digitalWrite(RST, HIGH);
        digitalWrite(LEDF, LOW);    // off LED 176.4
        digitalWrite(LEDA, HIGH);  // on LED 44.1
        digitalWrite(fsA, LOW);   //  FS0 = 0
        digitalWrite(fsB, LOW);   //  FS1 = 0
        digitalWrite(HWCK0, LOW);   //HWCK0 = 0
        digitalWrite(HWCK1, HIGH);  //HWCK1 = 1
        digitalWrite(YA, HIGH);    // 22.5792 MCK ON
        digitalWrite(YB, LOW);     //off 24.576MHz MCK
        digitalWrite(RST, LOW);     //reset on
        delay(500);
        digitalWrite(RST, HIGH);    //reset off
        configDone = true;
    }
    break;

Is this what you mean?

Thanks for the reply.
Consider case 0 as the default condition when the hardware powers up,
then at the first button touch, it advances to case 1, then 2, 3, 4, 5 then 0 again.

All the config pins work just fine.

Now, with the mod you suggested, I get the reset pulse and stable operation
at power up (case 0) but the button loop is lost, as from case 5 the loop does not return to case 0.

Further, what I need is the reset pin to output a LOW pulse at each 'case', thus each time the button is depressed.

With the following updated code, I get
case 0 default, reset pulse ok, executed once
case 1 config pins ok, but reset pulse continuous,

the button loop ignores case 0, and jumps to case 1

Don't know, but it seems that each case should be executed once.

What do you suggest?

// PAD-01
// Default state 44.1, RST off (HIGH)
// First touch: 48
// Second touch: 88.2
// Third touch: led 96
// Fourth touch: led 176.4

const int  LEDA = 13;       // LED A connected to digital pin 13, 44.1kHz
const int  LEDB = 12;         // LED B digipin 12,        48  kHz
const int  LEDC = 11;         // LED C digital pin 11:    88.2kHz
const int  LEDD = 10;       // LED D Digital Pin 10       96  kHz
const int  LEDE = 9;          // LED E digital pin 9      176.4kHz
const int  LEDF = 8;          // LED pin digitale 8       192.0kHz

//MasterClock select
const int YA = 7;         //Y1 digital pin 7 (PD7)    22.5792MHz
const int YB = 6;         //Y2 digital Pin 6 (PD6)    24.576 MHz

//button input and reset
const int BUTTON = 5;   // Button connected to Input DigitalPin 5 PD5
const int RST = 2;      //Reset control digital pin 2, PD2

const int fsA = 4;       //FS0 digitalPin 4         PD4
const int fsB = 3;      //FS1 pin digitale 3        PD3
const int HWCK0 = 0;    //HWCK0 Digital Pin 0       PD0
const int HWCK1 = 1;    //HWCK1 Digital Pin 1       PD1

/* 
 * Global variables (all integers) 
 */
int statoButton     = 0;      // button state (initially not depressed)
int lastStatoButton = 0;      // last state of the button (actually not depressed)
int countButton     = 0;      // Button Count
int configDone      = false;  

// App start
void setup()
{
  pinMode(LEDA, OUTPUT);       // sets the digital pin as an output
  pinMode(LEDB, OUTPUT);
  pinMode(LEDC, OUTPUT);
  pinMode(LEDD, OUTPUT);
  pinMode(LEDE, OUTPUT);
  pinMode(LEDF, OUTPUT);
  pinMode(YA, OUTPUT);
  pinMode(YB, OUTPUT);
  pinMode(RST, OUTPUT);
  pinMode(fsA, OUTPUT);
  pinMode(fsB, OUTPUT);
  pinMode(HWCK0, OUTPUT);
  pinMode(HWCK1, OUTPUT);
  pinMode(RST, OUTPUT);
  
  pinMode(BUTTON, INPUT);     // sets the digital pin as an input
 
}

// Loop start 
void loop()
{
   
  // Verify if user has depressed the button
  if(digitalRead(BUTTON))
  {
    // Wait for 250ms to let the finger release
    delay(250);
    // Change the last state of the button
    if(lastStatoButton==0) lastStatoButton=1;
    else lastStatoButton=0;
    // Increase button count
    if(countButton<=5) countButton=countButton+1;
    else countButton=0;
  }

  // Based on button state choose the action
  switch (countButton)
  {
    // 48 kHz
  case 1:
    digitalWrite(RST, LOW);     // reset active
    digitalWrite(LEDA, LOW);
    digitalWrite(LEDB, HIGH);   // LED 48 on
    digitalWrite(fsA, LOW);     //  FS0 = 0
    digitalWrite(fsB, LOW);     //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, HIGH);  //HWCK1 = 1
    digitalWrite(YA, LOW);    
    digitalWrite(YB, HIGH);     // 24.576MHz MCK active
    digitalWrite(RST, HIGH);    // deactivates reset
    break;

    // 88.2 kHz double speed mode
  case 2:
    digitalWrite(RST, LOW);   // reset active
    digitalWrite(LEDB, LOW);  // off LED     48
    digitalWrite(LEDC, HIGH); // on LED 88.2
    digitalWrite(fsA, HIGH);   //  FS0 = 1
    digitalWrite(fsB, LOW);    //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, HIGH);    // 22.5792 On
    digitalWrite(YB, LOW);     //off 24.576MHz MCK
    digitalWrite(RST, HIGH);    // deactivates reset
    break;

    // 96 kHz double speed mode
  case 3:
    digitalWrite(RST, HIGH);   //off reset
    digitalWrite(LEDC, LOW);  // off il LED 88.2
    digitalWrite(LEDD, HIGH); // on LED 96
    digitalWrite(fsA, HIGH);   //  FS0 = 1
    digitalWrite(fsB, LOW);    //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, LOW);    // 22.5792 Off
    digitalWrite(YB, HIGH);   // on 24.576MHz MCK
    //delay(500);              // wait for a second
    break;

    // 176.4 kHz quad speed mode
  case 4:
    digitalWrite(RST, HIGH);   // off reset
    digitalWrite(LEDD, LOW);   // off LED 96 
    digitalWrite(LEDE, HIGH);  //on LED 176.4
    digitalWrite(fsA, LOW);     //  FS0 = 0
    digitalWrite(fsB, HIGH);    //  FS1 = 1
    digitalWrite(HWCK0, HIGH);  //HWCK0 = 1
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, HIGH);    // 22.5792 On
    digitalWrite(YB, LOW);     // off 24.576MHz MCK
    //delay(500);              // wait for a second
    break;

    // 192 kHz quad speed mode
  case 5:             
    digitalWrite(RST, HIGH);
    digitalWrite(LEDE, LOW);  // off LED 176.4 
    digitalWrite(LEDF, HIGH); // on LED 192
    digitalWrite(fsA, LOW);   //  FS0 = 0
    digitalWrite(fsB, HIGH);  //  FS1 = 1
    digitalWrite(HWCK0, HIGH);  //HWCK0 = 1
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, LOW);    // 22.5792 Off
    digitalWrite(YB, HIGH);     // on 24.576MHz MCK
    //delay(500);              // wait for a second
    break;

    // 44.1 kHz
  case 0:
  if (!configDone)
    {
    digitalWrite(RST, HIGH);
    digitalWrite(LEDF, LOW);    // off LED 176.4
    digitalWrite(LEDA, HIGH);  // on LED 44.1
    digitalWrite(fsA, LOW);   //  FS0 = 0
    digitalWrite(fsB, LOW);   //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, HIGH);  //HWCK1 = 1
    digitalWrite(YA, HIGH);    // 22.5792 MCK ON
    digitalWrite(YB, LOW);     //off 24.576MHz MCK
    digitalWrite(RST, LOW);     //reset on
    delay(2000);
    digitalWrite(RST, HIGH);    //reset off
    configDone = true;
    }
    break;
    
  }
}

pristine98:
Now, with the mod you suggested, I get the reset pulse and stable operation
at power up (case 0) but the button loop is lost, as from case 5 the loop does not return to case 0.

(Edited when I realised more of what you want.)

Don't use the flag then.

You haven't accurately described what you want. I assumed that 'config' was 'case 0'. You talk about 'configuration', but don't accurately describe exactly what it means.

And if you want a 'RST' pulse on every button press, you need to write it in each 'case' statement. Only one is executed at each button press.

And you still didn't fix this, so the count actually goes to 6:-

if(countButton<=5)
    countButton=countButton+1;
else countButton=0;

Thank you for your time and patience!

Ok, I will try to describe again:

all of the pins, except RST, are needed to configure external ICs, so I referred to as 'configuration' pins,
anytime you change state by pressing the button, a new hardware configuration, takes place, and the Arduino sets all the pins of the external IC's as needed.

RST (active LOW) serves to keep the external ICs in reset until their own internal configuration pins get the desired values from Arduino, then RST is deasserted again (brought to HIGH).

And I'm assuming (consider I'm a total newbie and this is my very first sketch) that
when Arduino is powered up, together with the external ADC board that I want to configure,
everything starts at 'case 0'.

With the following code, I'm almost done.
The problem is that the RST pulse is continuously going on, (pulsewave on the scope)
where I just need a SINGLE reset pulse, for each case,

Please note; in the following code I didn't paste the RST pulse for all the cases, just the
first three (RST pulse doesn't work yet as intended), so I will recopy when it works.

I updated the count to 4, I hope this is done right, and it seems to work.
At this point, the only thing that I need to fix is the single pulse for the RST pin.

Any help much appreciated.

// PAD-01
// Default state 44.1, RST off (HIGH)
// First touch: 48
// Second touch: 88.2
// Third touch: led 96
// Fourth touch: led 176.4

const int  LEDA = 13;       // LED A connected to digital pin 13, 44.1kHz
const int  LEDB = 12;         // LED B digipin 12,        48  kHz
const int  LEDC = 11;         // LED C digital pin 11:    88.2kHz
const int  LEDD = 10;       // LED D Digital Pin 10       96  kHz
const int  LEDE = 9;          // LED E digital pin 9      176.4kHz
const int  LEDF = 8;          // LED pin digitale 8       192.0kHz

//MasterClock select
const int YA = 7;         //Y1 digital pin 7 (PD7)    22.5792MHz
const int YB = 6;         //Y2 digital Pin 6 (PD6)    24.576 MHz

//button input and reset
const int BUTTON = 5;   // Button connected to Input DigitalPin 5 PD5
const int RST = 2;      //Reset control digital pin 2, PD2

const int fsA = 4;       //FS0 digitalPin 4         PD4
const int fsB = 3;      //FS1 pin digitale 3        PD3
const int HWCK0 = 0;    //HWCK0 Digital Pin 0       PD0
const int HWCK1 = 1;    //HWCK1 Digital Pin 1       PD1

/* 
 * Global variables (all integers) 
 */
int statoButton     = 0;      // button state (initially not depressed)
int lastStatoButton = 0;      // last state of the button (actually not depressed)
int countButton     = 0;      // Button Count
int configDone      = false;  

// App start
void setup()
{
  pinMode(LEDA, OUTPUT);       // sets the digital pin as an output
  pinMode(LEDB, OUTPUT);
  pinMode(LEDC, OUTPUT);
  pinMode(LEDD, OUTPUT);
  pinMode(LEDE, OUTPUT);
  pinMode(LEDF, OUTPUT);
  pinMode(YA, OUTPUT);
  pinMode(YB, OUTPUT);
  pinMode(RST, OUTPUT);
  pinMode(fsA, OUTPUT);
  pinMode(fsB, OUTPUT);
  pinMode(HWCK0, OUTPUT);
  pinMode(HWCK1, OUTPUT);
  
  pinMode(BUTTON, INPUT);     // sets the digital pin as an input
 
}

// Loop start 
void loop()
{
   
  // Verify if user has depressed the button
  if(digitalRead(BUTTON))
  {
    // Wait for 250ms to let the finger release
    delay(250);
    // Change the last state of the button
    if(lastStatoButton==0) lastStatoButton=1;
    else lastStatoButton=0;
    // Increase button count
    if(countButton<=4) countButton=countButton+1;
    else countButton=0;
  }

  // Based on button state choose the action
  switch (countButton)
  {
    // 48 kHz
  case 1:
    digitalWrite(RST, LOW);     // reset active
    digitalWrite(LEDA, LOW);
    digitalWrite(LEDB, HIGH);   // LED 48 on
    digitalWrite(fsA, LOW);     //  FS0 = 0
    digitalWrite(fsB, LOW);     //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, HIGH);  //HWCK1 = 1
    digitalWrite(YA, LOW);    
    digitalWrite(YB, HIGH);     // 24.576MHz MCK active
    delay(500);
    digitalWrite(RST, HIGH);    // deactivates reset
    break;

    // 88.2 kHz double speed mode
  case 2:
    digitalWrite(RST, LOW);   // reset active
    digitalWrite(LEDB, LOW);  // off LED     48
    digitalWrite(LEDC, HIGH); // on LED 88.2
    digitalWrite(fsA, HIGH);   //  FS0 = 1
    digitalWrite(fsB, LOW);    //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, HIGH);    // 22.5792 On
    digitalWrite(YB, LOW);     //off 24.576MHz MCK
    digitalWrite(RST, HIGH);    // deactivates reset
    break;

    // 96 kHz double speed mode
  case 3:
    digitalWrite(RST, LOW);   // reset active
    digitalWrite(LEDC, LOW);  // off il LED 88.2
    digitalWrite(LEDD, HIGH); // on LED 96
    digitalWrite(fsA, HIGH);   //  FS0 = 1
    digitalWrite(fsB, LOW);    //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, LOW);    // 22.5792 Off
    digitalWrite(YB, HIGH);   // on 24.576MHz MCK
    digitalWrite(RST, HIGH);  // reset off
    //delay(500);              // wait for a second
    break;

    // 176.4 kHz quad speed mode
  case 4:
    digitalWrite(RST, HIGH);   // off reset
    digitalWrite(LEDD, LOW);   // off LED 96 
    digitalWrite(LEDE, HIGH);  //on LED 176.4
    digitalWrite(fsA, LOW);     //  FS0 = 0
    digitalWrite(fsB, HIGH);    //  FS1 = 1
    digitalWrite(HWCK0, HIGH);  //HWCK0 = 1
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, HIGH);    // 22.5792 On
    digitalWrite(YB, LOW);     // off 24.576MHz MCK
    //delay(500);              // wait for a second
    break;

    // 192 kHz quad speed mode
  case 5:             
    digitalWrite(RST, HIGH);
    digitalWrite(LEDE, LOW);  // off LED 176.4 
    digitalWrite(LEDF, HIGH); // on LED 192
    digitalWrite(fsA, LOW);   //  FS0 = 0
    digitalWrite(fsB, HIGH);  //  FS1 = 1
    digitalWrite(HWCK0, HIGH);  //HWCK0 = 1
    digitalWrite(HWCK1, LOW);   //HWCK1 = 0
    digitalWrite(YA, LOW);    // 22.5792 Off
    digitalWrite(YB, HIGH);     // on 24.576MHz MCK
    //delay(500);              // wait for a second
    configDone = false;
    break;

    // 44.1 kHz
  case 0:
  if (!configDone)
    {
    digitalWrite(RST, HIGH);
    digitalWrite(LEDF, LOW);    // off LED 176.4
    digitalWrite(LEDA, HIGH);  // on LED 44.1
    digitalWrite(fsA, LOW);   //  FS0 = 0
    digitalWrite(fsB, LOW);   //  FS1 = 0
    digitalWrite(HWCK0, LOW);   //HWCK0 = 0
    digitalWrite(HWCK1, HIGH);  //HWCK1 = 1
    digitalWrite(YA, HIGH);    // 22.5792 MCK ON
    digitalWrite(YB, LOW);     //off 24.576MHz MCK
    digitalWrite(RST, LOW);     //reset on
    delay(2000);
    digitalWrite(RST, HIGH);    //reset off
    configDone = true;
    }
    break;
    
  }
}

It's 11pm here and I'm really exhausted, but if no one else has helped in the meantime, I'll reply in the morning and go over your code properly.
If I try now, I'm bound to make mistakes.
I'll keep the link to this thread in my InBox, so I see it first up tomorrow.

For one thing, the flag that I suggested won't be needed. I misunderstood what you wanted. (Didn't read your opening post well enough. :frowning: )

For now, it's off to bed for me. :slight_smile:

It was too hot to sleep, so I got back up and took a good look at your code.

A couple of things I'm not sure of.

Regarding 'case0':-

  1. On initial power-up, should there be a reset pulse for 44.1kHz?
  2. When cycling back to 44.1kHz, from 'case 5', should there be a reset pulse?
    ie Should 'case 0' always behave the same, both on power up and on subsequent cycles back to it?
  3. I notice that when selecting 'case 1' to 'case 5', 'RST' is asserted, the right pins are set/cleared for that frequency, then 'RST' is released, yet your last code for 'case 0' set up the pins then took the 'RST' pin low and high, with a 2 second delay in between. Should 'case 0' behave like the others? And should it have that delay, but not the others? (Or should all have the 500ms delay?)

All others, ('case 1' to 'case 5'), have a 500ms delay that's been commented out. Is that delay required, or not?
I'm trying hard to understand exactly what you want, based on the code you've shown, but it's not easy.

Meantime, I've re-written the code so that it basically performs how you want - only the issues I just raised need clarifying, then some final touches can be made.

I've tested the following in my Arduino simulator, and on power up 44.1kHz is selected, and RST doesn't continuously pulse as it was before.
Then for each button press, the next higher frequency is selected, with reset taken high, all config pins set/cleared, then reset taken low.
When 'case 5' is selected, and the button is pressed again, the frequency reverts to 'case 0', (44.1kHz).
It's almost there. Here's the code so far:-
(Note that I moved 'case 0' up to the top of the 'switch' statement, where it rightfully belongs. :slight_smile: )

// PAD-01
// Default state 44.1, RST off (HIGH)
// First touch: 48
// Second touch: 88.2
// Third touch: led 96
// Fourth touch: led 176.4

const int LEDA = 13;    // LED A connected to digital pin 13, 44.1kHz
const int LEDB = 12;    // LED B digipin 12, 48 kHz
const int LEDC = 11;    // LED C digital pin 11: 88.2kHz
const int LEDD = 10;    // LED D Digital Pin 10 96 kHz
const int LEDE = 9;     // LED E digital pin 9 176.4kHz
const int LEDF = 8;     // LED pin digitale 8 192.0 kHz

//MasterClock select
const int YA = 7;       // Y1 digital pin 7 (PD7) 22.5792MHz
const int YB = 6;       // Y2 digital Pin 6 (PD6) 24.576 MHz

//button input and reset
const int BUTTON = 5;   // Button connected to Input DigitalPin 5 PD5
const int RST = 2;      // Reset control digital pin 2, PD2

const int fsA = 4;      // FS0 digitalPin 4 PD4
const int fsB = 3;      // FS1 pin digitale 3 PD3
const int HWCK0 = 0;    // HWCK0 Digital Pin 0 PD0
const int HWCK1 = 1;    // HWCK1 Digital Pin 1 PD1

/*
* Global variables (all integers) * Not any more :)
*/
int countButton = 0;        // Button Count
bool buttonPressed = true;  // 'true' so that initial (case 0) config happens without a button press.

// App start
void setup()
{
    pinMode(LEDA, OUTPUT); // sets the digital pin as an output
    pinMode(LEDB, OUTPUT);
    pinMode(LEDC, OUTPUT);
    pinMode(LEDD, OUTPUT);
    pinMode(LEDE, OUTPUT);
    pinMode(LEDF, OUTPUT);
    pinMode(YA, OUTPUT);
    pinMode(YB, OUTPUT);
    pinMode(RST, OUTPUT);
    pinMode(fsA, OUTPUT);
    pinMode(fsB, OUTPUT);
    pinMode(HWCK0, OUTPUT);
    pinMode(HWCK1, OUTPUT);

    pinMode(BUTTON, INPUT); // sets the digital pin as an input
}

// Loop start
void loop()
{
    // Check if user has depressed the button:-
    if (digitalRead(BUTTON))
    {
        delay(250);             // Wait for 250ms to let the finger release.
        buttonPressed = true;   // Flag the button press.

        // Increase button count:-
        if (countButton <= 4)
            countButton++;
        else countButton = 0;
    }

    if (buttonPressed)
    {
        // Based on button count choose the action:-
        switch (countButton)
        {
            // 44.1 kHz
            case 0:
                digitalWrite(RST, HIGH);
                digitalWrite(LEDF, LOW);    // off LED 176.4
                digitalWrite(LEDA, HIGH);   // on LED 44.1
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, HIGH);  // HWCK1 = 1
                digitalWrite(YA, HIGH);     // 22.5792 MCK ON
                digitalWrite(YB, LOW);      // off 24.576MHz MCK
                digitalWrite(RST, LOW);     // reset on
                delay(2000);
                digitalWrite(RST, HIGH);    // reset off
                buttonPressed = false;      // Clear the 'button pressed' flag.
                break;

            // 48 kHz:-
            case 1:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDA, LOW);    // off LED 44.1
                digitalWrite(LEDB, HIGH);   // LED 48 on
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, HIGH);  // HWCK1 = 1
                digitalWrite(YA, LOW);
                digitalWrite(YB, HIGH);     // 24.576MHz MCK active
                delay(500);
                digitalWrite(RST, HIGH);    // deactivates reset
                buttonPressed = false;
                break;

            // 88.2 kHz double speed mode:-
            case 2:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDB, LOW);    // off LED 48
                digitalWrite(LEDC, HIGH);   // on LED 88.2
                digitalWrite(fsA, HIGH);    // FS0 = 1
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, HIGH);     // 22.5792 On
                digitalWrite(YB, LOW);      // off 24.576MHz MCK
                digitalWrite(RST, HIGH);    // deactivates reset
                buttonPressed = false;
                break;

            // 96 kHz double speed mode:-
            case 3:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDC, LOW);    // off il LED 88.2
                digitalWrite(LEDD, HIGH);   // on LED 96
                digitalWrite(fsA, HIGH);    // FS0 = 1
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, LOW);      // 22.5792 Off
                digitalWrite(YB, HIGH);     // on 24.576MHz MCK
                digitalWrite(RST, HIGH);    // reset off
                //delay(500);               // wait for a second
                buttonPressed = false;
                break;

            // 176.4 kHz quad speed mode:-
            case 4:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDD, LOW);    // off LED 96
                digitalWrite(LEDE, HIGH);   // on LED 176.4
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, HIGH);    // FS1 = 1
                digitalWrite(HWCK0, HIGH);  // HWCK0 = 1
                digitalWrite( HWCK1, LOW);  // HWCK1 = 0
                digitalWrite(YA, HIGH);     // 22.5792 On
                digitalWrite(YB, LOW);      // off 24.576MHz MCK
                digitalWrite(RST, HIGH);    // reset off
                //delay(500);               // wait for a second
                buttonPressed = false;
                break;

            // 192 kHz quad speed mode:-
            case 5:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDE, LOW);    // off LED 176.4
                digitalWrite(LEDF, HIGH);   // on LED 192
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, HIGH);    // FS1 = 1
                digitalWrite(HWCK0, HIGH);  // HWCK0 = 1
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, LOW);      // 22.5792 Off
                digitalWrite(YB, HIGH);     // on 24.576MHz MCK
                digitalWrite(RST, HIGH);    // reset off
                //delay(500);               // wait for a second
                buttonPressed = false;
                break;
        }
    }
}

I had to do a bit of re-arranging, deleted some unused variables and added one.
Now if you can check it out, then answer my questions above, I can help with the finishing touches when I get up tomorrow, (later today really - it's 3am :slight_smile: .)

I should have added - the reason for the previous behaviour was that the 'switch case' was being executed with every iteration of the 'loop()', whether or not the button was pressed. The right pins for the last chosen frequency were staying high/low because 'countButton' wasn't changing unless the button was pressed. And 'RST' was only pulsing when 'case 0' was true because reset hadn't yet been implemented in the other cases.

I couldn't edit my last reply to add this because it then exceeded the maximum 9000 characters per post limit.

Hi OldSteve,

Many thanks for your reply!
That solved the problem, I made a few exchanges, the following code works flawlessly.
I apologise as I fear I have been too bold upon your rest.

I'm unsure about the RST
since it should be HIGH by default, probably there is a better way to declare this outside the void loop().
That should answers your doubt about case 0.
and yes I prefer at start-up, the RST to be active while configuring hardware pins in any case,
even when the button loop starts again from case 5 to case 0

OldSteve:
It was too hot to sleep, so I got back up and took a good look at your code.

A couple of things I'm not sure of.

Regarding 'case0':-

  1. On initial power-up, should there be a reset pulse for 44.1kHz?

Yes

  1. When cycling back to 44.1kHz, from 'case 5', should there be a reset pulse?
    ie Should 'case 0' always behave the same, both on power up and on subsequent cycles back to it?

Yes, exactly.

  1. I notice that when selecting 'case 1' to 'case 5', 'RST' is asserted, the right pins are set/cleared for that frequency, then 'RST' is released, yet your last code for 'case 0' set up the pins then took the 'RST' pin low and high, with a 2 second delay in between. Should 'case 0' behave like the others? And should it have that delay, but not the others? (Or should all have the 500ms delay?)

I've changed this in my new code, the problem is that the Reset pin should be declared HIGH,
as this is its default condition. Bear in mind that all hardware resets are usually 'active low', as in this case.
Probably another int variable for the RST Pin?

All others, ('case 1' to 'case 5'), have a 500ms delay that's been commented out. Is that delay required, or not?
I'm trying hard to understand exactly what you want, based on the code you've shown, but it's not easy.

I've updated the correct code, please see below.... and yes, the delay is always needed.

Meantime, I've re-written the code so that it basically performs how you want - only the issues I just raised need clarifying, then some final touches can be made.

I've tested the following in my Arduino simulator, and on power up 44.1kHz is selected, and RST doesn't continuously pulse as it was before.
Then for each button press, the next higher frequency is selected, with reset taken high, all config pins set/cleared, then reset taken low.
When 'case 5' is selected, and the button is pressed again, the frequency reverts to 'case 0', (44.1kHz).
It's almost there. Here's the code so far:-
(Note that I moved 'case 0' up to the top of the 'switch' statement, where it rightfully belongs. :slight_smile: )

that was what I intended the Arduino to do.

I had to do a bit of re-arranging, deleted some unused variables and added one.
Now if you can check it out, then answer my questions above, I can help with the finishing touches when I get up tomorrow, (later today really - it's 3am :slight_smile: .)

Sorry again if I troubled your sleep :stuck_out_tongue:

The updated code follows .........

// Default state 44.1, RST off (HIGH)
// First touch: 48
// Second touch: 88.2
// Third touch: led 96
// Fourth touch: led 176.4
// Fifth touch: 192 kHz
// Sixth touch: restarts the loop, 44.1kHz (default)

const int LEDA = 13;    // LED A connected to digital pin 13, 44.1kHz
const int LEDB = 12;    // LED B digipin 12, 48 kHz
const int LEDC = 11;    // LED C digital pin 11: 88.2kHz
const int LEDD = 10;    // LED D Digital Pin 10 96 kHz
const int LEDE = 9;     // LED E digital pin 9 176.4kHz
const int LEDF = 8;     // LED pin digitale 8 192.0 kHz

//MasterClock select
const int YA = 7;       // Y1 digital pin 7 (PD7) 22.5792MHz
const int YB = 6;       // Y2 digital Pin 6 (PD6) 24.576 MHz

//button input and reset
const int BUTTON = 5;   // Button connected to Input DigitalPin 5 PD5
const int RST = 2;      // Reset control digital pin 2, PD2

const int fsA = 4;      // FS0 digitalPin 4 PD4
const int fsB = 3;      // FS1 pin digitale 3 PD3
const int HWCK0 = 0;    // HWCK0 Digital Pin 0 PD0
const int HWCK1 = 1;    // HWCK1 Digital Pin 1 PD1

/*
* Global variables
*/
int countButton = 0;        // Button Count
bool buttonPressed = true;  // 'true' so that initial (case 0) config happens without a button press.

// App start
void setup()
{
    pinMode(LEDA, OUTPUT); // sets the digital pin as an output
    pinMode(LEDB, OUTPUT);
    pinMode(LEDC, OUTPUT);
    pinMode(LEDD, OUTPUT);
    pinMode(LEDE, OUTPUT);
    pinMode(LEDF, OUTPUT);
    pinMode(YA, OUTPUT);
    pinMode(YB, OUTPUT);
    pinMode(RST, OUTPUT);
    pinMode(fsA, OUTPUT);
    pinMode(fsB, OUTPUT);
    pinMode(HWCK0, OUTPUT);
    pinMode(HWCK1, OUTPUT);

    pinMode(BUTTON, INPUT); // sets the digital pin as an input
}

// Loop start
void loop()
{
    // Check if user has depressed the button:-
    if (digitalRead(BUTTON))
    {
        delay(250);             // Wait for 250ms to let the finger release.
        buttonPressed = true;   // Flag the button press.

        // Increase button count:-
        if (countButton <= 4)
            countButton++;
        else countButton = 0;
    }

    if (buttonPressed)
    {
        // Based on button count choose the action:-
        switch (countButton)
        {
            // 44.1 kHz
            case 0:
                digitalWrite(RST, HIGH);    // reset default condition is unactive (HIGH) << probably better declared within the setup ???
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDF, LOW);    // off LED 176.4
                digitalWrite(LEDA, HIGH);   // on LED 44.1
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, HIGH);  // HWCK1 = 1
                digitalWrite(YA, HIGH);     // 22.5792 MCK ON
                digitalWrite(YB, LOW);      // off 24.576MHz MCK  
                delay(1000);                // wait for a second
                digitalWrite(RST, HIGH);    // deactivate reset
                buttonPressed = false;      // Clear the 'button pressed' flag.
                break;

            // 48 kHz:-
            case 1:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDA, LOW);    // off LED 44.1
                digitalWrite(LEDB, HIGH);   // LED 48 on
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, HIGH);  // HWCK1 = 1
                digitalWrite(YA, LOW);
                digitalWrite(YB, HIGH);     // 24.576MHz MCK active
                delay(1000);                // waits for a second
                digitalWrite(RST, HIGH);    // deactivates reset
                buttonPressed = false;
                break;

            // 88.2 kHz double speed mode:-
            case 2:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDB, LOW);    // off LED 48
                digitalWrite(LEDC, HIGH);   // on LED 88.2
                digitalWrite(fsA, HIGH);    // FS0 = 1
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, HIGH);     // 22.5792 On
                digitalWrite(YB, LOW);      // off 24.576MHz MCK
                delay(1000);                // waits for a second
                digitalWrite(RST, HIGH);    // deactivates reset
                buttonPressed = false;
                break;

            // 96 kHz double speed mode:-
            case 3:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDC, LOW);    // off il LED 88.2
                digitalWrite(LEDD, HIGH);   // on LED 96
                digitalWrite(fsA, HIGH);    // FS0 = 1
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, LOW);      // 22.5792 Off
                digitalWrite(YB, HIGH);     // on 24.576MHz MCK
                delay(1000);                // wait for a second
                digitalWrite(RST, HIGH);    // deactivates reset
                buttonPressed = false;
                break;

            // 176.4 kHz quad speed mode:-
            case 4:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDD, LOW);    // off LED 96
                digitalWrite(LEDE, HIGH);   // on LED 176.4
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, HIGH);    // FS1 = 1
                digitalWrite(HWCK0, HIGH);  // HWCK0 = 1
                digitalWrite( HWCK1, LOW);  // HWCK1 = 0
                digitalWrite(YA, HIGH);     // 22.5792 On
                digitalWrite(YB, LOW);      // off 24.576MHz MCK
                delay(1000);                // wait for a second
                digitalWrite(RST, HIGH);    // reset off
                buttonPressed = false;
                break;

            // 192 kHz quad speed mode:-
            case 5:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDE, LOW);    // off LED 176.4
                digitalWrite(LEDF, HIGH);   // on LED 192
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, HIGH);    // FS1 = 1
                digitalWrite(HWCK0, HIGH);  // HWCK0 = 1
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, LOW);      // 22.5792 Off
                digitalWrite(YB, HIGH);     // on 24.576MHz MCK
                delay(1000);                // wait for a second
                digitalWrite(RST, HIGH);    // reset off
                buttonPressed = false;
                break;
        }
    }
}

No problem. The last bit is easy.
I have to pop out for a bit, but I'll add those finishing touches when I get back in about an hour, then post the result.
Stay tuned..... :slight_smile:

pristine98:
I'm unsure about the RST
since it should be HIGH by default, probably there is a better way to declare this outside the void loop().
That should answers your doubt about case 0.
and yes I prefer at start-up, the RST to be active while configuring hardware pins in any case,
even when the button loop starts again from case 5 to case 0

YesYes, exactly.
I've changed this in my new code, the problem is that the Reset pin should be declared HIGH,
as this is its default condition. Bear in mind that all hardware resets are usually 'active low', as in this case.
Probably another int variable for the RST Pin?

Sorting out the last little 'RST' problem is easy.
It's best to make it 'HIGH' in 'setup()' as you say, to set the default. Then when the 'loop()' function is entered, 'RST' is in the correct state.
Each 'case' is then responsible for pulling the 'RST' pin low, then taking it high again so that it's always high unless reconfiguration is in progress.

So you didn't actually need me to help at all this morning - you already had the right idea.
Anyway, I've moved the line that initialises the 'RST' pin from the beginning of 'case 0' to the end of 'setup()'. I can't see anything else that needs addressing at the moment, so you're good-to-go.
It compiles without errors and works fine in my simulator, doing what it should:-

// Default state 44.1, RST off (HIGH)
// First touch: 48
// Second touch: 88.2
// Third touch: led 96
// Fourth touch: led 176.4
// Fifth touch: 192 kHz
// Sixth touch: restarts the loop, 44.1kHz (default)

const int LEDA = 13;    // LED A connected to digital pin 13, 44.1kHz
const int LEDB = 12;    // LED B digipin 12, 48 kHz
const int LEDC = 11;    // LED C digital pin 11: 88.2kHz
const int LEDD = 10;    // LED D Digital Pin 10 96 kHz
const int LEDE = 9;     // LED E digital pin 9 176.4kHz
const int LEDF = 8;     // LED pin digitale 8 192.0 kHz

//MasterClock select
const int YA = 7;       // Y1 digital pin 7 (PD7) 22.5792MHz
const int YB = 6;       // Y2 digital Pin 6 (PD6) 24.576 MHz

//button input and reset
const int BUTTON = 5;   // Button connected to Input DigitalPin 5 PD5
const int RST = 2;      // Reset control digital pin 2, PD2

const int fsA = 4;      // FS0 digitalPin 4 PD4
const int fsB = 3;      // FS1 pin digitale 3 PD3
const int HWCK0 = 0;    // HWCK0 Digital Pin 0 PD0
const int HWCK1 = 1;    // HWCK1 Digital Pin 1 PD1

/*
* Global variables
*/
int countButton = 0;        // Button Count
bool buttonPressed = true;  // 'true' so that initial (case 0) config happens without a button press.

// App start
void setup()
{
    pinMode(LEDA, OUTPUT);      // sets the digital pin as an output
    pinMode(LEDB, OUTPUT);
    pinMode(LEDC, OUTPUT);
    pinMode(LEDD, OUTPUT);
    pinMode(LEDE, OUTPUT);
    pinMode(LEDF, OUTPUT);
    pinMode(YA, OUTPUT);
    pinMode(YB, OUTPUT);
    pinMode(RST, OUTPUT);
    pinMode(fsA, OUTPUT);
    pinMode(fsB, OUTPUT);
    pinMode(HWCK0, OUTPUT);
    pinMode(HWCK1, OUTPUT);

    pinMode(BUTTON, INPUT);     // sets the digital pin as an input
    digitalWrite(RST, HIGH);    // reset default condition is unactive (HIGH)
}

// Loop start
void loop()
{
    // Check if user has depressed the button:-
    if (digitalRead(BUTTON))
    {
        delay(250);             // Wait for 250ms to let the finger release.
        buttonPressed = true;   // Flag the button press.

        // Increase button count:-
        if (countButton <= 4)
            countButton++;
        else countButton = 0;
    }

    if (buttonPressed)
    {
        // Based on button count choose the action:-
        switch (countButton)
        {
            // 44.1 kHz
            case 0:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDF, LOW);    // off LED 176.4
                digitalWrite(LEDA, HIGH);   // on LED 44.1
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, HIGH);  // HWCK1 = 1
                digitalWrite(YA, HIGH);     // 22.5792 MCK ON
                digitalWrite(YB, LOW);      // off 24.576MHz MCK
                delay(1000);                // wait for a second
                digitalWrite(RST, HIGH);    // deactivate reset
                buttonPressed = false;      // Clear the 'button pressed' flag.
                break;

            // 48 kHz:-
            case 1:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDA, LOW);    // off LED 44.1
                digitalWrite(LEDB, HIGH);   // LED 48 on
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, HIGH);  // HWCK1 = 1
                digitalWrite(YA, LOW);
                digitalWrite(YB, HIGH);     // 24.576MHz MCK active
                delay(1000);                // waits for a second
                digitalWrite(RST, HIGH);    // deactivates reset
                buttonPressed = false;
                break;

            // 88.2 kHz double speed mode:-
            case 2:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDB, LOW);    // off LED 48
                digitalWrite(LEDC, HIGH);   // on LED 88.2
                digitalWrite(fsA, HIGH);    // FS0 = 1
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, HIGH);     // 22.5792 On
                digitalWrite(YB, LOW);      // off 24.576MHz MCK
                delay(1000);                // waits for a second
                digitalWrite(RST, HIGH);    // deactivates reset
                buttonPressed = false;
                break;

            // 96 kHz double speed mode:-
            case 3:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDC, LOW);    // off il LED 88.2
                digitalWrite(LEDD, HIGH);   // on LED 96
                digitalWrite(fsA, HIGH);    // FS0 = 1
                digitalWrite(fsB, LOW);     // FS1 = 0
                digitalWrite(HWCK0, LOW);   // HWCK0 = 0
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, LOW);      // 22.5792 Off
                digitalWrite(YB, HIGH);     // on 24.576MHz MCK
                delay(1000);                // wait for a second
                digitalWrite(RST, HIGH);    // deactivates reset
                buttonPressed = false;
                break;

            // 176.4 kHz quad speed mode:-
            case 4:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDD, LOW);    // off LED 96
                digitalWrite(LEDE, HIGH);   // on LED 176.4
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, HIGH);    // FS1 = 1
                digitalWrite(HWCK0, HIGH);  // HWCK0 = 1
                digitalWrite( HWCK1, LOW);  // HWCK1 = 0
                digitalWrite(YA, HIGH);     // 22.5792 On
                digitalWrite(YB, LOW);      // off 24.576MHz MCK
                delay(1000);                // wait for a second
                digitalWrite(RST, HIGH);    // reset off
                buttonPressed = false;
                break;

            // 192 kHz quad speed mode:-
            case 5:
                digitalWrite(RST, LOW);     // reset active
                digitalWrite(LEDE, LOW);    // off LED 176.4
                digitalWrite(LEDF, HIGH);   // on LED 192
                digitalWrite(fsA, LOW);     // FS0 = 0
                digitalWrite(fsB, HIGH);    // FS1 = 1
                digitalWrite(HWCK0, HIGH);  // HWCK0 = 1
                digitalWrite(HWCK1, LOW);   // HWCK1 = 0
                digitalWrite(YA, LOW);      // 22.5792 Off
                digitalWrite(YB, HIGH);     // on 24.576MHz MCK
                delay(1000);                // wait for a second
                digitalWrite(RST, HIGH);    // reset off
                buttonPressed = false;
                break;
        }
    }
}

Let me know if you have any problems.

Thank you for your collaborative efforts.

Everything works just fine!!! :slight_smile:

pristine98:
Thank you for your collaborative efforts.

Everything works just fine!!! :slight_smile:

Good. I'm pleased to hear it.
(Another successful mission. :slight_smile: )