This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Difficulty in generating square wave using DM3730

Other Parts Discussed in Thread: DM3730

I made the following program for generating the square wave using DM3730 but i get a lot of jitter in generation of square wave
and do not get the required frequency even. Please look into it and suggest methods immediately.

My observation 

for usleep = 10^6, I get 0.5 hertz
for usleep = 10^4, I get 50 hertz
for usleep = 10^2, I get 1.5 Kilo hertz,
for usleep = 1, I get 1.5 Kilo hertz,


Please suggest some program to generate square wave faithfully upto a frequency of 10MHz or so....

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

int main() {

  int fd = open("/dev/mem", O_RDWR | O_SYNC);

  if (fd < 0) {
    printf("Could not open memory\n");
    return 0;
  }

  // Pad configuration
  volatile ulong *pinconf;
  pinconf = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x48000000);
  if (pinconf == MAP_FAILED) {
    printf("Pinconf Mapping failed\n");
    close(fd);
    return 0;
  }

   // Configure ONE Expansion HEADER PIN AS OUTPUT FOR SOC.
  //CONFIGURE ONE EXPANSION HEADER PIN AS OUTPUT FOR EOC
  //CONFIGURE ONE EXPANSION HEADER PINS AS BIDIRECTIONAL



  pinconf[0x2158/4] = 0x011C011C; //PIN CONFIGURED AS BIDIRECTIONAL
  pinconf[0x215C/4] = 0x011C011C; //PIN CONFIGURED AS
  pinconf[0x2160/4] = 0x011C011C; //PIN CONFIGURED AS  
  pinconf[0x2164/4] = 0x011C011C; //PIN CONFIGURED AS
  pinconf[0x2168/4] = 0x011C011C; //PIN CONFIGURED AS
  pinconf[0x216C/4] = 0x011C011C; //PIN CONFIGURED AS
  pinconf[0x2170/4] = 0x011C011C; //PIN CONFIGURED AS
  pinconf[0x2188/4] = 0x011C011C; //PIN CONFIGURED AS  
  close(fd);

 
  fd = open("/dev/mem", O_RDWR | O_SYNC);
 
  // GPIO Configuration: configure are input ---FOR ADC INPUT DATA
  volatile ulong *gpio;
  gpio = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x49050000);
  if (gpio == MAP_FAILED) {
     printf("Gpio Mapping failed\n");
     close(fd);
     return 0;
  }

  // Configure all GPIO pins on bank 5 as OUTPUT
  gpio[0x6034/4] = 0x00000000;
  int c=0;
  int count;
  for(;;) {
      gpio[0x603c/4] = 0xffffffff;
      usleep(1);   
      gpio[0x603c/4] = 0x00000000;
      usleep(1);   
  }
}