Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for high current pin configuration #21

Closed
rokweom opened this issue May 4, 2020 · 7 comments
Closed

Support for high current pin configuration #21

rokweom opened this issue May 4, 2020 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@rokweom
Copy link

rokweom commented May 4, 2020

According to the datasheet (page 81 in v1.0.5) some pins can be set to a a high current push-pull configuration, allowing for 80mA, instead of the standard 12/30mA. This can be done by setting a register. Any plans to add support for that? It would be useful for stuff like driving mosfets.

@dbuezas
Copy link
Owner

dbuezas commented Jul 9, 2020

You are right, this is quite interesting. I would rather provide an example sketch though. If you have a tested one, I'll welcome a PR! :)

@dbuezas dbuezas added the help wanted Extra attention is needed label Jul 9, 2020
@rokweom
Copy link
Author

rokweom commented Jul 10, 2020

Actually, my coding skills are really basic and I have no idea how to do it. That's why I was hoping for a simple solution, like pinMode(pin, OUTPUT_HIGHCURR).
There's also a matter of testing if this mode actually works. Question is, how it can be done? Measure pin impedance? Draw high current and see if the pin dies? I'm really not sure.

@dbuezas
Copy link
Owner

dbuezas commented Jul 11, 2020

I may give this a try today. There are only 3 usable pins available though:
Pins D2, D5 and D6.

Also D1 but if you connect it to something else, it may interfere with serial communication (including uploading).

There are two more (E4 and E5), but these are typically left floating in the breakout boards. You could solder wires directly to the chip though.

@dbuezas
Copy link
Owner

dbuezas commented Jul 11, 2020

I just tried it, it only worked on pin D5 and D6. For some reason it had no effect on all other pins. (these need special treatment)

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  digitalWrite(D5, HIGH);
  digitalWrite(D6, HIGH);
/*
  Port F is not defined in the lqfp32 and ssop20 cores, you need to select the lqfp48 core to use these.
  (*) This may bring some incompatibilities. 
  (*) UPDATE: it should be OK, but make sure not to do digitalWrite(F1, HIGH) and digitalWrite(D1, LOW) (or even use Serial)  as this shorts the pins internally and you may kill the board

  pinMode(F1, OUTPUT); // internally connected to D1 in LQFP32 chips
  pinMode(F2, OUTPUT); // internally connected to D2
  pinMode(F4, OUTPUT); // internally connected to E4
  pinMode(F5, OUTPUT); // internally connected to E5

  digitalWrite(F1, HIGH);
  digitalWrite(F2, HIGH);
  digitalWrite(F4, HIGH);
  digitalWrite(F5, HIGH);
*/
}
void loop() {
  HDR = 0b00111111;  // ENABLE high current on the 6 pins
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  HDR = 0b00000000;   // DISABLE high current on the 6 pins
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

For activating each pin individually:

  HDR |= 1 << 0;  // Enable high current D5
  HDR |= 1 << 1;  // Enable high current D6
  HDR |= 1 << 2;  // Enable high current F1/D1
  HDR |= 1 << 3;  // Enable high current F2/D2
  HDR |= 1 << 4;  // Enable high current F4/E4
  HDR |= 1 << 5;  // Enable high current F5/E5

You can test it with a multimeter, it will output ~40ma(*1) in normal mode and ~140ma (*2) in high current mode. Just make sure to do it quickly to avoid risking the board (as you'll be shorting the pin). They don't die THAT fast :)

(*1) using more than 12ma is unsafe
(*2) using more than 80ma is unsafe

Thanks for the issue, I wasn't aware of this and it may come handy :)

@dbuezas dbuezas added documentation Improvements or additions to documentation and removed help wanted Extra attention is needed labels Jul 11, 2020
@rokweom
Copy link
Author

rokweom commented Jul 16, 2020

I just tested it and can confirm PD5 and PD6 work correctly on LQFP32. What about PD2 tho? It works when you enable pinMode(F2, OUTPUT); and digitalWrite(F2, HIGH); and select LQFP48 as the board, but not when you select LQFP32.

@dbuezas
Copy link
Owner

dbuezas commented Jul 17, 2020 via email

@dbuezas
Copy link
Owner

dbuezas commented May 18, 2021

the 80mAh drive is spectacular to drive logic level Mosfets w/o a driver at high speed. Unfortunately the only timer that has "convenient" 80mA pins (in the QFP32) as output is timer0 (D5 and D6), which is the 8 bit timer with less modes and one looses millis() and delay().

Timer 3 can also be used (by enabling the alternate outputs to F1 and F2), but F1 and F2 are exposed as D1 and D2 which are the standard serial pins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants