Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MOSFET switching issue

Status
Not open for further replies.

earckens

Member
In the attached schematic MOSFET Q3 is switched one once a minute during a few seconds. The issue is that as soon as the gate is triggered to switch the MOSFET on, it stays on. Only when I attach a scope probe to the gate, does the MOSFET switch off when it must go off.

Any suggestion on design improvement?

Thanks!

EDIT: D9, 10 and 11 all trigger the same signal out. The issue I have is even there with only one output connected to the gate.
 

Attachments

  • soil moisture sensor Low Frequency_v1_sch.pdf
    29.1 KB · Views: 159
The MOSFET appears to be labeled 1N60 which is a diode!! What MOSFET is it?

You're driving the gate with 3 I/O pins, do you drive these low to turn it off or switch them to input? What voltage are the I/O working at?

Can I add that this is the most unconventional schematic I've seen in a while.

Edit, LED3 seems to be connected between AGND and GND!!! What is AGND?

Mike.
 
Last edited:
The I/O output level is 0 to 5V. The 1N60 datahseet is attached.
 

Attachments

  • 1N60 MOSFET n-channel TO92 low power.pdf
    361.7 KB · Views: 130
Agnd is the ground for the ADC module.
And the 1N60 i think comes in a 3 pin package the center not used tho.
MCIGICM-10pcs-CS1N60-1N60-TO-92-N-Channel-Power-MOSFET-0-8A-600V.jpg_640x640.jpg

Like those
funny this is what there calling them
MCIGICM 10pcs CS1N60 1N60 TO-92 N-Channel Power MOSFET 0.8A 600V
**broken link removed**
600V/32526022646.html
There a diode I have some I got to play with a crystal radio.
I have the glass ones but I seen the 3 pin I just looked there they where.
 
Last edited:
How do you simultaneously switch 3 I/O lines without getting a conflict?

Your MOSFET appears to connect AGND and GND!! What is AGND?

Mike.
 
How do you simultaneously switch 3 I/O lines without getting a conflict?

Your MOSFET appears to connect AGND and GND!! What is AGND?

Mike.
In the schematic the source and drain are wrong, A-GND is general ground, GND is to be connected to A-GND when the mosfet is switched. In effect, the Vcc must go through the load, then to GND, and through the mosfet drain to source to A-GND.
When connected like that on a prototype board it works, except again for the parasitic behavior of the gate described above.
 
1N60 is not a
TO-92 N-Channel Power MOSFET 0.8A 600V
It's diode that just happens to come in a TO-92 case
 
The source is connected to GND not AGND! As I said, an unusual schematic which I'm struggling to understand.

Again, How do you simultaneously switch 3 I/O lines without getting a conflict? Show us the code.

Mike.
 
The source is connected to GND not AGND! As I said, an unusual schematic which I'm struggling to understand.

Again, How do you simultaneously switch 3 I/O lines without getting a conflict? Show us the code.

Mike.
Hi, even with the protoype board and only one digital output connected this issue is present.

A 100nF cap just added between gate and source does not help.

Code:
Code:
// https://www.instructables.com/id/Arduino-Sleep-and-Wakeup-Test-With-DS3231-RTC/
// Arduino wake-up with DS3231
// corrected the library for use with Atmega168P
// corrected by: https://github.com/rocketscream/Low-Power/issues/45
// and also: https://github.com/rocketscream/Low-Power/issues/14
// connect DS3231 pin INT/SQW to D2 on Arduino (INT0, PCINT18, PD2)
// v8: includes ethernet shield and upload to Thingspeak
//    code from https://github.com/iobridge/ThingSpeak-Arduino-Examples/blob/master/Ethernet/Arduino_to_ThingSpeak.ino
// and for two values: https://community.particle.io/t/uploading-sensor-data-to-thingspeak/5497
// V9: modified for transmission over HC12 via hardware serial
//   1. prepare values for transmission: int sendDutyCycle, time and date
//   2. serialPrint only what needs to be transmitted
//   3. includes Thingspeak code
//   4. send 3 integers: humidity %, minute, hour and sensor identification (A, B, ..)
//
// V10: code without thingspeak, no ethernet module, and cleaned up
// status: 1/12/17: tested ok
// V11: send 4 integers: duty cycle %, temperature, minute, hour and sensor identification (A, B, ..)


#include <Wire.h>
#include <RTClibExtended.h>
#include <LowPower.h>
// #include <SPI.h> //Thingspeak
#define DS3231_I2C_ADDRESS 0x68
RTC_DS3231 RTC;      //we are using the DS3231 RTC

// Variable Setup
// NOTE: pin D8 is used for reading incoming square wave for duty cycle measurement

long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
int wakePin = 2;    //use interrupt 0 (pin 2) and run function wakeUp when pin 2 gets LOW
int ledPin = 13;    //use arduino on-board led for indicating sleep or wakeup status
int wakeStatus = 11; //use D10 to drive 5V power to sensor module and HC-12 with MOSFET, 1=wake
int temperaturePin = A0; // analog input for LM35 temperature sensor
byte goToSleepNow = 1;
byte ledStatus = 1;
volatile word timerValue[4];
volatile byte testState = 0;
volatile boolean signalPresent = false;
boolean newValuesAvailable = false;
float pwmPeriod, pwmWidth, pwmFrequency, pwmDutyDisplay;
unsigned long pwmDuty;
const byte x = 10; // loop value: loop amount = x
int sendDutyCycle;  // contains integer value of float cycleValue
int dutyCycleStatus = 8;
int temperatureT1 ;

//-------------------------------------------------

void wakeUp()        // here the interrupt is handled after wakeup
{
}

//------------------------------------------------------------

void setup() {
  //Set pin D2 as INPUT for accepting the interrupt signal from DS3231
  pinMode(wakePin, INPUT);
  //switch-on the on-board led for 1 second for indicating that the sketch is ok and running
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  digitalWrite(wakeStatus, LOW);
  delay(1000);
  //Initialize communication with the clock
  Wire.begin();
  RTC.begin();
  // A convenient constructor for using "the compiler's time":
  // DateTime now (__DATE__, __TIME__);
  // uncomment following line when compiling and uploading,
  // then comment following line and immediately upload again

  // RTC.adjust(DateTime(__DATE__, __TIME__));   //set RTC date and time to COMPILE time, see instructions above

  //clear any pending alarms
  RTC.armAlarm(1, false);
  RTC.clearAlarm(1);
  RTC.alarmInterrupt(1, false);
  RTC.armAlarm(2, false);
  RTC.clearAlarm(2);
  RTC.alarmInterrupt(2, false);
  //Set SQW pin to OFF (in my case it was set by default to 1Hz)
  //The output of the DS3231 INT pin is connected to this pin
  //It must be connected to arduino D2 pin for wake-up
  RTC.writeSqwPinMode(DS3231_OFF);
  //example: Set alarm1 every day at 18:33: 00 seconds, 33 minutes, 18 hours, 0 = every day;
  // if for example Sunday then: dowSunday if a date then date of the month
  //
  // see for explanation: https://github.com/JChristensen/DS3232RTC#alarm-methods
  RTC.setAlarm(ALM1_MATCH_SECONDS, 30, 00, 0, 0);   //set your wake-up time here:
  // every 00 minutes past the hour;
  // if every minute is needed change MINUTES to SECONDS
  // matches seconds AND minutes when _MINUTES is used. Sequence of time:
  // first seconds, then minutes, hours, daydate
  // or: seconds (but enter 00, is ignored), minutes then hours, daydate for ALM2
  // zero's mean: always
  // example: Set alarm1 every day at 18:33
  // RTC.setAlarm(ALM1_MATCH_HOURS, 33, 18, 0);  set your wake-up time here
  // RTC.alarmInterrupt(1, true);

  RTC.alarmInterrupt(1, true); //set alarm1
 
  Serial.begin(115200);
}

//------------------------------------------------------------

void loop() {

  //On first loop we enter the sleep mode
  if (goToSleepNow == 1) {                                 // value 1 = go to sleep
    attachInterrupt(0, wakeUp, LOW);                       //use interrupt 0 (pin PD2) and run function wakeUp when pin 2 gets LOW
    digitalWrite(ledPin, LOW);                             //switch-off the led for indicating that we enter the sleep mode
    ledStatus = 0;                                         //set the led status accordingly
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);   //arduino enters sleep mode here
    detachInterrupt(0); //execution resumes from here after wake-up
    //test signal jumper pin 7 to pin 8
    //tone(7,2400);
    //digitalWrite(7,HIGH);
    //digitalWrite(7,LOW);
    //When exiting the sleep mode we clear the alarm
    RTC.armAlarm(1, false);
    RTC.clearAlarm(1);
    RTC.alarmInterrupt(1, false);
    goToSleepNow = 0;                                      // value 0 = do not go to sleep
  }

  //cycles the led to indicate that we are no more in sleep mode
  if (ledStatus == 0) {
    ledStatus = 1;
    digitalWrite(ledPin, HIGH);
  }
  digitalWrite(wakeStatus, HIGH);  // set wakeStatus to HIGH, wake mode
  delay (1000);
  measure(); //execute duty cycle measurement during wakeUp
  delay (500);
  digitalWrite(wakeStatus, LOW);                       //initiate wake status LOW, sleepmode
  goToSleepNow = 1;
  RTC.alarmInterrupt(1, true);
}

void measure()
{
  DateTime now = RTC.now();
  temperatureT1 = analogRead(temperaturePin);
  int repeat1 = 0;
  unsigned long signalMax1 = 0; // max value for duty cycle
  unsigned long signalMin1 = 1000000; // min value for duty cycle
  // unsigned long currentMillis = millis();
  unsigned long cycleTotal = 0;
  float cycleValue = 0;

  while (repeat1 < x)
  {
    getPwmValues();
    if (newValuesAvailable)
    {
      repeat1++;
      newValuesAvailable = false;
      if (signalPresent)
      {

        if (pwmDuty < signalMin1) signalMin1 = pwmDuty;
        if (pwmDuty > signalMax1) signalMax1 = pwmDuty;
        cycleTotal += pwmDuty;
        pwmDutyDisplay = pwmDuty / 1000.0;
      }
    }
  }
  if (signalPresent)   // if signal is present
  {
    DateTime now = RTC.now();
    cycleTotal -= signalMin1;
    cycleTotal -= signalMax1;
    cycleValue = cycleTotal / 1000.0 / (x - 2);

    Serial.print('<'); // this section for HC-12 transmission
    Serial.print(cycleValue);  // ref Robin2's Serial Output Basics
    Serial.print(',');   // http://forum.arduino.cc/index.php?topic=396450.0
    Serial.print(temperatureT1); // send temperature read from analog input temperaturePin
    Serial.print(',');
    Serial.print(now.minute(), DEC); // send minute
    Serial.print(',');
    Serial.print(now.hour(), DEC); // send hour
    Serial.print(",B>"); // send sensor identifier
  }
  else   // if no signal is present
  {

    if (digitalRead(dutyCycleStatus) == true)  //if true then 5V present on pin 8, sensor present
    {
      Serial.print('<'); // this section for HC-12 transmission
      Serial.print(",100");  // ref Robin2's Serial Output Basics
      Serial.print(',');   // http://forum.arduino.cc/index.php?topic=396450.0
      Serial.print(temperatureT1); // send temperature read from analog input temperaturePin
      Serial.print(',');
      Serial.print(now.second(), DEC);
      Serial.print(',');
      Serial.print(now.minute(), DEC);
      Serial.print(",B>");
    }

    else        //if false then 0V on pin 8 then there is hardware error
    {
      Serial.print('<'); // this section for HC-12 transmission
      Serial.print(",0");  // ref Robin2's Serial Output Basics
      Serial.print(',');   // http://forum.arduino.cc/index.php?topic=396450.0
      Serial.print(temperatureT1); // send temperature read from analog input temperaturePin
      Serial.print(',');
      Serial.print(now.second(), DEC);
      Serial.print(',');
      Serial.print(now.minute(), DEC);
      Serial.print(",B>");
    }
  }
}

void pwmMeasureBegin()
{
  for (byte j = 0; j < 4; j++)
  {
    timerValue[j] = 0;
  }

  TCCR1A = 0;       // normal operation mode
  TCCR1B = 0;       // stop timer clock (no clock source)
  TCNT1  = 0;      // clear counter
  TIFR1 = bit (ICF1) | bit (TOV1); // clear flags
  testState = 0;   // clear testState
  signalPresent = false; //reset
  TIMSK1 = bit (ICIE1); // interrupt on input capture
  TCCR1B =  bit (CS10) | bit (ICES1);// start clock with no prescaler, rising edge on pin D8
}

ISR (TIMER1_CAPT_vect)
{
  signalPresent = true;
  switch (testState) {
    case 0: // first rising edge
      timerValue[0] = ICR1;
      testState = 1;
      break;
    case 1: // second rising edge
      timerValue[1] = ICR1;
      TCCR1B &=  ~bit (ICES1); // capture on falling edge (pin D8)
      testState = 2;
      break;
    case 2:  // first falling edge
      testState = 3;
      break;
    case 3: // second falling edge
      timerValue[2] = ICR1;
      testState = 4;
      break;
    case 4: // third falling edge
      timerValue[3] = ICR1;
      testState = 5;  // all tests done
      TCCR1B = 0; //stop timer
      break;
  }
}

void getPwmValues()
{
  static boolean measurementInProcess = false;

  if (!measurementInProcess)
  {
    pwmMeasureBegin();
    measurementInProcess = true;
    delay(50);//time for signalPresent to be set
  }
  else if (testState == 5 || !signalPresent)//measurement complete or noSignal
  {
    if (!signalPresent)
    {
      //      Serial.println("100% duty cycle. No PWM signal, zero data");
      //      float cycleValue = 100.0;
      //      Serial.print(cycleValue, 3);
      //      Serial.println(" %");
      //      displayTime();
      //      Serial.println();
      //      Serial.println();
    }
    calculatePwmValues();
    measurementInProcess = false; //reset
  }
}

void calculatePwmValues()
{
  word periodValue = timerValue[3] - timerValue[2];
  // word is the same as unsigned int
  word widthValue = timerValue[2] - timerValue[1];
  word diffValue = widthValue - periodValue;

  pwmPeriod = (periodValue * 0.0625);
  pwmWidth = diffValue * 0.0625;
  pwmDuty = (pwmWidth / pwmPeriod) * 100000;
  pwmFrequency = 1000 / (pwmPeriod);

  newValuesAvailable = true;
}
 
I don't want to wade through all your code I just wanted the bit where it switches the pin(s) off.

Does a 10k resistor from gate to source solve the problem?

Mike.
 
I don't want to wade through all your code I just wanted the bit where it switches the pin(s) off.

Does a 10k resistor from gate to source solve the problem?

Mike.
Removed the cap, added 10k between G and S, I measure controller output no higher than 1V when switched. Same when assigned different controller outputs.
When I force the mosfet with 5V from the supply at the gate, it switches ok. When I measure controller outputs when disconnected from gate, all outputs switch to 5V when activated.

Defective mosfet?
 
The fet needs to be a logic level one, and your scem doesnt show a pull down on the gate, if the micro has push pull o/p's thats fine, however if the micro only pulls up and goes high imp when off thats why your load doesnt switch off.
Do you have a logic probe?, if so bung it on the o/p from the micro to the fet gate, if it stays high then you've a software issue, if it goes logic high to neither a logic high or low then the above is the case.
 
The fet needs to be a logic level one, and your scem doesnt show a pull down on the gate, if the micro has push pull o/p's thats fine, however if the micro only pulls up and goes high imp when off thats why your load doesnt switch off.
Do you have a logic probe?, if so bung it on the o/p from the micro to the fet gate, if it stays high then you've a software issue, if it goes logic high to neither a logic high or low then the above is the case.
Hi, the controller output is low impedance, so unless the drawn current is too high (>20mA) it will go high.
The issue I see is that when connected to the gat 150R resistance the output does not even go higher than 1V. You have a point when you hint at output issues too: however, any output I use, this issue shows up (by the way, pwm is not involved, I use purely high or low output values).
Current status: when forcing the mosfet high or low at the gate using direct 5V potential, the mosfet switches ok regardless of a oscilloscope present on the gate or not. Currently a 10k resistor is connected between G and S.
When using any controller output I get 1V max only at the gate.
 
My initial impression (since deleted as Pommie in post 10 said effectively the same thing) was that you needed a turn-off resistor.* It is bothersome that with a 10k resistor on an output pin you only read 1 V. EDIT: Is that read with a scope or with a voltmeter? If voltmeter, you are probably just seeing an average.

An output pin should be able to drive more than that. Also noted that D10 (Arduino) is Atmega !SS pin. Are you sure that function is turned off?

Can you completely disconnect D10 and D11 and leave only D9 attached to your mosfet?


*Some programs toggle the impedance (i.e., input vs output) state of a pin instead of toggling the logic state of an output pin.
 
Last edited:
My initial impression (since deleted as Pommie in post 10 said effectively the same thing) was that you needed a turn-off resistor.* It is bothersome that with a 10k resistor on an output pin you only read 1 V. EDIT: Is that read with a scope or with a voltmeter? If voltmeter, you are probably just seeing an average.

An output pin should be able to drive more than that. Also noted that D10 (Arduino) is Atmega !SS pin. Are you sure that function is turned off?

Can you completely disconnect D10 and D11 and leave only D9 attached to your mosfet?


*Some programs toggle the impedance (i.e., input vs output) state of a pin instead of toggling the logic state of an output pin.
Measured with scope.
The output pins used for this function are configured digital output (no pwm).
Yes, I currently work off prototype board with one output only connected to G.
 
Two things...
A) Check Burt's suggestion where your mosfet may be a diode...
B) Check out Mike's theories.... If the outputs are not switched together ( which they are not ) all three pins may be damaged... This means if the device is a mosfet, the switching will now be indeterminate...

Also... I had a great difficulty switching a mosfet at low voltage.. I had to use one of these ONSEMI MGSF2N02ELT1G
 
Another quick one, is the voltage on the gate below the avalanche level for the fet, if not while static while switching, that would hold it on.
If theres any inductance in the load that could mess you up.
 
:confused: If I'm reading the schematic correctly you are using the Arduino outputs D9-11 to drive the FET which switches AGND to GND; but the Arduino ground is AGND and the 5V regulator ground is also AGND, so aren't you effectively asking the Arduino to turn itself and its power supply on ??
 
If what he really has is a 1N60 it's not a Fet It's a diode that come's in a 3 pin package and seeing the poster not saying if for sure it's a 1N60.

Not said nothing just blowing over good deal
I no they sell them saying there mosfet

Cause I got a bag of 50 1N60 there diodes and when looking i found some in 3 pin package

Now if you got really one of these
http://www.unisonic.com.tw/datasheet/1N60.pdf
it would never work for what your trying to do.
 
:confused: If I'm reading the schematic correctly you are using the Arduino outputs D9-11 to drive the FET which switches AGND to GND; but the Arduino ground is AGND and the 5V regulator ground is also AGND, so aren't you effectively asking the Arduino to turn itself and its power supply on ??
A-GND is the main ground, for the power supply (Vcc), for the Arduino, for the whole circuit.
GND is ground for anything that needs to be powered on or off by the MOSFET: switching the gate means connecting GND to A-GND, means powering up anything connected to GND.
Note: drain and source in the schematic need to be reversed.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top