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.

AM3358: toggling GPIO for every 20 milli seconds

Part Number: AM3358

We want to toggle few gpios on am335x for every 20 milli seconds or less, how can we achieve that. Currently we see it 

it not going below 32milli seconds. 

Regards

  • Hello Shaik,

    Can you please share the code for how you are toggling? so that we can better assist you.

    Regards,

    S.Anil.

  • we are using sysfs interface 

    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/mman.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <string.h>
    
    
    int main ()
    {
    	
    	system("echo 45 >/sys/class/gpio/export");		//reset
    	system("echo 89 >/sys/class/gpio/export");		//cs
    	
    	system("echo out >/sys/class/gpio/gpio45/direction");		//reset
    	system("echo out >/sys/class/gpio/gpio89/direction");		//cs
    	
    	while(1)
    	{
    	system("echo 1 >/sys/class/gpio/gpio45/value");		//rest pin
    	system("echo 1 >/sys/class/gpio/gpio89/value");		//chip select
    	dealy(1000);
    		
    	system("echo 0 >/sys/class/gpio/gpio45/value");		
    	system("echo 0 >/sys/class/gpio/gpio89/value");		
    	dealy(1000);	
    	}
    
    
       return 0;
    }

    Currently it is set to toggle for every 1sec. but we are unable to toggle it if it set below 20 milli seconds.
  • Hi Shaik,

    Currently it is set to toggle for every 1sec. but we are unable to toggle it if it set below 20 milli seconds.

    What do you mean by "unable to toggle it"? What do you observe if you set the delay to 20 msec?

  • for example if we are trying to generate a pulse of 10 milli second , we see that it is limited to 20 milli seconds only. we are unable to generate below 20 milli seconds. 

  • Hi Shaik,

    There are many issues in your system design. Let me try to explain a few important ones.

    First of all, Linux is not a realtime OS, it is not guaranteed to generate operations in a defined time interval precisely (20ms in your case), not even possible in kernel space, not to mention you are doing it in user space.

    Another issue is that you are adding delay() in the loop in your program, how do you determine the delay value to the delay() function, have you considered each function call in the loop also adds time to the loop?

    Another big issue is that you shouldn't use system() function in a C program. Please search on Internet for the reason.

  • As Bin points out above, you are using the wrong tool for the task at hand. Linux on a Cortex-A core won't be able to do what you want. But, fortunately, The AM335x family includes the PRU cores that are perfectly designed for what you are looking to do. I would look into using them to accomplish your goals. Good luck!