Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Pulling pin immediately low.

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    2

    Pulling pin immediately low.

    I have externally an IC connected to my Teensy 3.2 which i would like to disable on startup. I have to pull a reset pin on the IC towards ground. However it takes the teensy about 100ms to do this. Is there a way to make this quicker something like 10ms wouldn't be a problem.

    This is my code:

    Code:
    #include <Arduino.h>
    const int Pin_Reset = 14; 
    
    void setup() { 
      pinMode(Pin_Reset, OUTPUT);
      digitalWriteFast(Pin_Reset, LOW); // 100ms have passed until this happens !!
      ...
    I checked how quickly the linear regulator has the 3.3V and that only takes 3 ms or so, so the delay does not result from a slow power supply.
    Last edited by Leakus; 05-28-2020 at 12:37 PM.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,959
    Warning, I am a Software person, so maybe an EE type might give you a better answer.

    Things I would probably try to see if it works include:

    a) Tie the Reset line of the display to reset pin of Teensy? I have done this for a display to make sure the display resets without tying up an IO pin...

    b) Use a weak external Pull Down resistor on the reset line, such that the pin will have a low value at startup until your code actually sets it high.

  3. #3
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,379
    no need to write it low, its low by default when set by pinmode to output, maybe try putting volatile asm "dsb" after pinmode?

    EDIT, a resistor like kurt said is recommended, as the pins are in high-Z whenever teensy is off, rebooted, or reprogrammed

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,910
    As said, a resistor would do it.
    If you don't want it: Take a look at the startup hooks, in startup.c, esp. the early hook.

    Teensy delays the booting, because PCs are not quick enough to detect the new USB-Device, and some I2C chips need a long time, too.

  5. #5
    Junior Member
    Join Date
    Feb 2019
    Posts
    2
    Quote Originally Posted by Frank B View Post
    As said, a resistor would do it.
    I didn't really get it to work with a resistor. Because of the teensy's internal pullup. So I decided to put an RC in the supply of the IC to delay the startup. This works, but seems a little bit of a hack. But I'll probably leave it at that for now.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,838
    As Frank B noted ... and I located and tested in beta ...

    Adding code in the sketch ::
    Code:
    int pList[] = { 0, 1, 6, 7, 2, 3, 4, 5 };
    uint32_t timeSEH = 0;
    extern "C" void startup_early_hook(void) {
      timeSEH = micros();
      pinMode( LED_BUILTIN, OUTPUT );
      digitalWriteFast( LED_BUILTIN, 1 );
      // pin change and set code here
    }
    
    void setup()
    {
      for ( int ii = 0; ii < 4; ii++ ) {
        pinMode( pList[ii], INPUT_PULLUP );
      }
      for ( int ii = 4; ii < 8; ii++ ) {
        pinMode( pList[ii], OUTPUT );
      }
      while (!Serial && millis() < 2000) ; // wait
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      Serial.printf( "startup_early_hook entered at %lu us\n", timeSEH );
    }
    
    void loop() {
      for ( int ii = 0; ii < 4; ii++ ) {
        digitalWriteFast(pList[ii + 4], digitalReadFast(pList[ii]));
      }
    }
    Will happen in under 20 ms. I/O is ready and the systick and cycle counter is running - so millis() and micros() are valid.

    On a T_4.0 here this logged timeSEH at::
    Code:
    T:\tCode\TEST_IO\TEST_IO.ino Jun  2 2020 03:16:17
    startup_early_hook entered at 1391 us
    Tested in above sketch that was currently open - run as is to test - or integrate the BOLD to test.
    That was the longest time I saw on a few tries. Not the Teensy is POWERED some short time doing setup ( code copy from FLASH, CPU set to compile speed, other hardware ) before those clocks are valid.
    If you have a scope you can see if that is good enough - it could be done sooner hacking startup.c::ResetHandler() >> // pin 13 - if startup crashes, use this to turn on the LED early for troubleshooting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •