JRA
Posts: 20
Joined: Wed Jan 17, 2018 10:25 pm
Location: Maryland, USA

How to assign hysteresis/Schmitt trigger to an Input?

Fri Jan 19, 2018 3:04 am

I searched here a bit and didn't find anything. I've searched the Net looking for just how in Python to characterize a GPIO Input as having hysteresis or Schmitt trigger behavior. The Pi input structure shows that one can assign hysteresis to an Input along with up-down pulls but I and others can't find how you do that. After hours of googling could I have missed a "how to" example? Is it possible in Python? I'm not a programmer but am asking for another frustrated Linux friend. I thought he was kidding when he told me that none of his resources + Net googling address this. Also thought it was nuts that folks resort to an external Schmitt trigger IC like the 7414 b/c they have a slow-rising/falling signal and need a clean transition for the Pi input. The Pi is supposed to have Schmitt trigger as an Input selection...yes?

User avatar
davef21370
Posts: 890
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: How to assign hysteresis/Schmitt trigger to an Input?

Fri Jan 19, 2018 2:46 pm

According to this site https://www.circuits.dk/everything-abou ... erry-gpio/
GPIO input hysteresis (Schmitt trigger) can be on or off, output slew rate can be fast or limited, and source and sink current is configurable from 2 mA up to 16 mA. See GPIO Datasheet Addendum – GPIO Pads Control.[Ref.4]
But can't find any info on how to set it up so yes & no. Everything seems to point towards using the 74HC14.

Dave.
Apple say... Monkey do !!

User avatar
joan
Posts: 12982
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to assign hysteresis/Schmitt trigger to an Input?

Fri Jan 19, 2018 2:55 pm

Hysteresis is enabled by default on all GPIO. I'm not aware of any software to allow it to be switched off.

https://www.scribd.com/doc/101830961/GPIO-Pads-Control2

JRA
Posts: 20
Joined: Wed Jan 17, 2018 10:25 pm
Location: Maryland, USA

Re: How to assign hysteresis/Schmitt trigger to an Input?

Fri Jan 19, 2018 8:45 pm

Thanks all:
I came across that Errata site in my travels but did not interpret what the author was telling me so I moved on. Is this the only place in the Raspberry Pi landscape where it "seems" the clue is hidden? If so joan, you may be the only person in the Land of Pi to translate this obscure tid-bit as meaning: Hysteresis = Yes by Default. I am not doubting you or teasing you but this information flies in the face of the all too many examples of noobies out there trying to interface a switch to a Pi GPIO pin. Their code is good but they fail with multiple Input events b/c of switch-bounce. So, many long stories short, they employ a capacitor as an open-close switch contact smoother. But they may still have problems with more than one Hi-Lo Input detections. Then the person has to get a 74HC14 Hex Schmitt Inverter and that works, but why? See, if Hysteresis was Set by default then why couldn't that GPIO input handle a ramping signal? IOW, it should have worked, me thinks.

Is it possible that Hysteresis is Set at first during the deep-dark boot setup of the ARMs but then cleared later by higher-level code? I think this case is still open.

User avatar
joan
Posts: 12982
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to assign hysteresis/Schmitt trigger to an Input?

Fri Jan 19, 2018 9:18 pm

pigpio uses the following code to set the pad drive strength.

The constant 0x18 sets the slew and hysteresis bits. Perhaps experiment by not setting one or both bits.

Code: Select all

int gpioSetPad(unsigned pad, unsigned padStrength)
{
   DBG(DBG_USER, "pad=%d  padStrength=%d", pad, padStrength);

   CHECK_INITED;

   if (pad > PI_MAX_PAD)
      SOFT_ERROR(PI_BAD_PAD, "bad pad number (%d)", pad);

   if ((padStrength < PI_MIN_PAD_STRENGTH) ||
       (padStrength > PI_MAX_PAD_STRENGTH))
      SOFT_ERROR(PI_BAD_STRENGTH, "bad pad drive strength (%d)", pad);

   /* 1-16 -> 0-7 */

   padStrength += 1;
   padStrength /= 2;
   padStrength -= 1;

   padsReg[11+pad] = BCM_PASSWD | 0x18 | (padStrength & 7) ;

   return 0;
}

JRA
Posts: 20
Joined: Wed Jan 17, 2018 10:25 pm
Location: Maryland, USA

Re: How to assign hysteresis/Schmitt trigger to an Input?

Sat Jan 20, 2018 5:06 am

Well as you probably know, Pad Strength and Slew Rate are GPIO Output attributes. Are you saying that the Input Hysteresis attribute On-Off control is in the same register? Can you read that register after boot? Seems like you are somewhat deep into it vs. high-level Python. Sorry if I sound over my head. Please remember that I'm a hardware person but know more than some low-level "speak". Please continue and I'll pass pigpio to my friend.

User avatar
joan
Posts: 12982
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to assign hysteresis/Schmitt trigger to an Input?

Sat Jan 20, 2018 8:28 am

Yes they are in the same register (as indicated in the datasheet I linked). There is a corresponding gpioGetPad() function which could be modified to print out all the bits. I guess I probably checked the value of slew and hysteresis were both 1 when I tested but thereagain perhaps I didn't.

It would take someone a few minutes to modify the code and check.

JRA
Posts: 20
Joined: Wed Jan 17, 2018 10:25 pm
Location: Maryland, USA

Re: How to assign hysteresis/Schmitt trigger to an Input?

Sat Jan 20, 2018 10:33 pm

Yes I see what you mean now. So I think that a Write to 0x 7e10 002c with 5A000018 would set Slew to max/normal; enable Hysteresis; set Drive Strength to min/2mA. And those settings would then apply to all GPIOs 0 - 27..? If set to Output in Python, GPIOx would automatically have Slew = Max and Drive = Min, right? If set as an Input, GPIOx would automatically have Hysteresis = On, right? Now, what I'm assuming is that in Python, one may be able to override some of those attributes on a GPIO basis but there is no way in Python to "turn hysteresis on or off". I think what you are telling me is that one has to go poking at a register. True?

I've asked my RPi3B Linux friend if he can peek on address 0x 7e10 002c to see what's there on bits 0:4

If this Hysteresis thing gets too involved in order to get a clean detection from the very slow-rising capacitor charge input I'm giving him he'll just do a s/w de-bounce as part of the "looking for a GPIO7 High level" script and that will do it. The script will run and see the bit high, go away and come back after some milliseconds; read it as high again; do that x times and declare it real. Or, if Low one time then exit and return upon notification of next High. Repeat until all snapshots are True = High. Or something like that in h/w speak.

Any comments on the ? in 1st paragraph?

shadetree01010100
Posts: 29
Joined: Thu Oct 12, 2017 9:19 pm
Location: CO, USA
Contact: Website

Re: How to assign hysteresis/Schmitt trigger to an Input?

Mon Jan 22, 2018 11:49 pm

I've never been able to improve the behavior of the built-in Schmitt triggers, often finding that the hysteresis doesn't quite perform as I expected, and have instead used programmed solutions, similar to what you described.

User avatar
joan
Posts: 12982
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to assign hysteresis/Schmitt trigger to an Input?

Tue Jan 23, 2018 8:20 am

I should mention that pigpio offers a glitch filter which ignores edges shorter than a specified number of microseconds. That could be used to debounce signals.

http://abyz.me.uk/rpi/pigpio/python.htm ... tch_filter

Return to “Python”

Who is online

Users browsing this forum: Paul Hutch, RogerW, vav395 and 22 guests