Attiny824 and SL3416 based brushed esc

I was trying to make a brushed esc for my 720 coreless motor to be used with fs2a receiver from flysky. I had a SL3416 (n channel 6A mosfet), 10k resistor between gate and source, SS24 diode between motor terminals, 10uf+15nf caps across attiny824 vcc and gnd.

However, by mistake I had put a p channel si2301 mosfet in place of SL3416 and tried using it (didnt realize that it was a p mosfet). Since the motor didnt rotate (obv), I realized my mistake and replaced it with the SL3416. This is where I ran into a problem.

With the motor disconnected, the values I get range from 1.5V-3.9V (I was using 1S 550mah 90C HV lipo, charged to 3.9V) and when I put a lighter load (615 coreless motor with 45mm prop, 0.7A continous, 1.5A stall) then the range becomes 0-3V. With the 720 motor, it falls to 0-0.4V.
After probing with the multimeter a bit, I found that the attiny’s pwm pin was the culprit itself. Instead of the full 0-3.9V, it changed with the load.

Why is this happening? If the pin was damaged, shouldnt it not work regardless of the load? I am only using it to drive a mosfet, not the motor itself.

Is there any way I can still use the attiny? Or would I have to bin it?

I tried using a 1k resistor in between Gate and PA5 of the attiny, but nothing changed. I also tried changing the pin from PA5 to PA4, but the result was the same.

As for the code, here it is

// ATtiny824 basic RC-to-PWM test

// PB0 = FS2A receiver throttle input

// PA5 = MOSFET gate PWM output




const uint8_t IN_PIN  = PIN_PB0;

const uint8_t OUT_PIN = PIN_PA4;




void setup() {

  pinMode(IN_PIN, INPUT_PULLUP);

  pinMode(OUT_PIN, OUTPUT);

  analogWrite(OUT_PIN, 0);

}




void loop() {

  unsigned long pulse = pulseIn(IN_PIN, HIGH, 30000);




  if (pulse >= 1000 && pulse <= 2000) {

    uint8_t pwm = map(pulse, 1000, 2000, 0, 255);

    analogWrite(OUT_PIN, pwm);

  } else {

    analogWrite(OUT_PIN, 0);

  }

}

Any help would be appreciated :slight_smile:

Interesting word salad, but an annotated schematic would make it much easier to try and solve your problem.

How do we guess what you did, you do not even know?

Here you go,

#define PWM_PIN PIN_PA5

void setup() {
pinMode(PWM_PIN, OUTPUT);
}

void loop() {
for (int duty = 0; duty <= 255; duty++) {
analogWrite(PWM_PIN, duty);
delay(39);
}

for (int duty = 255; duty >= 0; duty--) {
analogWrite(PWM_PIN, duty);
delay(39);
}
}

I don’t have any schematics with me, any online software recommendation?

Sorry I have no recommendations.

Pen and paper and a posted foto of it usually works well.

Is the pin PWM? If not, it will just be "on" for ten seconds and "off" for ten seconds.

Here is how I use duty cycle on a non-PWM pin...

Click here for code
// #define SERIAL_ON

#define PWM_PIN LED_BUILTIN
int i, freq = 1000;  // 1Hz peak to peak
bool j;

void setup() {
#ifdef SERIAL_ON
  Serial.begin(115200);
  Serial.println("PWM on LED_BUILTIN");
#endif

  pinMode(PWM_PIN, OUTPUT);
}

void loop() {
#ifdef SERIAL_ON
  Serial.print(j);
  Serial.print(" ");
  Serial.print(i);
  Serial.println();
#endif

  if (i >= freq) {  // end of cycle
    j = !j;         // change phase
    i = 0;          // restart cycle
  }

  digitalWrite(PWM_PIN, !digitalRead(LED_BUILTIN));  // invert state

  switch (j) {
    case (0):
      delayMicroseconds(freq * j + i);  // % duty cycle
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
      delayMicroseconds(freq * !j - i);
      break;
    case (1):
      delayMicroseconds(freq * j - i);
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
      delayMicroseconds(freq * !j + i);
      break;
  }

  i++;  // increasing to 100% duty cycle
}

Yes it is. Went through that once, now make sure of it before I solder anything :)

Added in the post now

Could You provide a link to the datasheet of that motor current switching device? I wonder if the low controller voltage manages to make enough motor current flow.

The 10k resistor should sitt between PA4 and GND. The 1k resistor could lower, say around 200 Ohm.

Cant seem to paste the pdf directly here without attaching it as a document. How do I do that?

ds.pdf (699.1 KB)

The 10k is sitting between Source and Gate. The source is directly connected to GND.
I had tried it with both the 1k resistor and without it, but the results were the same. I havent tried it with 200ohm yet, since I dont have any resistor lesser than 1k and they would be arriving in about 2-3weeks

That's not the best. The purpose is discharging the PA4 and keeping the MOSFET off during startup if the PA4 goes in TRI-state.

You can parallell a few 1k until receiving lower values.

Screen-shot the page or export to image using GiMP.

Is it for this case? Usually 10k was the optimum resistor which works (I had experimented with 2.2k and 1k before).

It's for every case using a MOSFET for driving just anything but You put it in the wrong place, not the optimal place.

UPDATE:
I tried using a NPN transistor in between the mosfet and pwm pin. While this successfully took away the problem, I had to invert the pwm from the attiny as well as connect the mosfet Gate to +ve via 10k.