generation of square wave form beagle board

Hi all,

I made the following program for generating the square wave of 1MHz 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 if possible. Actually I want to generate wave upto
20MHz or so…

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 20MHz or so…

The code used by me is as follows:

#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(;:wink: {
gpio[0x603c/4] = 0xffffffff;
usleep(1);
gpio[0x603c/4] = 0x00000000;
usleep(1);
}
}

Using a SW-only solution, especially in user space is not going to work very well. In kernel using HR timers you might get better results but I think the best option would be to use some of the DM3730’s peripherals to create the wave for you. For example McBSP can, with some creative clock and frame sync and size configurations, create a lot of frequencies. Especially so if you do not require a 50/50 duty cycle on the signal.

  • Juha

Hi mohit hada,

You have the second processor (DSP C64+) so you can use it. :slight_smile:

Cheers,
Max.

mohit hada wrote:

Hi all,

I made the following program for generating the square wave of 1MHz using DM3730
<http://focus-webapps.ti.com/general/docs/sitesearch/searchdevice.tsp?partNumber=dm3730&gt; 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 if possible. Actually I want to
generate wave upto
20MHz or so....

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 20MHz or so....

http://elinux.org/BeagleBoard/GSoC/2010_Projects/Pulse_Width_Modulation

You could try SCHED_FIFO, although even then I doubt you'll get anywhere
near 20MHz. IIRC the clockrate of some internal bus sets an upper bound
on the GPIO update rate. A little googling reveals that this bound is
about 1MHz[1]. Anything above this really should be done with dedicated
hardware.

Cheers,

- Ben

[1] http://groups.google.com/group/beagleboard/browse_thread/thread/278336fb96fd661a/43b8bfda73c10d6c?pli=1

Hi JUHA

If we make a kernel module giving delay using HR Timer …
then i will have to access GPIO from kernel mode …

at present i m accessing gpio port in user space by using mmap then how ill i access gpio from kernel mode …?

2)how can we access GPIO port in DSP in BB …as of now i havent worked in DSP of BB …please guide where can i read about how to work in DSP of BB and access GPIO port from DSP …and generate square wavw from DSP of BB.

Thanks
Nidhi.

I would be really surprised and actually happy if someone can get a square wave of 20MHz from DSP (Looking at the frequencies of DSP, it looks possible in theory but not sure if it is possible in reality).
Btw…As Ben suggested you might want to look at some dedicated hardware…One thing that comes to my mind is a DDS chip. You would get a fair bit of variety in DDS (Direct Digital Synthesis) from Analog Devices …AD9854 is one that I remember. Of course, lot of it depends on what exactly u want to do.
It comes with a SPI kind of interface wherein you can program the frequency with a high resolution. So you could have the beagle talk to DDS and get the desired output.

Tushar

tushar gurjar wrote:

I would be really surprised and actually happy if someone can get a square wave of 20MHz from DSP (Looking at the
frequencies of DSP, it looks possible in theory but not sure if it is possible in reality).
Btw...As Ben suggested you might want to look at some dedicated hardware...One thing that comes to my mind is a DDS
chip. You would get a fair bit of variety in DDS (Direct Digital Synthesis) from Analog Devices ..AD9854 is one that I
remember. Of course, lot of it depends on what exactly u want to do.
It comes with a SPI kind of interface wherein you can program the frequency with a high resolution. So you could have
the beagle talk to DDS and get the desired output.

why not just use the PWM module of the omap3?

Dear vladimir,

Is it possible to get 20 MHz or so from PWM… I dont know exactly…

Thanks Tushaar… I know what you have said and can be my last resort…

Currently I will try PWM as vladmir is stressing upon OR may be McBSP can be a solution…

But To make my problem further clear, I am trying to interface a parallal ADC on EPI connector of BB. I am doubtful that if i cant generate SOC (Start of conversion) signal (Which I am referring as square wave) for ADC using GPIO and use some other means such as McBSP or PWM, whether will i be able to read the EOC (End OF Conversion) signal from ADC and read the parallal data using GPIO… I want ADC conversion rate of 20Msps or atleat 10 Msps.

Regards

Mohit

Hi Vladimir,

According to the TRM for DM3730 each timer can be clocked from the
system clock (12, 13, 16.8, 19.2, 26 or 38.4 MHz). As I understand for
BB system clock is equal to 26 MHz. Could you please explain how can I
get 20 MHz output using PWM with 26 MHz timer clock? Thanks.

Cheers,
Max.

Most precisely this is my doubt as well. thanks max…

regards

mohit

ok, but 19.2 is pretty close, no :slight_smile:

but, if you need a fixed frequency only, why not wire up a 20MHz
oscillator and gate it with a GPIO?

Hi Vladimir ,

while compiling PWM demo c file from the link
http://www.rose-hulman.edu/~mosttw/omap3530-pwm-1.1.tar.gz

I have angstrom image on my beagle board xM target and I have angstrom sdk on my ubuntu 10.04 LTS as host…

While compilation of the program, it does not get glib.h and sys/types.h … Please help…

root@mohit-desktop:~/BB_programs/omap3530-pwm# /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/cc /home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c /home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c -o /home/mohit/BB_programs/omap3530-pwm/pwm_exrcs1

/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:43:18: error: glib.h: No such file or directory
In file included from /home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:52:
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:48: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:49: error: expected ‘)’ before '
’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:50: error: expected declaration specifiers or ‘…’ before ‘gboolean’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:50: error: expected declaration specifiers or ‘…’ before ‘gboolean’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:51: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘pwm_calc_resolution’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:52: error: expected ‘)’ before ‘’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:72: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘gpt_instance_addrs’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:97: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before '
’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:112: error: expected ‘)’ before ‘’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:121: error: expected declaration specifiers or ‘…’ before ‘gboolean’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:121: error: expected declaration specifiers or ‘…’ before ‘gboolean’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c: In function ‘pwm_config_clock’:
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:126: error: ‘guint8’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:126: error: (Each undeclared identifier is reported only once
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:126: error: for each function it appears in.)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:126: error: ‘registers’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:131: error: ‘guint32’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:131: error: expected ‘;’ before ‘value’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:132: error: ‘value’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:133: error: ‘gptimer10_13mhz’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:134: error: ‘gptimer11_13mhz’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:135: error: expected ‘)’ before ‘guint32’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c: At top level:
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:143: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘pwm_calc_resolution’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.c:153: error: expected ‘)’ before '
’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:43:18: error: glib.h: No such file or directory
In file included from /home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:48:
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:48: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:49: error: expected ‘)’ before '
’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:50: error: expected declaration specifiers or ‘…’ before ‘gboolean’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:50: error: expected declaration specifiers or ‘…’ before ‘gboolean’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:51: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘pwm_calc_resolution’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm.h:52: error: expected ‘)’ before ‘*’ token
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c: In function ‘main’:
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:59: error: ‘TRUE’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:59: error: (Each undeclared identifier is reported only once
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:59: error: for each function it appears in.)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:59: error: too many arguments to function ‘pwm_config_clock’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:60: error: ‘guint8’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:60: error: ‘gpt10’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:61: error: ‘gpt11’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:64: error: ‘guint32’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:64: error: expected ‘;’ before ‘resolution’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:67: error: ‘for’ loop initial declaration used outside C99 mode
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:69: error: ‘resolution’ undeclared (first use in this function)
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:74: error: redefinition of ‘i’
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:67: error: previous definition of ‘i’ was here
/home/mohit/BB_programs/omap3530-pwm/omap3530-pwm-demo.c:74: error: ‘for’ loop initial declaration used outside C99 mode

please tell me , how can i get these .h header files for my set up.

Thanks
Mohit

While compilation of the program, it does not get glib.h and sys/types.h
.... Please help...

I was trying to compile it natively (on BB) and was fasing similar
problems. However it is easy to fix them by modifying Makefile.
Missing include paths should be added. Fortunately, the makefile is
very simple. Here is how my looks like:

CFLAGS += -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include

all: pwm-demo

pwm-demo: omap3530-pwm-demo.o omap3530-pwm.o
        gcc omap3530-pwm-demo.o omap3530-pwm.o -o pwm-demo -lglib-2.0

omap3530-pwm-demo.o: omap3530-pwm.h omap3530-pwm-demo.c
        gcc -c $(CFLAGS) omap3530-pwm-demo.c

omap3530-pwm.o: omap3530-pwm.h omap3530-pwm.c
        gcc -c $(CFLAGS) omap3530-pwm.c

clean:
        rm -f *.o pwm-demo

If you are cross-compiling, then your paths might be slightly
different. You need to figure them out and adjust if necessary.

I guess I was also changing something in the source code, but do not
remember what exaclty any more :slight_smile: . Just try to compile it and see
what are the errors.

HTH,
Andrey.

Hi Andrey …

Thanks , i dint have glib-2.0 on my ubuntu …i installed it and it got compiled …
but as its cross compilation …

my makefile looks like

