hz through IRLB8721PBF Mosfet

Scope? Can you show the Gate trace and LED trace?

Does the sketch posted in #99 look even remotely the same as on you computer screen ?

larryd:
Does the sketch posted in #99 look even remotely the same as on you computer screen ?

Yes, it is verry good if I only use one LED, but more LEDs and it is going way off.

maker-20_:
Yes, it is verry good

Look again at reply #99.

aarg:
Look again at reply #99.

Fixed!

maker-20_:
Fixed!

No.

aarg:
No.

Fixed, and if not, tell me what you are pointing at...

maker-20_:
Fixed, and if not, tell me what you are pointing at...

It's good now. I guess I've been looking at a browser or server cached copy.

What are these "more LEDs" you refer to, that you say break your sketch? I only see one LED in the one you posted. Does that mean you posted a working sketch, not a non-working sketch?

You need to wire the switch as in the green oval:

aarg:
What are these "more LEDs" you refer to, that you say break your sketch? I only see one LED in the one you posted. Does that mean you posted a working sketch, not a non-working sketch?

I will now try to clear things up, I am developing a device that need to blink 108 LEDs in parallel (1.85A) That one LED is a indicator that are on while the 108 LEDs is on, since some devices will be infrared. I am getting right HZ out of it if I only put a few LEDs after the mosfet. But if I put the 108 LEDs I get wrong HZ, it can be 400 hz off what I said in my program. If I add the capacitor (c11) that has 100uF it is working but! You guys said that I should not have capacitor like that (In the beginning of this forum) but that was without gate resistor.... So are you understanding what I am doing and what I have to deal with?

So are you understanding what I am doing and what I have to deal with?

We have no idea ! :confused:

larryd:
You need to wire the switch as in the green oval:

Thanks @larryd did not see that!

larryd:
We have no idea ! :confused:

Gash... what is wrong with having c11 in the schematic?

You said you have measured the "wrong" behaviour using a scope. Can you please send taxes traces of the "wrong" and "right" behaviour? Also a photo of your setup may help.
The C11 simply does not make sense, it is stressing the pin and probably transistor too much. There must be something else hidden.

Adding a capacitor at that location makes the circuit act like a LOW pass filter.

That is, low frequencies will be passed (as long as the capacitor is not too large), HIGH frequencies will be rejected (shunted to ground).

And YES adding a capacitor there is stressing the pin.

maker-20_:
Gash... what is wrong with having c11 in the schematic?

Nothing. It's when you put it in the circuit that you have problems.

Try this sketch:

#define PUSHED            LOW

#define LEDon             HIGH
#define LEDoff            LOW

//***********************************************************************
//Switch connection
//+5V---[internal pullup resistor]---[input]---[switch]---GND(0V)
const byte startSwitch     = 2;

const byte onIndicationLED = 7;
const byte LEDpin          = 10;  //[output pin]---[LED >|]---[220R]---GND/0V

byte frequencyCounter      = 0;
bool flashFlag             = false;
uint8_t lastStartState;

//timing stuff
unsigned long xMillis;
uint32_t switchMillis;

const uint16_t
c_grBlinkPeriod[] =
{
  16000u,         //16000 x 62.5nS = 1mS --> 1kHz
  5333u,          //5333 x 62.5nS = 333.3125uS -->3000.19Hz
  160u            //160 x 62.5nS == 10uS --> 100kHz
};

const unsigned long xMinutes   = 1 * 1000ul;        //for testing use only 4 seconds

//***********************************************************************
void setup()
{
  pinMode(onIndicationLED, OUTPUT);
  pinMode(startSwitch, INPUT_PULLUP); //pushed/closed = LOW
  lastStartState = digitalRead( startSwitch );

  pinMode(LEDpin, OUTPUT);
  digitalWrite( LEDpin, LEDoff );

  //init WGM15 with prescaler of /1
  //pin 10 is disconnected from timer
  TCCR1A = _BV(WGM11) | _BV(WGM10);
  TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);
  OCR1A = 0;
  OCR1B = 0;

} //END of setup()

//***********************************************************************
void loop()
{
  //**************************
  //check the switches every 50ms
  //time to check our switches ?
  if (millis() - switchMillis >= 50)
  {
    switchMillis = millis();        //restart timer
    checkSwitches();

  }//if

  //**************************
  //is flashing enabled ?
  if (flashFlag == true)
  {
    //**************
    //X minute timer
    //has X minutes expired ?
    if (millis() - xMillis >= xMinutes)
    {
      //restart the timer
      xMillis = millis();

      //next frequency
      frequencyCounter++;
      if ( frequencyCounter > 2 )
      {
        //reset to the beginning
        frequencyCounter = 0;
        
        //disable flashing
        flashFlag = false;

        //turn LED OFF
        TCCR1A &= ~_BV(COM1B1);
        digitalWrite(onIndicationLED, LEDoff);

      }//if
      
      else
      {
        TCCR1A &= ~_BV(COM1B1);
        OCR1A = c_grBlinkPeriod[frequencyCounter];
        OCR1B = c_grBlinkPeriod[frequencyCounter] >> 1;
        TCCR1A |= _BV(COM1B1);

      }//else

    }//if

  } //END of if (flashFlag == true)

} //END of loop()



void checkSwitches()
{
  //**************************
  //Start switch
  uint8_t currentState = digitalRead(startSwitch);

  //has the switch changed state ?
  if (lastStartState != currentState)
  {
    //update to the new state
    lastStartState = currentState;

    //when we 'are not' flashing, was the switch just pushed/closed ?
    if (flashFlag == false && currentState == PUSHED)
    {
      OCR1A = c_grBlinkPeriod[frequencyCounter];
      OCR1B = c_grBlinkPeriod[frequencyCounter] >> 1;
      TCCR1A |= _BV(COM1B1);

      digitalWrite(onIndicationLED, LEDon);

      //start the x Timer
      xMillis = millis();
      
      //enable flashing
      flashFlag = true;

    }//if
    
//    else if (flashFlag == true && currentState == PUSHED)
//    {
//      //disable flashing
//      flashFlag = false;
//      //turn LED OFF
//      TCCR1A &= ~_BV(COM1B1);
//      digitalWrite(onIndicationLED, LEDoff);
//
//    }//else

  }//if

}//checkSwitches

Push and release the switch:

At 500 milliseconds, what is the frequency on pin D10 (without the capacitor in the circuit).

At 1,500 milliseconds, what is the frequency on pin D10 (without the capacitor in the circuit).

At 2,500 milliseconds, what is the frequency on pin D10 (without the capacitor in the circuit).

larryd:
Push and release the switch:

At 500 milliseconds, what is the frequency on pin D10 (without the capacitor in the circuit).

At 1,500 milliseconds, what is the frequency on pin D10 (without the capacitor in the circuit).

At 2,500 milliseconds, what is the frequency on pin D10 (without the capacitor in the circuit).

Hm I do not have oscilloscope at home but this is what I can do with my multimeter connected and recording to my PC.

No Time DC/AC Value Unit AUTO
23 23:05:59 Freq 1,999 Hz pass
24 23:06:00 Freq 5,998 Hz pass
26 23:06:01 Freq 198,7 Hz pass
34 23:06:06 Freq 0,000 Hz pass