Go Down

Topic: ESP32 passive peizo buzzer (Read 4062 times) previous topic - next topic

manveen_singh

I have told you in a thread before that the gate threshold is the point where the FET is OFF, not the point where it is fully on.
I have asked this question in my post also.

If we give Vgs below threshold it will turn off,
If we give Vgs above threshold it will turn on (partially) .
Am i correct in assuming the above statements?

I have told you in a thread before

That is why i have not suggested any particular mosfet for that. if you had not told me about that in my last post. i would have also suggested my own mosfet.

The reason i have suggested an n channel mosfet is because many electronic books also suggest this.

Grumpy_Mike

#16
Dec 21, 2018, 02:50 pm Last Edit: Dec 21, 2018, 02:59 pm by Grumpy_Mike
Quote
And even If i am wrong ,someone more with knowledge than me about the matter can correct me
I thought that was what I was doing, or do I not count.

Quote
(or maybe you were feed up of me and did not care to post to that thread.)
Yes I indicated that, given your attitude I would not even read the thread.

Quote
If we give Vgs below threshold it will turn off,
If we give Vgs above threshold it will turn on (partially) .
Am i correct in assuming the above statements?
Yes but more accurately:-
If we give Vgs above threshold it will start to just turn on.
There is no saying by how much it will turn on as FET parameters in this region are not guaranteed by the manufacturers. The curves are "typical" and no real device is typical, all are above or below it. You have to go on the parameters they give. For that FET I recall that only at 4.5V can they guaranteed the turn on resistance is 6 ohms, which is quite high for a FET.

So while operating this FET for you with the devices you have might be fine. If you want the design to be solid and work for everyone who uses that circuit, or even that FET and that drive voltage you have to use a better FET.

manveen_singh

I thought that was what I was doing, or do I not count.

Obviously you do count.
Right now you are doing your part in my learning process :

someone more with knowledge than me about the matter can correct me .

and i am doing this part :

that is why I question everything others suggest.
So i can finally do this :
Thus i can learn from my mistakes and give the correct advice and help the next time.

Yes I indicated that, given your attitude I would not even read the thread.

If you think that is the problem, As i have stated earlier , i will be even more careful next time.

 
NOW COMING BACK,

according to that datasheet:

In electrical char.

Vgs threshold  = 1.3 v
and Id (on)  =200 mA

What will happen happen if i give Vgs =3.3v , i know mosfet will turn on partially. so how will this affect my system ? how does the partially turned on mosfet affect my driven system ?

The new Id (on) will less right ?

lets say my new Id (on) becomes 100mA . but my whole system requires only 50 mA then how will my system be affected ?

And how does Rds on come into play ?
The curves are "typical" and no real device is typical, all are above or below it.
Then why do manufacturers bother to put all typical curves in the datasheet if typical curves cant be used or trusted?

Grumpy_Mike

#18
Dec 22, 2018, 07:23 am Last Edit: Dec 22, 2018, 07:25 am by Grumpy_Mike
Quote
i know mosfet will turn on partially. so how will this affect my system ? how does the partially turned on mosfet affect my driven system ?
When a FET is not fully on it is in what is called the linear mode. In this mode it acts as a variable resistor. That means that the current through it is going to be limited by the value of resistor the FET is presenting to the rest of the circuit. It also means that any current passing through the FET will cause heating of the FET to the value of

Watts = Current2 * R

So the heating increases rapidly with the square of the current.

Quote
and Id (on)  =200 mA
That is the absolute maximum you can drive through the FET without damaging it. However that value for a FET is often misleading. Because before you reach that value any heating will have fried the component before that current is reached.
The maximum power dissipation is shown as 0.36W, but that is only if you can keep the ambient temperature below 25oC, anything above that and you have to de-rate that value ( that means reduce it ) to the tune of 2.8mW per degree C. The note on this parameter also says:-
Quote
RθJA is the sum of the junction-to-case and case-to-ambient thermal resistance where the case thermal reference is defined as the solder mounting surface of
the drain pins. RθJC is guaranteed by design while RθCA is determined by the user's board design.
For every 10 degrees you can reduce the junction temperature of any semiconductor device, the expected life time of that device doubles. So it is important that a component runs as cool as possible. 

