Hello everyone ! Today i have generated clock signal from GPIO.my board have pre-shipped friendlyarm linux. The digital clock signal i tested has freqency of around 750 Hz only. is there any way to achieve higher speed from gpio. i tested the gpio with following shell script found from one site. # blink.sh # # Blink the onboard LED GPIO=$1 cleanup() { # Release the GPIO port echo $GPIO > /sys/class/gpio/unexport exit } # Open the GPIO port # echo $GPIO > /sys/class/gpio/export echo "high" > /sys/class/gpio/gpio$GPIO/direction trap cleanup SIGINT # call cleanup on Ctrl-C # Blink forever while [ "1" = "1" ]; do echo "1" > /sys/class/gpio/gpio$GPIO/value echo "0" > /sys/class/gpio/gpio$GPIO/value done cleanup # call the cleanup routine
GPIO Speed not exceed 1k
Google "kernel driver gpio" returns lots of hits, maybe this one? http://www.seiner.com/mediawiki/index.php/Gpio_kernel_drivers
Thanks both of you for replays. @Andre i have little knowledge of linux , but i know that every thing in linux represented as file even physical components. So, C code means i have to write a program which write "high" in direction file for output , "1" or "0" in value file using file pointer. may be i am wrong.please correct me. but, from c code can i achieve speed in MHz lets say 10 MHz or more?. @davef Thank you for the link. i will go through it.
http://www.avrfreaks.net/wiki/index.php/Documentation:Linux/GPIO You have the right idea, but this is still userspace access and therefore SLOW. You could use a GPIO kernel driver but even that is not going to get you MHz. Even using a "hard real time" patch to the Linux kernel you might not get there. Search "hard real time" on the forum. Get rid of the OS and then you can get some reasonable speeds. Might help to say what you are wanting to do.
I did this already, if you really need just that high frequency just use the PWM driver, and modified the C code, that way is done in the hardware, if you have a oscilloscope, and you run you bash file check the signal what happens when you run another program at the same time when your program is running ;) if you ever worked with an 8Bit micro controller you would do it the same way. you would use the PWM from the chip.
@davef I have just tested the program from your given link. i disabled all the printf statements and sleep in while so that maximum speed can be achieved. However i got frequency around 850~900 Hz on oscilloscope. if i use GPIO kernel driver can i get at least 1MHz ? I want it for application in Laser scanner. the laser scans in raster mode so, speed is desired as fast as possible. currently we are using pre-shipped FPGA cards with Laser galvo. it works in MHz. @Andre I got your point. i have to initialise PWM. let PWM is 8-bit. then i have to assign pwm=255 for 1 and assign pwm=0 for 0 but i think it will same as writing gpio device file from which i got speed of 850~900 Hz.
Jaydeep yes you can get that with the GPIO, but have you seen on the oscilloscope what happen to the PWM when you run another program at the same time you are running your program?
yes, i understand what you are saying. currently i am just test the gpio with very simple method. if other programs are working in userspace or the application have with nice gui features than this would cause delay. and i can not get even 850 Hz. the program should send fixed no. of pulses with maximum frequency. PWM can have freqency in MHz. if i initialize PWM to 50 % duty cycle and send it. but how can i send fixed no of pulses with PWM and then stop it.
@Jaydeep, @andre, @davef I have written kernel driver (ref. taken from mini2440_leds), however I am only getting 382 khz of freq in oscilloscope, I have optimized the driver and c program but i am unable to get 800 khz of frequency. can you please tell me how to increase the frequency, do i need to change in driver, kernel? in module rather than setting gpio_output I am sending command to register value, but some how I am not able to get desired frequency. Please suggest some solution, so that i can reach at 800-900 khz freq. Thank You for your time.
I think you might not get that high because you are using software PWM instead of hardware, if you type PS you would see other programs running, that could be decreasing your PWM freq.
Hello Andre, Yes, I am using software pwm, actually the whole scenario is like this. I am doing one project for stepper motor control, motor is connected with con4 of mini2440 board. I am using 30 pin out of 24 ping of con4, pin 31 as pwm. Pmw logic i have configured in driver, {source taking from mini2440_leds.c and mini2440_pwm.c }, using c program using while loop i am sending 0 and 1 on one pin and try to measure freq. on that pin, but i am getting only 382 khz freq. Below is the outcome from ps command PID USER VSZ STAT COMMAND 1 root 3068 S init 2 root 0 SW [kthreadd] 3 root 0 SW [ksoftirqd/0] 4 root 0 SW [events/0] 5 root 0 SW [khelper] 11 root 0 SW [async/mgr] 110 root 0 SW [sync_supers] 112 root 0 SW [bdi-default] 114 root 0 SW [kblockd/0] 124 root 0 SW [khubd] 128 root 0 SW [kmmcd] 144 root 0 SW [rpciod/0] 151 root 0 SW [kswapd0] 198 root 0 SW [aio/0] 202 root 0 SW [nfsiod] 206 root 0 SW [crypto/0] 315 root 0 SW [mtdblockd] 376 root 0 SW [usbhid_resumer] 408 root 3068 S syslogd 411 root 3328 S /usr/sbin/inetd 415 root 1940 S /usr/sbin/boa 427 root 3392 S -/bin/sh 428 root 3068 S init 431 root 3068 S init 433 root 3068 S init 471 root 3392 R ps no other program is using pwm expect the modified driver {the program is not running, so this is not in the ps output} people are talking here they get 800 khz of freq. how can i get the same using pwm? can you please explain me in little more details, or share some code? this will be a great help, i have achieve what i want but if i get more freq. then surely there will be a difference in speed and output. Thank you for your time and help. @Jaydeep, can you please share the code or hint on this, as you're trying the same...?
Hello All, The module consist of pwm code itself, in c code i just open that char device and constant try to send 1 and 0 in while loop, measuring the freq. in oscilloscope giving me 382 khz of freq. I have tried to read pclk value which is 50625000 which is 50 MHZ { as per the s3chxx pdf, it seems ok }, but I am unable to get desired frequency. Please suggest me some solution, path. patch to increase frequency. Thank you for your time and consideration in advance.