I am trying to use GPIO interrupts to measure a frequency. The input signal comes from a weather station anemometer so it is a reed switch closing at a few HZ. When the switch closes it grounds the pin. A 47k pullup resistor and 100nF capacitor bring the pin to 3.3v after 20ms or so.
The datasheet specifies Vil as 0.8v (max) and Vih as 2v (min) even without hysteresis enabled. With Hysteresis the data sheet specifies an additional 0.2v . I assume that if the input is low, the new Vih is 2.2v and when the input is high, the new Vil is 0.6v but some clarity would be nice.
The code monitors GP27 and fire interrupts for rising and falling edges. When the edge is rising, it toggles GP8 and when the edge is falling, it toggles GP7.
Here is a capture of the rising edge from my logic probe. Note: the logic analyser glitch filter is turned off on the input channel and it does not use hysteresis. The interrupts are firing continuously as the signal rises through the "no-man's land" between the Vil and Vih thresholds. I was expecting the area between the thresholds to be quiet and I was expecting the hysteresis to increase the size of that quite area to ensure some amount of noise immunity. The analog view of the input signal shows that there are no switch bounce issues to resolve on the rising edge and I would not expect any when the switch opens. For completeness here is the switch closing event.
Any suggestions? Before I can add some filtering to remove the noise I would like to confirm that I am using the SDK correctly and the chip is operating as expected. The behavior looks like the Vil/Vih is about 1.4v without hysteresis.
The datasheet specifies Vil as 0.8v (max) and Vih as 2v (min) even without hysteresis enabled. With Hysteresis the data sheet specifies an additional 0.2v . I assume that if the input is low, the new Vih is 2.2v and when the input is high, the new Vil is 0.6v but some clarity would be nice.
The code monitors GP27 and fire interrupts for rising and falling edges. When the edge is rising, it toggles GP8 and when the edge is falling, it toggles GP7.
Code:
#include <stdio.h>#include "pico/stdlib.h"#include "hardware/gpio.h"#include <stdlib.h>const int interrupt_pin = 27;void gpio_callback(uint gpio, uint32_t events){gpio_put(8, events & GPIO_IRQ_EDGE_RISE);gpio_put(7, events & GPIO_IRQ_EDGE_FALL);busy_wait_us(20);gpio_put(8, false);gpio_put(7, false);}int main(){stdio_init_all();gpio_init(8);gpio_set_dir(8, GPIO_OUT);gpio_init(7);gpio_set_dir(7, GPIO_OUT);gpio_init(interrupt_pin);gpio_set_input_hysteresis_enabled(interrupt_pin, true);gpio_set_pulls(interrupt_pin, false, false);gpio_set_irq_enabled_with_callback(interrupt_pin, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, &gpio_callback);for (;;);}
Any suggestions? Before I can add some filtering to remove the noise I would like to confirm that I am using the SDK correctly and the chip is operating as expected. The behavior looks like the Vil/Vih is about 1.4v without hysteresis.
Statistics: Posted by n9wxu — Thu Feb 29, 2024 8:13 pm — Replies 0 — Views 29