Author Topic: Minimize start-up time  (Read 5533 times)

gmen

  • Newbie
  • *
  • Posts: 5
Minimize start-up time
« on: October 29, 2016, 01:15:48 am »
Hello all!

I have a Digispark Pro controlling parts of a music box. One of these parts is a pc fan with a PWM-in signal, which I use to a very low point (~10%). When the switch powers the entire circuit, the digispark waits its 5 secs before starting. In the meantime, the digital pin is low. However, when my fan reads a zero in the PWM, it assumes no connection and starts working at 100%. This effect is undesirable. Could I program the pro to wait far less in the beginning? (maybe .1 secs?) Can you propose any other solution? I thought of adding a fet and control the fan's power also from another digital pin....but I have very restricted space, so if it can be avoided, it will be better. Any of your help will be appreciated!

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Minimize start-up time
« Reply #1 on: October 29, 2016, 06:05:18 pm »
There was a alternative bootloader for the Digispark (original) that would only run when a pin (P1? P5? can't remember which now) was connected to GND (so it would only be programmable when that pin was grounded), which mean there was no need for the 5 second delay anymore. However, I can't see any mention of that functionality being made available on the Pro... Ralf seems to be more on top of things Pro related (I just dabble ;) ) , so maybe he will comment on this?

gmen

  • Newbie
  • *
  • Posts: 5
Re: Minimize start-up time
« Reply #2 on: October 31, 2016, 05:43:07 pm »
That would be SO good!!!

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Minimize start-up time
« Reply #3 on: November 02, 2016, 05:07:54 pm »
I haven't tried it, but it looks like the configuration options are still there in the bootloader configuration file. If I remember, I'll try compiling that later today to see if that works still. Looks promising though.

Edit: Ok, I did try it, and it *appears* to be working ok - I'm just running a simple blink sketch, and it is now running instantly rather than after a five second delay. And to program the Pro again, I connect P0 (PB0) to GND and either press reset, or cycle the power on the Digispark Pro.

I basically cloned the micronucleus GIT repo, fixed up my compile toolchain so it would compile, copied the t167_default config folder to t167_jumper (not really necessary), edited the bootloaderconfig.h on 126 to say ENTRY_JUMPER, and then ran make CONFIG=t167_jumper to compile it. I then used a USBasp programmer to load that to the Digispark Pro. If you follow the instructions on the wiki for replacing the Bootloader, it shows you how to use an arduino instead if you don't have a usbasp or similar, and you can just substitute the bootloader for the custom jumper one. If P0 isn't practical for you, it can be changed, just need to let me know which pin you want instead.

« Last Edit: November 02, 2016, 06:19:04 pm by PeterF »

gmen

  • Newbie
  • *
  • Posts: 5
Re: Minimize start-up time
« Reply #4 on: November 15, 2016, 03:00:44 am »
A great thank you sir! These things were a bit terrifying at first, but it works like a charm now.
Since you offered an alternative hex, using another pin, how about this.
I use the arduino IDE to program my pro. I click upload, wait for compile, then it says "Plug in your board now". I do so, and it starts uploading.
No need for either 5 sec wait or any pin tied to GND. Can you make it work like that and then immediately start the user program?
Else, please make me a hex for one of the less digital functionality-providing pins, ie PA3 or PA7 (I don't have much need for analog)
« Last Edit: November 15, 2016, 05:50:36 am by gmen »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Minimize start-up time
« Reply #5 on: November 15, 2016, 07:17:26 pm »
For option 1, probably the most you could do is shorten the delay (I guessing 1 sec would still be long enough?), as it is needed as otherwise there is not enough time for the USB to be initialised, the device recognised, and then the program upload started.

Regarding option 2, I don't see that being a problem... I'll see what the code lets me do ;) Then you can just have a momentary press button that you hold when you turn on the digispark to put it into programming mode, or when the button isn't held it starts the user sketch immediately.

gmen

  • Newbie
  • *
  • Posts: 5
Re: Minimize start-up time
« Reply #6 on: November 25, 2016, 09:04:26 am »
Bump! Got any news for me?

If someone could point me in a relatively easy to understand direction of how to do this myself I would be as grateful. The main difficulty in understanding is what comprises the "compile toolchain". Is there any tutorial for this?

Sorry for the persistence, but I need the I2C interface on pins PB0,PB2, and thus can't have them be the bootloader check ones.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Minimize start-up time
« Reply #7 on: November 27, 2016, 09:41:29 pm »
Apologies... I completely forgot about this... I'll look into it within the next day or so.

Toolchain wise... A linux box is the path of least resistance ;) I cloned the micronucleus repo from github using git to my system, and then went and editied the bootloaderconfig.h file in the firmware/configuration/t167_default folder. Then ran the firmware/makerelease.bat file (or run the below commands to generate just the relevant firmware).

Code: [Select]
make clean
make CONFIG=t167_default
cp main.hex releases/t167_default.hex

Edit: Sooner rather than later ;) I haven't tested these whatsoever yet... so use at your own risk! :D I have simply changed the four pin constants relating to the pin to use as a jumper pin, and it has successfully compiled. Please let me know how you go if you do try them. I will be a couple of days until I get around to pulling my Pro to see if it breaks works!
« Last Edit: November 27, 2016, 10:33:01 pm by PeterF »

gmen

  • Newbie
  • *
  • Posts: 5
Re: Minimize start-up time
« Reply #8 on: November 28, 2016, 02:33:59 am »
I didn't test the PA3 version, but the PA7 works. Thank you SO much!
I believe these hexes should be uploaded in an appropriate tutorial section, what I needed seems like common stuff.
« Last Edit: November 28, 2016, 03:50:12 pm by gmen »