CFLAGS += -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include

all: pwm-demo

pwm-demo: omap3530-pwm-demo.o omap3530-pwm.o
/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/cc omap3530-pwm-demo.o omap3530-pwm.o -L/usr/lib/glib-2.0/ pkg-config --libs glib-2.0 -o pwm-demo

omap3530-pwm-demo.o: omap3530-pwm.h omap3530-pwm-demo.c
/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/cc -c $(CFLAGS) omap3530-pwm-demo.c

omap3530-pwm.o: omap3530-pwm.h omap3530-pwm.c
/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/cc -c $(CFLAGS) omap3530-pwm.c

clean:
rm -f *.o pwm-demo

But it gives error in linking …
/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/cc -c -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include omap3530-pwm-demo.c
/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/cc -c -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include omap3530-pwm.c
/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/cc omap3530-pwm-demo.o omap3530-pwm.o -L/usr/lib/glib-2.0/ pkg-config --libs glib-2.0 -o pwm-demo
/usr/local/angstrom/arm/lib/gcc/arm-angstrom-linux-gnueabi/4.3.3/…/…/…/…/arm-angstrom-linux-gnueabi/bin/ld: cannot find -lglib-2.0
collect2: ld returned 1 exit status
make: *** [pwm-demo] Error 1

wherein i have glib2.0 on my ubuntu host
root@mohit-desktop:~/BB_programs/omap3530-pwm# pkg-config --list-all |grep glib
gio-unix-2.0 GIO unix specific APIs - unix specific headers for glib I/O library
dbus-glib-1 dbus-glib - GLib integration for the free desktop message bus
gio-2.0 GIO - glib I/O library
glib-2.0 GLib - C Utility Library

Then why its not able to find glibc while linking it ?

2)Do i have to install glib-2.0 package in my target BB-angstrom too ?
or can i copy same glib folder for /usr/include and /usr/lib to angstrom target …?

Nidhi.

Thanks , i dint have glib-2.0 on my ubuntu ...i installed it and it got
compiled ...
but as its cross compilation ..

You should have corresponding headers and libraries inside your
*cross-compiling environment* (as I understand, in your case it should
be something beginning with /usr/local/angstrom....). Adding your
host's include files (/usr/include...) to the include path is somehow
dangerous because there might be different versions used on your
Ubuntu and by cross-compiling environment. I was using this path
because I was compiling directly on BB (not cross-compiling).

If you do not have glib-2.0 for ARM, then you need to cross-compile it first.

2)Do i have to install glib-2.0 package in my target BB-angstrom too ?
or can i copy same glib folder for /usr/include and /usr/lib to angstrom
target ...?

It depends on whether you are linking glib-2.0 statically or
dynamically. Most probably you would link dynamically, then you will
need corresponding .so files on the target too. If you are using
angstrom, then the simplest way to install them properly would be to
use opkg install <package_name> . I do not remember exactly what is
the package name for glib. You can find it out on angstrom web-site.

Andrey.

I seriously doubt it. The GPIO pins on the OMAP are multiplexed, and
on the C4 board they only update every 240 ns. So, you can get just
over 2 MHz out of them. This is the bare GPIO pins, some of the
higher-level I/O functions run faster, like SPI. I suspect the DSP
can't update the pins any faster than the ARM CPU can.

Jon

I seriously doubt it. The GPIO pins on the OMAP are multiplexed, and
on the C4 board they only update every 240 ns. So, you can get just
over 2 MHz out of them. This is the bare GPIO pins, some of the
higher-level I/O functions run faster, like SPI. I suspect the DSP
can't update the pins any faster than the ARM CPU can.

Is there any way to access GPIO from DSP? It could be very interesting
for the hard real-time applications since there is no OS running on
DSP and that is why, theoretically, the timing could be very precise.
I would appreciate any pointers to the relevant information sources.

Thanks,
Andrey.

DM37x TRM page 1983, 9.1.4 Connectivity Matrix, Table 9-14 shows
data path between IVA2.2 and L4-targets, so if you are using
bb-xm it seems to be possible. Maybe you find such table
from omap TRM if you are using BB-C4.

Petri

Hi jon,

i think you are right since when i do not give any delay between toggling the GPIO pins from
user space, I got just 2 MHz…

Now I have a doubt will i get this as maximum speed while reading data form GPIO as well, for e.g.
If using an external interrupt signal, if I want to read 12 bit data on GPIO pins coming from Analog to
Digital Converter, will the maximum speed limit to 2 MHz. Please tell me.

Regards…

Mohit