2 Replies Latest reply on Mar 27, 2015 10:24 AM by arfoll

    Use GPIO as TTL/CMOS pulse counter

    Erazer

      Hi,

       

      I'm trying to create an c/c++ application to count pulses over a TTL/CMOS signal. (lowering 5V to 1.8V with resistors)

      The maximum count is around 15000/second.

       

      My target count should be over 100k/s.

      So the edison is to slow or I'm doing this all wrong.

       

      How can i make sure the edison counts to 100k/s? Or isn't this possible?

      Thanks

       

      Hardware

      - Edison module with yocto

      - Mini breakout board.

      - TTL/CMOS pulse generator

      - 1.8k resistor attached to 5v TTL/CMOS output

      - 10k resistor attached to TTL/CMOS mass & edison mass

      - GPIO-165 attached between resistors

       

      Application:

      
      #include <unistd.h>
      #include "mraa.h"
      #include <sys/time.h>
      static volatile uint counter = 0;
      void interrupt (void * args) {
          ++counter;
      }
      int main ()
      {
          mraa_init();
          mraa_gpio_context  gpio = mraa_gpio_init(15);
          if (gpio == NULL) return 1;
          mraa_gpio_dir(gpio, MRAA_GPIO_IN);
          //mraa_gpio_mode(gpio, MRAA_GPIO_STRONG);
          gpio_edge_t edge = MRAA_GPIO_EDGE_RISING;
          mraa_gpio_isr(gpio, edge, &interrupt, NULL);
        //mraa_gpio_use_mmaped(gpio, 1);
        int ct = 0;
          for(;;) {
          sleep(1);
          ct = counter;
          counter = 0;
          //usleep(1000000);
          fprintf(stdout, "%d\n", ct);
          }
          mraa_gpio_close(gpio);
          return MRAA_SUCCESS;
      }