Something odd I'm just now noticing is that GPI on the beaglewbone seems to 
have some lag.

What I'm doing:We have a cape with 6 channels PWM, 6 pins input, and 
several pins output. In order to test the PWM circuitry on our capes, I'm 
configuring these pins as GPO's, and we have a test header that ties the 
PWM pins to the input pins. All this is configured via an overlay file, and 
it is all correct. Additionally, we have LEDs on each channel PWM on these 
headers for visual inspection. The LEDs light up correctly when the PWM 
pins( again configured as GPO's for the purpose of this test ) are high.

However, when setting these pins high, then reading back the value from the 
PWM pins, and input pins, The input pins lag behind a great deal. Code:
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

#define HIGH    1
#define LOW    0

#define PWM1    2
#define PWM2    3
#define PWM3    50
#define PWM4    22
#define PWM5    51
#define PWM6    23

#define Z1IN    44
#define Z2IN    45
#define Z3IN    46
#define Z4IN    47
#define Z5IN    48
#define Z6IN    49

void set_pin(int pin_num, int value)
{
    char gpio_path[40] = {0};
    char str_value[2] = {0};

    sprintf(str_value, "%d", value);
    sprintf(gpio_path, "/sys/class/gpio/gpio%d/value", pin_num);

    int fd = open(gpio_path, O_WRONLY);
    if(fd == -1){
            perror(gpio_path);
            exit(1);
    }

    int nread = write(fd, str_value, 1);
    if( nread < 0){
        perror("write()");
        exit(1);
    }

    close(fd);
}

int get_pin(int pin_num)
{
    char gpio_path[40] = {0};
    char str_value[2] = {0};

    sprintf(gpio_path, "/sys/class/gpio/gpio%d/value", pin_num);

    int fd = open(gpio_path, O_RDONLY);
    if(fd == -1){
            perror(gpio_path);
            exit(1);
    }

    read(fd, str_value, sizeof(str_value - 1));

    close(fd);

    return strtol(str_value, NULL, 10);
}

int main()
{

    set_pin(PWM1, LOW);
    set_pin(PWM2, LOW);
    set_pin(PWM3, LOW);
    set_pin(PWM4, LOW);
    set_pin(PWM5, LOW);
    set_pin(PWM6, LOW);
    sleep(1);
    printf("PWM1: %i Z1IN: %i \n", get_pin(PWM1), get_pin(Z1IN));
    printf("PWM2: %i Z2IN: %i \n", get_pin(PWM2), get_pin(Z2IN));
    printf("PWM3: %i Z3IN: %i \n", get_pin(PWM3), get_pin(Z3IN));
    printf("PWM4: %i Z4IN: %i \n", get_pin(PWM4), get_pin(Z4IN));
    printf("PWM5: %i Z5IN: %i \n", get_pin(PWM5), get_pin(Z5IN));
    printf("PWM6: %i Z6IN: %i \n", get_pin(PWM6), get_pin(Z6IN));

    printf("\n");

    /***********************************************************/
    set_pin(PWM1, HIGH);
    set_pin(PWM2, HIGH);
    set_pin(PWM3, HIGH);
    set_pin(PWM4, HIGH);
    set_pin(PWM5, HIGH);
    set_pin(PWM6, HIGH);
    sleep(1);
    printf("PWM1: %i Z1IN: %i \n", get_pin(PWM1), get_pin(Z1IN));
    printf("PWM2: %i Z2IN: %i \n", get_pin(PWM2), get_pin(Z2IN));
    printf("PWM3: %i Z3IN: %i \n", get_pin(PWM3), get_pin(Z3IN));
    printf("PWM4: %i Z4IN: %i \n", get_pin(PWM4), get_pin(Z4IN));
    printf("PWM5: %i Z5IN: %i \n", get_pin(PWM5), get_pin(Z5IN));
    printf("PWM6: %i Z6IN: %i \n", get_pin(PWM6), get_pin(Z6IN));

    return  0;
}

As anyone can see, really simple straight forward code. The sleep shown in 
the code is required at this value, and if lowered, the input pins will be 
set correctly, but will read wrong. So here's the output as it stands.

root@wgd:~/dl-i2c-test#  nano read_zonein.c
root@wgd:~/dl-i2c-test# gcc -Wall -o read_zonein read_zonein.c
root@wgd:~/dl-i2c-test# ./read_zonein
PWM1: 0 Z1IN: 1
PWM2: 0 Z2IN: 1
PWM3: 0 Z3IN: 1
PWM4: 0 Z4IN: 1
PWM5: 0 Z5IN: 1
PWM6: 0 Z6IN: 1

PWM1: 1 Z1IN: 0
PWM2: 1 Z2IN: 0
PWM3: 1 Z3IN: 0
PWM4: 1 Z4IN: 0
PWM5: 1 Z5IN: 0
PWM6: 1 Z6IN: 0

But change the sleep() value to .5( 500 ms ) . . .
root@wgd:~/dl-i2c-test#  nano read_zonein.c
root@wgd:~/dl-i2c-test# gcc -Wall -o read_zonein read_zonein.c
root@wgd:~/dl-i2c-test# ./read_zonein
PWM1: 0 Z1IN: 1
PWM2: 0 Z2IN: 1
PWM3: 0 Z3IN: 1
PWM4: 0 Z4IN: 1
PWM5: 0 Z5IN: 1
PWM6: 0 Z6IN: 1


*PWM1: 1 Z1IN: 1PWM2: 1 Z2IN: 1*
PWM3: 1 Z3IN: 0
PWM4: 1 Z4IN: 0
PWM5: 1 Z5IN: 0
PWM6: 1 Z6IN: 0

Change the sleep value to .2(200 ms ), and the executed code gets all kinds 
of squirely. e.g. very inconsistent.

Does anyone know what's going on here ?
root@wgd:~/dl-i2c-test# uname -r
4.4.55-ti-r94
root@wgd:~/dl-i2c-test# free
             total       used       free     shared    buffers     cached
Mem:        499308      64736     434572       1456       5792      32348
-/+ buffers/cache:      26596     472712
Swap:            0          0          0
root@wgd:~/dl-i2c-test# uptime
 15:57:39 up  2:33,  1 user,  load average: *0.00, 0.01, 0.00*
root@wgd:~/dl-i2c-test# cat /etc/dogtag
BeagleBoard.org Debian Image 2017-04-02 

Even for a non RT kernel this seems ridiculously slow     

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/5885cd25-64f8-4989-940a-35ba85365828%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to