Quote
And how does Rds on come into play ?
This is the resistance between the drain and source that we are talking about. The data sheet says this is going to be 6R if you can put a 4.5V signal on the gate and you have 220mA through the FET. This reduces to 3.5R if you can increase the signal to 10V.

Quote
Then why do manufacturers bother to put all typical curves in the datasheet if typical curves cant be used or trusted?
Good point. When you design a circuit for mass production you usually assume the worse case parameter. But it is useful to know how a parameter can change at values other than the guaranteed ones, and also to look at different conditions for that parameter. If you look at Figure 4, this shows how the Rds changes with gate voltage for a different drain current than the one quoted in the specifications. You will see that for a smaller current ( 100mA as opposed to 220mA ) the Rds is smaller. As a designer you have to look at that curve and treat it as the typical case. Then look back at the guaranteed conditions and apply the worst case for that design. This is where design skills come in, it is not a simple process and depends on the whole design.

You need to look at all the graphs to see how the component behaves. For example figure 1 shows you the behavior of the FET in the linear region. You will see how at 3V it is linear and at 3.5V it is starting to become saturated. As there is no curve for 3.3V you would have to interpolate between the two curves give.

SviFi

Thank you Val42 !! Your simple tone() function resolves it before they fix it. Very simple and straight to the point! Fantastic! :-)



While searching for a better solution for my original problem, I came across ESP32 Arduino: Controlling a buzzer with PWM.  In summary, even though the ESP-32 libraries don't have a tone(), they do have other functions that will let you do the equivalent.

Code: [Select]

#define BUZZER_PIN          13

#ifdef    ARDUINO_ARCH_ESP32

#define SOUND_PWM_CHANNEL   0
#define SOUND_RESOLUTION    8 // 8 bit resolution
#define SOUND_ON            (1<<(SOUND_RESOLUTION-1)) // 50% duty cycle
#define SOUND_OFF           0                         // 0% duty cycle

void tone(int pin, int frequency, int duration)
{
  ledcSetup(SOUND_PWM_CHANNEL, frequency, SOUND_RESOLUTION);  // Set up PWM channel
  ledcAttachPin(pin, SOUND_PWM_CHANNEL);                      // Attach channel to pin
  ledcWrite(SOUND_PWM_CHANNEL, SOUND_ON);
  delay(duration);
  ledcWrite(SOUND_PWM_CHANNEL, SOUND_OFF);
}

#endif


This code is in an example program that I wrote.  I found what is defined when the IDE compiles for ESP-32.  "Show verbose output during: [ ] compilation" will show you too.  This allows me to use the same code for ESP-32 or Arduino UNO.

Since the PWM channel can be 0-15, I tried running three piezo buzzers at the same time at different frequencies.  I got only one frequency out though.  I'm thinking that the PWM can only run at one frequency at a time, but I'm still looking into this.

Code: [Select]

int buzzer_pin[] = {13, 12, 14};

void tones(int freq1, int freq2, int freq3, int duration)
{
  // Set up pins
  ledcSetup(SOUND_PWM_CHANNEL+0, freq1, SOUND_RESOLUTION);  // Set up PWM channel
  ledcAttachPin(buzzer_pin[0], SOUND_PWM_CHANNEL+0);        // Attach channel to pin

  ledcSetup(SOUND_PWM_CHANNEL+1, freq2, SOUND_RESOLUTION);  // Set up PWM channel
  ledcAttachPin(buzzer_pin[1], SOUND_PWM_CHANNEL+1);        // Attach channel to pin

  ledcSetup(SOUND_PWM_CHANNEL+2, freq3, SOUND_RESOLUTION);  // Set up PWM channel
  ledcAttachPin(buzzer_pin[2], SOUND_PWM_CHANNEL+2);        // Attach channel to pin

  // Sound buzzers
  ledcWrite(SOUND_PWM_CHANNEL+0, SOUND_ON);
  ledcWrite(SOUND_PWM_CHANNEL+1, SOUND_ON);
  ledcWrite(SOUND_PWM_CHANNEL+2, SOUND_ON);

  delay(duration);

  ledcWrite(SOUND_PWM_CHANNEL+0, SOUND_OFF);
  ledcWrite(SOUND_PWM_CHANNEL+1, SOUND_OFF);
  ledcWrite(SOUND_PWM_CHANNEL+2, SOUND_OFF);
}



I could have made a mistake in this code (for multiple tones), but I don't see it.

Go Up