Christoph1985
Posts: 63
Joined: Sat Jul 28, 2012 11:58 am
Location: Germany

gpio_slew and gpio_hysteresis?

Tue May 19, 2015 10:09 am

Hello,

can somebody please explain, what slew and hysteresis are for?
These are parameters you can find in the eeprom settings.
In which cases will I need this settings?

gpio_drive sets the maximal current for all usable GPIO pins? (for ex. 16 mA per pin?)

Thanks in advance

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: gpio_slew and gpio_hysteresis?

Tue May 19, 2015 11:44 am

Read the datasheet for your particular sensor. If you can read the datasheet as pdf all the better; you can 'find' "hysteresis" throughout the document.

You might also want to try googling for 'hysteresis' and read-up!
marcus
:ugeek:

User avatar
Burngate
Posts: 5470
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: gpio_slew and gpio_hysteresis?

Tue May 19, 2015 3:55 pm

Hysteresis (for a digital input): a change from 0 to 1 occurs at a higher input voltage than a change from 1 to 0. There's never an input voltage that's undetermined.
Without hysteresis, there can be an input voltage that may produce either 0 or 1

Slew rate (for an output): in the real world it takes time for a pin to change from one state to another. In between, it's neither one nor t'other.
Because all real circuits have capacitance (and inductance, resistance, etc.) and to change a pin's voltage requires the capacitance to charge, large currents can flow.
Among other things, that can cause interference on adjacent wires. Limiting the rate at which the voltage changes reduces those problems, at the expense of more time before it's valid.

boyoh
Posts: 1175
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: gpio_slew and gpio_hysteresis?

Tue May 19, 2015 5:00 pm

Christoph1985 wrote:Hello,

can somebody please explain, what slew and hysteresis are for?
These are parameters you can find in the eeprom settings.
In which cases will I need this settings?

gpio_drive sets the maximal current for all usable GPIO pins? (for ex. 16 mA per pin?)

Thanks in advance
Slew rate is when signal may be slow in changing
from one state to a nother
The speed that signal changes can be speeded
up by using a circuit called a Schmitt trigger,
You could call it a snap action ( Hysteresis.)
It is as if a rising signal is kicking It's self
up It's backside, A blunt way of putting It,
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1786
Joined: Thu Jul 11, 2013 2:37 pm

Re: gpio_slew and gpio_hysteresis?

Mon May 25, 2015 4:26 pm

Burngate wrote:Hysteresis (for a digital input): a change from 0 to 1 occurs at a higher input voltage than a change from 1 to 0. There's never an input voltage that's undetermined.
Without hysteresis, there can be an input voltage that may produce either 0 or 1

Slew rate (for an output): in the real world it takes time for a pin to change from one state to another. In between, it's neither one nor t'other.
Because all real circuits have capacitance (and inductance, resistance, etc.) and to change a pin's voltage requires the capacitance to charge, large currents can flow.
Among other things, that can cause interference on adjacent wires. Limiting the rate at which the voltage changes reduces those problems, at the expense of more time before it's valid.
Fun anecdote time: logic (CMOS) inputs without hysteresis act as quite high-gain RF amplifiers if you let their inputs wander to VDD/2. On a particularly ancient and badly-designed board that I had the displeasure of repairing quite a few times, leakage currents and a dodgy terminal connection conspired to make a 4000 series hex inverter bounce up and down at about 18MHz. The output traces were coupling to the input traces at that frequency.

For the case of GPIO pins, hysteresis acts in exactly the same way as hysteresis on the input of 74HC series logic chips. The output toggles at different input voltage levels depending on the state of the output.

The slew rate option *limits* slew rate. Because the GPIOs can operate in the 10s of MHz region, slew rate limiting helps to prevent supply "bounce" when simultaneously switching multiple outputs. It reduces the maximum frequency possible from a single pin but improves the speeds of bus-style interfaces.
Rockets are loud.
https://astro-pi.org

stevovee
Posts: 8
Joined: Tue Aug 02, 2016 6:17 pm

Re: gpio_slew and gpio_hysteresis?

Tue Aug 02, 2016 6:18 pm

How/where do you change the GPIO_SLEW to limit it? I have read in a bunch of different places that setting this to 0 will limit the slew but can't find any clear information on how/where to set this. Any help would be apprecated.

stevovee
Posts: 8
Joined: Tue Aug 02, 2016 6:17 pm

Re: gpio_slew and gpio_hysteresis?

Thu Aug 04, 2016 7:46 pm

Is this something that you change in the config.txt file or through code in a script?

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

Re: gpio_slew and gpio_hysteresis?

Thu Aug 04, 2016 7:57 pm

You clear bit 4 of the pad control register.

E.g. in https://github.com/joan2937/pigpio/blob/master/pigpio.c gpioSetPad you would use the constant 0x08 rather than 0x18 to set slew rate limited.
Last edited by joan on Mon Nov 21, 2016 12:43 pm, edited 1 time in total.

blownelco
Posts: 10
Joined: Wed Nov 11, 2015 9:52 pm

Re: gpio_slew and gpio_hysteresis?

Mon Nov 21, 2016 12:23 pm

Hello,

I'm trying to change the slew rate of my raspberry pi 3.
I have gathering some code in C, it's reading the default values and changes to slew rate off.

If i'm toggle an io, nothing changes, raise time stays about 28ns.

Any clue why it doesn't work?

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

#define BCM2708_PERI_BASE 0x3F000000
#define PADS_GPIO_BASE (BCM2708_PERI_BASE + 0x100000 )
#define PADS_GPIO_00_27 0x002C
#define PADS_GPIO_28_45 0x0030
#define PADS_GPIO_46_53 0x0034

#define GETPAD32(offset) ( *(unsigned *) ((char *) (pads)+offset))

#define BLOCK_SIZE (4*1024)

volatile unsigned *pads ;


void initialize(void) {
int mem_fd = open("/dev/mem",O_RDWR|O_SYNC);
char *pads_map;

if ( mem_fd <= 0 ) {
perror("Opening/dev/mem");
exit(1);
}

pads_map = (char *)mmap(
NULL, /*Any address */
BLOCK_SIZE, /*Map length */
PROT_READ|PROT_WRITE,
MAP_SHARED,
mem_fd, /*File to map */
PADS_GPIO_BASE /*Offset to registers */
);

//if ((long)pads_map == −1L ) {
// perror("mmap failed.");
//xit(1);


close(mem_fd);
pads = (volatile unsigned *)pads_map;
}


int main(int argc,char **argv) {
int x;
union {
struct {
unsigned drive : 3;
unsigned hyst : 1;
unsigned slew : 1;
unsigned reserved : 13;
unsigned passwrd : 8;
} s;
unsigned w;
} word;

initialize();

printf ("reg=%x/n",PADS_GPIO_BASE);

for ( x=PADS_GPIO_00_27; x<=PADS_GPIO_46_53; x += 4 ) {
word.w = GETPAD32(x) ;
printf("%08X : %08X %x %x %x\n" ,
x+0x7E10000, word.w,
word.s.slew, word.s. hyst, word.s.drive) ;
}
printf("Writing register");

word.w = 0x5A00000C;
GETPAD32(PADS_GPIO_00_27)= word.w;

word.w = 0x5A00000C;
GETPAD32(PADS_GPIO_28_45)= word.w;

word.w = 0x5A00000C;
GETPAD32(PADS_GPIO_46_53)= word.w;




return 0;
}

User avatar
weinert
Posts: 1
Joined: Mon May 28, 2018 8:58 am
Location: Bochum
Contact: Website

Re: gpio_slew and gpio_hysteresis?

Mon May 28, 2018 9:32 am

Is there an "official" way to turn input hysteresis on/off with pigpoi C/IF?
With "official" I mean using the downloaded version in the Pis and made known to the cross platform development stations (Eclipse Windows or Ubuntu) without modifying pigpio source code.

Thanks
Albrecht
albrecht-weinert.de

Return to “HATs and other add-ons”