Hi there,

I try to generate a square signal to the gpio A with a duty cycle of 1ms. 

My code is:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <fcntl.h>
#define _POSIX_C_SOURCE 199309
#include <time.h>
#include <string.h>
#include <linux/gpio_syscalls.h>

int main(int argc, char **argv) {
        struct timespec ts={
                .tv_sec=0,
                .tv_nsec=1000000
        };
        int return_value=0;
        
  // set PA0 as output
  gpiosetdir(PORTA, DIROUT, PA0);

  while(1) {
    gpiosetbits(PORTA, PA0);
    return_value=nanosleep(&ts, NULL);

    gpioclearbits(PORTA, PA0);
    return_value=nanosleep(&ts, NULL);
  }
  return(0);
}

But whatever I will use as .tv_nsec (if smaller than 20000000), the
duty cycle is 20 ms! I also tried usleep - the same.

I recompiled the kernel and - the same.

My kernel is:
2.6.15 #1 PREEMPT Thu Oct 30 10:41:51 CET 2008 cris unknown
with Preempt on!

Best regards
Johann

Reply via email to