generation of square wave form beagle board

1,950 views
Skip to first unread message

mohit hada

unread,
Feb 10, 2011, 12:41:12 AM2/10/11
to beagl...@googlegroups.com
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(;;) {
      gpio[0x603c/4] = 0xffffffff;
      usleep(1);   
      gpio[0x603c/4] = 0x00000000;
      usleep(1);   
  }
}

--
Mohit Hada (owner)
Technid Solutions(An Embedded and FPGA based Design and Development Company)

Registered Office :

Flat No- 7,
73, Ashutosh Mukherjee Road,
Kolkata - 700025

ph : 08820074382 (preferred) / 09322156564


Ass No : 110720200429

Vat No. - 19415754062



Juha Kuikka

unread,
Feb 10, 2011, 1:00:19 AM2/10/11
to beagl...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.



--
Duck tape is like the force, it has a light side and a dark side and it holds the universe together.

Max Galemin

unread,
Feb 10, 2011, 1:04:27 AM2/10/11
to Beagle Board
Hi mohit hada,

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


Cheers,
Max.


On Feb 10, 4:41 pm, mohit hada <mohit....@gmail.com> 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?...>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,*
> *Mohit Hada (owner)
> **Technid Solutions**(An Embedded and FPGA based Design and Development
> Company)
> *
>
> *Registered Office :
> *
>
> **
>
> **
>
> * Flat No- 7,
> 73, Ashutosh Mukherjee Road,
> Kolkata - 700025*
>
> *ph : **08820074382 (preferred) */ *09322156564
> *
>
> **
> **
>
> * *
>
> *Ass No : 110720200429*
>
> *Vat No. - 19415754062
> *
>
> * *
> * *

Vladimir Pantelic

unread,
Feb 10, 2011, 3:34:32 AM2/10/11
to beagl...@googlegroups.com
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> 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

Ben Gamari

unread,
Feb 10, 2011, 7:49:40 AM2/10/11
to mohit hada, beagl...@googlegroups.com
On Thu, 10 Feb 2011 11:11:12 +0530, mohit hada <mohi...@gmail.com> 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>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....
>
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

mohit hada

unread,
Feb 11, 2011, 11:17:22 AM2/11/11
to beagl...@googlegroups.com

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.

tushar gurjar

unread,
Feb 11, 2011, 11:29:03 AM2/11/11
to beagl...@googlegroups.com
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

Vladimir Pantelic

unread,
Feb 11, 2011, 12:14:59 PM2/11/11
to beagl...@googlegroups.com
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?

mohit hada

unread,
Feb 12, 2011, 12:35:35 AM2/12/11
to beagl...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

Max Galemin

unread,
Feb 12, 2011, 1:23:37 AM2/12/11
to Beagle Board
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.

mohit hada

unread,
Feb 12, 2011, 2:17:27 AM2/12/11
to beagl...@googlegroups.com
Most precisely this is my doubt as well. thanks max....

regards

mohit

--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

Vladimir Pantelic

unread,
Feb 12, 2011, 3:02:50 AM2/12/11
to beagl...@googlegroups.com
On Sat, Feb 12, 2011 at 7:23 AM, Max Galemin <maksim....@gmail.com> wrote:
> 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.

ok, but 19.2 is pretty close, no :)

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

mohit hada

unread,
Feb 12, 2011, 7:58:42 AM2/12/11
to beagl...@googlegroups.com
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




--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

Andrey Nechypurenko

unread,
Feb 12, 2011, 8:26:32 AM2/12/11
to beagl...@googlegroups.com
> 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 :-) . Just try to compile it and see
what are the errors.

HTH,
Andrey.

mohit hada

unread,
Feb 12, 2011, 10:12:33 AM2/12/11
to beagl...@googlegroups.com
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.











--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

Andrey Nechypurenko

unread,
Feb 12, 2011, 11:51:14 AM2/12/11
to beagl...@googlegroups.com
> 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.

jmelson

unread,
Feb 12, 2011, 3:00:19 PM2/12/11
to Beagle Board


On Feb 11, 10:29 am, tushar gurjar <tushar...@hotmail.com> 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).

>
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

Andrey Nechypurenko

unread,
Feb 12, 2011, 4:23:23 PM2/12/11
to beagl...@googlegroups.com
> 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.

Petri Laakso

unread,
Feb 12, 2011, 5:00:07 PM2/12/11
to beagl...@googlegroups.com
On Sat, 12 Feb 2011 22:23:23 +0100
Andrey Nechypurenko <andre...@googlemail.com> wrote:

> 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.

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

mohit hada

unread,
Feb 13, 2011, 1:26:59 AM2/13/11
to beagl...@googlegroups.com
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
 

--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

mohit hada

unread,
Feb 13, 2011, 1:41:44 AM2/13/11
to beagl...@googlegroups.com
Dear Jon,

Where can we get the GPIO update information from the datasheet of DM3730 or OMAP 3530.

I could not find it.

Regards

Mohit

On Sun, Feb 13, 2011 at 1:30 AM, jmelson <el...@pico-systems.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

mohit hada

unread,
Feb 13, 2011, 3:44:02 AM2/13/11
to beagl...@googlegroups.com, andre...@googlemail.com
Dear andrey, vladmir,

when I try to run the pwm demo program on the beagle board with angstrom image taken from :

http://processors.wiki.ti.com/index.php/Getting_Started_With_C6Run_On_Beagleboard

I get the following error :

root@beagleboard:~# ./pwm-demo                                                                          
[  174.893035] Unhandled fault: external abort on non-linefetch (0x1818) at 0x4001e024                  
Bus error 


Please tell me some remedy of this... running a simple gpio program did run on the BB-xM fine.

regards

--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

Ben Gamari

unread,
Feb 13, 2011, 8:16:07 AM2/13/11
to mohit hada, beagl...@googlegroups.com, andre...@googlemail.com
On Sun, 13 Feb 2011 14:14:02 +0530, mohit hada <mohi...@gmail.com> wrote:
> I get the following error :
> *

> root@beagleboard:~#
> ./pwm-demo
>
> [ 174.893035] Unhandled fault: external abort on non-linefetch (0x1818) at
> 0x4001e024
> Bus error *

>
> Please tell me some remedy of this... running a simple gpio program did run
> on the BB-xM fine.
>
A little bit of Googling goes a long ways:

http://e2e.ti.com/support/embedded/f/354/p/49197/196854.aspx
http://markmail.org/message/dzcyrbqkeeivesyq
http://linux.omap.com/pipermail/linux-omap-open-source/2007-November/012094.html

The problem is apparently that your pwm demo doesn't enable the PWM
unit's clocks before accessing the PWM. You should take a look at
section 16.2 to determine which clocks are needed.

- Ben

Maksym Parkachov

unread,
Feb 13, 2011, 11:21:16 AM2/13/11
to beagl...@googlegroups.com
Hi,

as far as I remember, this error happens if you have
CONFIG_OMAP_RESET_CLOCKS enabled in the kernel. You can check
following kernel module, but it does exactly the same as library you
are using.

https://github.com/scottellis/omap3-pwm

At the bottom of the page, there is a notice with the setting which
should be disabled. So, you need to rebuild the kernel with this
option.

Regards,
Maksym.

mohit hada

unread,
Feb 13, 2011, 11:41:36 AM2/13/11
to Ben Gamari, beagl...@googlegroups.com, andre...@googlemail.com
Hi to all

Thanks a lot Ben for your help in your last mail....

Now I have been able to generate PWM but on beagle board xM, I have been able to generate maximum 4.34 MHz... The code modified is given
below, my added parts are indicated separately. But Now My doubt is why I get so low value of 4.34 MHz with 26MHz system clock. Is it that I am not able to use 26 MHz or ??? Please help. Thanks....

omap3530-pwm-demo.c :

#include <glib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>



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



#include "omap3530-pwm.h"

int
main(int argc, char **argv)
{
int mem_fd;
int i;


  
 /* New addition written by mohit */
volatile ulong *pinconf, *clk_selec;

  mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
  pinconf = (ulong*)mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, 0x48000000);

  if (pinconf == MAP_FAILED) {
    printf("Pinconf Mapping failed\n");
    close(mem_fd);
    return 0;
  }

 pinconf[0x2174/4] = 0x011A011A; //PIN CONFIGURED AS BIDIRECTIONAL
 pinconf[0x2178/4] = 0x011A011A; //PIN CONFIGURED AS BIDIRECTIONAL
 close(mem_fd);


   mem_fd = pwm_open_devmem();
      
    if (mem_fd == -1) {
//        g_error("Unable to open /dev/mem, are you root?: %s", g_strerror(errno));
    }

   pwm_clkfreq_sel(mem_fd, TRUE, TRUE);
   pwm_close_devmem(mem_fd);


/*program end by mohit*/


    mem_fd = pwm_open_devmem();
      
    if (mem_fd == -1) {
//        g_error("Unable to open /dev/mem, are you root?: %s", g_strerror(errno));
    }


////////////////////////////////INCLUSION OF ADDITIONAL FUNCTION CALLS FOR FCLK AND ICLK ENABLE///////////////////////////////////////////////////////

    // ENABLE ICLK CLOCK
    pwm_iclken_clock(mem_fd, TRUE, TRUE);
    pwm_close_devmem(mem_fd);

    mem_fd = pwm_open_devmem();
      
    if (mem_fd == -1) {
//        g_error("Unable to open /dev/mem, are you root?: %s", g_strerror(errno));
    }

    // ENABLE FCLK CLOCK
    pwm_fclken_clock(mem_fd, TRUE, TRUE);
    pwm_close_devmem(mem_fd);

    mem_fd = pwm_open_devmem();
      
    if (mem_fd == -1) {
//        g_error("Unable to open /dev/mem, are you root?: %s", g_strerror(errno));
    }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    // Set instances 10 and 11 to use the 13 Mhz clock
    pwm_config_clock(mem_fd, TRUE, TRUE);
    guint8 *gpt10 = pwm_mmap_instance(mem_fd, 10);
    guint8 *gpt11 = pwm_mmap_instance(mem_fd, 11);

    // Get the resolution for 20 kHz PWM
    guint32 resolution = pwm_calc_resolution(20000000, PWM_FREQUENCY_13MHZ);


    // Ramp up and down a bit
    for(i = 0; i <= 100; i++) {
//        g_print("%3d\n", i);
        pwm_config_timer(gpt10, resolution, i / 100.0);
        pwm_config_timer(gpt11, resolution, i / 100.0);
        usleep(100000);
    }
    sleep(500);
    for (i = 100; i >= 0; i--) {
 //       g_print("%3d\n", i);
        pwm_config_timer(gpt10, resolution, i / 100.0);
        pwm_config_timer(gpt11, resolution, i / 100.0);
        usleep(100000);
    }

    pwm_munmap_instance(gpt10);
    pwm_munmap_instance(gpt11);
    pwm_close_devmem(mem_fd);
}

// vim: set ts=4 et :


omap3530-pwm.c :

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

#include "omap3530-pwm.h"

// Clock configuration registers (TRM p. 470)
#define CM_CLKSEL_CORE 0x48004A40
#define CLKSEL_GPT10_MASK (1 << 6)
#define CLKSEL_GPT11_MASK (1 << 7)


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define CM_CLKSEL_FCLK 0x48004A00
#define FCLKSEL_GPT10_MASK (1 << 11)
#define FCLKSEL_GPT11_MASK (1 << 12)

#define CM_CLKSEL_ICLK 0x48004A10
#define ICLKSEL_GPT10_MASK (1 << 11)
#define ICLKSEL_GPT11_MASK (1 << 12)

#define CLKFREQ_SEL 0x48306D40
#define BIT1 (1 << 1)
#define BIT0 (1 << 0)


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// GPTIMER register offsets
#define GPT_REG_TCLR 0x024
#define GPT_REG_TCRR 0x028
#define GPT_REG_TLDR 0x02c
#define GPT_REG_TMAR 0x038

// Get a guint32 pointer to the register in block `instance` at byte
// offset `offset`.
#define REG32_PTR(instance, offset) ((volatile guint32*) (instance + offset))


// General purpose timer instances.  Not all of these can actually be
// used for PWM --- see the TRM for more information.
static guint32 gpt_instance_addrs[] = {
    0x4903e000, // GPTIMER8
    0x49040000, // GPTIMER9
    0x48086000, // GPTIMER10
    0x48088000, // GPTIMER11
};


// The default Linux page size is 4k and the GP timer register
// blocks are aligned to 4k.  Therefore it is convenient to just
// assume that pages are aligned there for the purposes of mmap()
// (since mmap only maps aligned pages).  This function checks
// that assumption and aborts if it is untrue.
static void
check_pagesize(void)
{
    if (getpagesize() != 4096) {
//        g_error("The page size is %d.  Must be 4096.", getpagesize());
    }
}

// Simply a wrapper around mmap that passes the correct arguments
// for mapping a register block.  `instance_number` must be between
// 1 and 12, or errno will be set to EDOM and MAP_FAILED returned.
// Otherwise the return value is that of `mmap()`.
guint8*
pwm_mmap_instance(int mem_fd, int instance_number)
{
    if (instance_number < 8 || instance_number > 11) {
        errno = EDOM;
        return MAP_FAILED;
    }
    int instance_addr = gpt_instance_addrs[instance_number - 8];
    return mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, instance_addr);
}

// The inverse of `pwm_mmap_instance()`, this is simply a wrapper
// arount `munmap()`.  It returns the underlying `munmap()` call's
// return value.
int
pwm_munmap_instance(guint8 *instance)
{
    return munmap(instance, 4096);
}

// Configure the clocks for GPTIMER10 and GPTIMER11, which can be set to
// use the 13 MHz system clock (otherwise they use the 32 kHz clock like
// the rest of the timers).  Return -1 on failure, with errno set.
int
pwm_config_clock(int mem_fd, gboolean gptimer10_13mhz, gboolean gptimer11_13mhz)
{
    int page_addr = CM_CLKSEL_CORE & 0xfffff000;
    int offset = CM_CLKSEL_CORE & 0xfff;

    guint8 *registers = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
    if (registers == MAP_FAILED) {
        return -1;
    }

    guint32 value = *REG32_PTR(registers, offset);
    value &= ~(CLKSEL_GPT10_MASK | CLKSEL_GPT11_MASK);
    if (gptimer10_13mhz) value |= CLKSEL_GPT10_MASK;
    if (gptimer11_13mhz) value |= CLKSEL_GPT11_MASK;
    *REG32_PTR(registers, offset) = value;

    return munmap(registers, 4096);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
pwm_fclken_clock(int mem_fd, gboolean gptimer10_13mhz, gboolean gptimer11_13mhz)
{
    int page_addr = CM_CLKSEL_FCLK & 0xfffff000;
    int offset = CM_CLKSEL_FCLK & 0xfff;

    guint8 *registers = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
    if (registers == MAP_FAILED) {
        return -1;
    }

    guint32 value = *REG32_PTR(registers, offset);
    value &= ~(FCLKSEL_GPT10_MASK | FCLKSEL_GPT11_MASK);
    if (gptimer10_13mhz) value |= FCLKSEL_GPT10_MASK;
    if (gptimer11_13mhz) value |= FCLKSEL_GPT11_MASK;
    *REG32_PTR(registers, offset) = value;

    return munmap(registers, 4096);
}


int
pwm_iclken_clock(int mem_fd, gboolean gptimer10_13mhz, gboolean gptimer11_13mhz)
{
    int page_addr = CM_CLKSEL_ICLK & 0xfffff000;
    int offset = CM_CLKSEL_ICLK & 0xfff;

    guint8 *registers = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
    if (registers == MAP_FAILED) {
        return -1;
    }

    guint32 value = *REG32_PTR(registers, offset);
    value &= ~(ICLKSEL_GPT10_MASK | ICLKSEL_GPT11_MASK);
    if (gptimer10_13mhz) value |= ICLKSEL_GPT10_MASK;
    if (gptimer11_13mhz) value |= ICLKSEL_GPT11_MASK;
    *REG32_PTR(registers, offset) = value;

    return munmap(registers, 4096);
}


int
pwm_clkfreq_sel(int mem_fd, gboolean gptimer10_13mhz, gboolean gptimer11_13mhz)
{
    int page_addr = CLKFREQ_SEL & 0xfffff000;
    int offset = CLKFREQ_SEL & 0xfff;

    guint8 *registers = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
    if (registers == MAP_FAILED) {
        return -1;
    }

    guint32 value = *REG32_PTR(registers, offset);
    value &= ~(BIT1 | BIT0);
    if (gptimer10_13mhz) value |= BIT1;
    if (gptimer11_13mhz) value |= BIT0;
    *REG32_PTR(registers, offset) = value;

    return munmap(registers, 4096);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



// Calculate the resolution of the PWM (the number of clock ticks
// in the period), which is passed to `pwm_config_timer()`.
guint32
pwm_calc_resolution(int pwm_frequency, int clock_frequency)
{
    float pwm_period = 1.0 / pwm_frequency;
    float clock_period = 1.0 / clock_frequency;
    return (guint32) (pwm_period / clock_period);
}

// Initialize the control registers of the specified timer
// instance for PWM at the specified resolution.
void
pwm_config_timer(guint8 *instance, guint32 resolution, float duty_cycle)
{
    guint32 counter_start = 0xffffffff - resolution;
    guint32 dc = 0xffffffff - ((guint32) (resolution * duty_cycle));

    // Edge condition: the duty cycle is set within two units of the overflow
    // value.  Loading the register with this value shouldn't be done (TRM 16.2.4.6).
    if (0xffffffff - dc <= 2) {
        dc = 0xffffffff - 2;
    }

    // Edge condition: TMAR will be set to within two units of the overflow
    // value.  This means that the resolution is extremely low, which doesn't
    // really make sense, but whatever.
    if (0xffffffff - counter_start <= 2) {
        counter_start = 0xffffffff - 2;
    }

    *REG32_PTR(instance, GPT_REG_TCLR) = 0; // Turn off
    *REG32_PTR(instance, GPT_REG_TCRR) = counter_start;
    *REG32_PTR(instance, GPT_REG_TLDR) = counter_start;
    *REG32_PTR(instance, GPT_REG_TMAR) = dc;
    *REG32_PTR(instance, GPT_REG_TCLR) = (
        (1 << 0)  | // ST -- enable counter
        (1 << 1)  | // AR -- autoreload on overflow
        (1 << 6)  | // CE -- compare enabled
        (1 << 7)  | // SCPWM -- invert pulse
        (2 << 10) | // TRG -- overflow and match trigger
        (1 << 12)   // PT -- toggle PWM mode
    );
}

int
pwm_open_devmem(void)
{
    check_pagesize();

    return open("/dev/mem", O_RDWR | O_SYNC);
}

void
pwm_close_devmem(int dev_fd)
{
    /* This function is useful! */
    close(dev_fd);
}

// vim: set ts=4 expandtab :

Vladimir Pantelic

unread,
Feb 14, 2011, 5:22:08 AM2/14/11
to beagl...@googlegroups.com
mohit hada wrote:
> 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.

see: http://groups.google.com/group/beagleboard/msg/c6d8cbd23fc46873

and the whole discussion thread:

http://groups.google.com/group/beagleboard/browse_thread/thread/de6f0d17b8d0c418?tvc=2

mohit hada

unread,
Feb 14, 2011, 6:52:29 AM2/14/11
to beagl...@googlegroups.com
Dear Vladmir,

The reply of soren tells that 4Mbps is the last on the GPIO which I can get..... so i have to drop the idea of using GPIO....
in fact i have to leave BB- xM for this project.....

But one doubt I still have if you can resolve.... why this link then tells that faster GPIO access can be done using DMA..??

https://e2e.ti.com/support/dsp/omap_applications_processors/f/447/p/49018/183185.aspx

As I was trying to explore that option.

Regards

Mohit



--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

mohit hada

unread,
Feb 14, 2011, 6:54:14 AM2/14/11
to beagl...@googlegroups.com
Hi vladmir,

Again I dont know why i could not get higher than around 4.34MHz through PWM.

regards

mohit

--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

Richard Watts

unread,
Feb 14, 2011, 7:08:39 AM2/14/11
to beagl...@googlegroups.com
On 14/02/11 11:52, mohit hada wrote:
> Dear Vladmir,
>
> The reply of soren tells that 4Mbps is the last on the GPIO which I can get..... so i have to drop the idea of using GPIO....
> in fact i have to leave BB- xM for this project.....
[snip]

A brief scan of S16 of the TRM would have told you that if you:

- Set timer clock to some suitable frequency, up to 38.4MHz
- Set the timer count to something suitable and timer to
auto-reload
- Program GPTi.TCLR to generate a pulse, or set 'toggle on overflow'

You can get a square wave of more or less any frequency you like.
I haven't checked the pads, but I'd be surprised if there wasn't
some PWM GPIO which wouldn't cope with 20MHz.

Odd duty cycles are less straightforward ..

If you want higher frequencies, you can get 216MHz / (0..31) from
the ISP CLKA or CLKB pins.

Richard.

Vladimir Pantelic

unread,
Feb 14, 2011, 7:11:21 AM2/14/11
to beagl...@googlegroups.com
mohit hada wrote:
> Dear Vladmir,
>
> The reply of soren tells that 4Mbps is the last on the GPIO which I can get..... so i have to drop the idea of using
> GPIO....
> in fact i have to leave BB- xM for this project.....

well, you have to drop the idea of connecting your ADC over GPIO, why not use one that works over SPI? Or McBSP?

> But one doubt I still have if you can resolve.... why this link then tells that faster GPIO access can be done using DMA..??
>
> https://e2e.ti.com/support/dsp/omap_applications_processors/f/447/p/49018/183185.aspx

I have no idea.

Vladimir Pantelic

unread,
Feb 14, 2011, 7:13:42 AM2/14/11
to beagl...@googlegroups.com
mohit hada wrote:
> Hi vladmir,
>
> Again I dont know why i could not get higher than around 4.34MHz through PWM.

I don't know.

but maybe you can tell us what you need that 20MHz output clock for?

>

Ben Gamari

unread,
Feb 14, 2011, 7:31:37 AM2/14/11
to mohit hada, beagl...@googlegroups.com
On Mon, 14 Feb 2011 17:22:29 +0530, mohit hada <mohi...@gmail.com> wrote:
> Dear Vladmir,
>
> The reply of soren tells that 4Mbps is the last on the GPIO which I can
> get..... so i have to drop the idea of using GPIO....
> in fact i have to leave BB- xM for this project.....
>
That is for GPIO usage. The PWM should do what you want. Blindly
Googling for things like this will only further cloud the issue. You
really just need to sit down and read the relevant section of the TRM
(chapter 16).

> But one doubt I still have if you can resolve.... why this link then tells
> that faster GPIO access can be done using DMA..??
>

You'll need to look through chapter 9 of the TRM and see what the
capabilities of the DMA unit are. I wasn't aware that the DMA controller
could drive the GPIOs.

Really though, you should either use the PWM or dedicated
hardware. Using GPIO to produce a simple waveform like this is just
insane.

- Ben

mohit hada

unread,
Feb 14, 2011, 7:53:59 AM2/14/11
to beagl...@googlegroups.com
Hi Ben and Vladmir,

I want to sample an analog input using a 12 bit ADC at around 20 Msps so I want 240Mbps of data input rate. So the start of conversion signal for the ADC, ADS 2807 has to be the square wave.

The reason I am not using McBSP or not  choosing an SPI based ADC is that, Beagle Board   can give only 48Mbps serially at the max which is much lower to my requirement.

So I am stuck...

regards

--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

mohit hada

unread,
Feb 14, 2011, 7:55:09 AM2/14/11
to beagl...@googlegroups.com
the ADC is parallal ADC and the square wave is 20MHz i.e. start of conversion signal of ADC.

mohit hada

unread,
Feb 14, 2011, 7:57:55 AM2/14/11
to beagl...@googlegroups.com
And the port that I have to use to connect parallal ADC is external peripheral header ...

Vladimir Pantelic

unread,
Feb 14, 2011, 8:23:49 AM2/14/11
to beagl...@googlegroups.com
mohit hada wrote:
> Hi Ben and Vladmir,
>
> I want to sample an analog input using a 12 bit ADC at around 20 Msps so I want 240Mbps of data input rate. So the start
> of conversion signal for the ADC, ADS 2807 has to be the square wave.

besides capturing, what do you want to do with that 240Mbps of data?

> The reason I am not using McBSP or not choosing an SPI based ADC is that, Beagle Board can give only 48Mbps serially
> at the max which is much lower to my requirement.

then maybe indeed the BB is not the right hardware for you...

Richard Watts

unread,
Feb 14, 2011, 8:54:16 AM2/14/11
to beagl...@googlegroups.com
On 14/02/11 12:53, mohit hada wrote:
> Hi Ben and Vladmir,
>
> I want to sample an analog input using a 12 bit ADC at around 20 Msps so I want 240Mbps of data input rate.
> So the start of conversion signal for the ADC, ADS 2807 has to be the square wave.

In that case, here is an exercise for you: read the TRM and spot a
parallel interface that will accept 20 Msps of 12-bit data. It has
a whole chapter to itself and everything ..

Richard.

Ben Gamari

unread,
Feb 14, 2011, 9:22:35 AM2/14/11
to mohit hada, beagl...@googlegroups.com
On Mon, 14 Feb 2011 18:23:59 +0530, mohit hada <mohi...@gmail.com> wrote:
> Hi Ben and Vladmir,
>
> I want to sample an analog input using a 12 bit ADC at around 20 Msps so I
> want 240Mbps of data input rate. So the start of conversion signal for the
> ADC, ADS 2807 has to be the square wave.
>
Ouch. That is a very high number. In fact, I believe it's a pretty large
fraction of the memory bandwidth of the OMAP. What do you intend on
doing with this data once you get it onto the device? I don't think
you'll have a lot of headroom computationally.

> The reason I am not using McBSP or not choosing an SPI based ADC is that,
> Beagle Board can give only 48Mbps serially at the max which is much lower
> to my requirement.
>
> So I am stuck...
>

Pretty much. I don't believe there's any way the BeagleBoard could
satisfy those requirements. As far as I know there simply isn't an
interface that could support that data rate (although I could be wrong).

That being said, you should look at the PandaBoard. It's an OMAP4-based
board which exposes the General-Purpose Memory Controller (at least
16-bits of it). I believe you'd need some dedicated logic to look after
the ADC (which shouldn't be a surprise given the data rate you are
looking for). Perhaps you could use an FPGA to push samples into a RAM
as well as multiplex reads from the GPMC. You could then perhaps use the
sDMA controller to pull memory over the GPMC into local memory. Just a
(perhaps fatally flawed) thought.

Cheers,

- Ben

Ben Gamari

unread,
Feb 14, 2011, 9:31:37 AM2/14/11
to Richard Watts, beagl...@googlegroups.com
I, for one, am stumped. Which interface would this be? Looking through
the ToC of the TRM, the only thing I can see is the GPMC. Perhaps
another hint is in order?

- Ben

Richard Watts

unread,
Feb 14, 2011, 9:46:19 AM2/14/11
to beagl...@googlegroups.com

To be fair, it does depend on your timing requirements, but the
ISP is quite capable of sampling at 20 MHz (VGA dot clock is
25, SD TV clocks 27). You just frame your problem as a video sampling one,
arrange for your syncs to be in (more or less) the right places
and away you go.

240Mbps is only 80 MByte/s - my USB attached hard disc can do 30%
of that (admittedly on a Panda, but still).

Now, if you want 240MByte/s you might have a problem.. :-)


Richard.

Ben Gamari

unread,
Feb 14, 2011, 10:28:26 AM2/14/11
to Richard Watts, beagl...@googlegroups.com
On Mon, 14 Feb 2011 14:46:19 +0000, Richard Watts <r...@kynesim.co.uk> wrote:
> On 14/02/11 14:31, Ben Gamari wrote:
> > I, for one, am stumped. Which interface would this be? Looking through
> > the ToC of the TRM, the only thing I can see is the GPMC. Perhaps
> > another hint is in order?
>
> To be fair, it does depend on your timing requirements, but the
> ISP is quite capable of sampling at 20 MHz (VGA dot clock is
> 25, SD TV clocks 27). You just frame your problem as a video sampling one,
> arrange for your syncs to be in (more or less) the right places
> and away you go.
>
Ahh, very nice thought. It's incredible how unexpectedly useful these
specialized hardware blocks can be. Personally, I think I'd still want
to use the GPMC on a Panda. It just feels nicer.

Cheers,

- Ben

Vladimir Pantelic

unread,
Feb 14, 2011, 1:17:38 PM2/14/11
to beagl...@googlegroups.com

using these odd 3bit bytes?

Richard Watts

unread,
Feb 14, 2011, 1:21:08 PM2/14/11
to beagl...@googlegroups.com
On 14/02/11 18:17, Vladimir Pantelic wrote:
> Richard Watts wrote:
[snip]

>>
>> 240Mbps is only 80 MByte/s - my USB attached hard disc can do 30%
>> of that (admittedly on a Panda, but still).
>
> using these odd 3bit bytes?

Exactly. Why follow convention? Um. Oops.

Richard.

jmelson

unread,
Feb 18, 2011, 6:47:50 PM2/18/11
to Beagle Board


On Feb 13, 12:41 am, mohit hada <mohit....@gmail.com> wrote:
> Dear Jon,
>
> Where can we get the GPIO update information from the datasheet of DM3730 or
> OMAP 3530.
>
> I could not find it.
I couldn't find it mentioned anywhere in there either! Of course, it
is a 3700-page manual, so I could have missed it. I can see where a
clock derived from another clock derived from another clock .......
feeds the whole GPIO architecture, but they don't say anything about
how that affects the update rate of one GPIO pin.

Jon

jmelson

unread,
Feb 18, 2011, 6:51:22 PM2/18/11
to Beagle Board


On Feb 13, 10:41 am, mohit hada <mohit....@gmail.com> wrote:
> Hi to all
>
> Thanks a lot Ben for your help in your last mail....
>
> Now I have been able to generate PWM but on beagle board xM, I have been
> able to generate maximum 4.34 MHz... The code modified is given
> below, my added parts are indicated separately. *But Now My doubt is why I
> get so low value of 4.34 MHz with 26MHz system clock. Is it that I am not
> able to use 26 MHz or ??? Please help. Thanks....*

Hmmm, that's a VERY interesting measurement! 26 MHz / 4.34 Mhz ~=
6 ! And, there are SIX GPIO banks on the OMAP CPUs.
So, I think that is the multiplexing rate right there, each clock
cycle updates one GPIO bank, then it moves on to the next bank.

Jon

mohit hada

unread,
Feb 19, 2011, 4:03:40 AM2/19/11
to beagl...@googlegroups.com
May be Jon, interesting derivation from your side....

At least some logic behind it...

regards

mohit


--
You received this message because you are subscribed to the Google Groups "Beagle Board" group.
To post to this group, send email to beagl...@googlegroups.com.
To unsubscribe from this group, send email to beagleboard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

mohit hada

unread,
Feb 19, 2011, 4:10:48 AM2/19/11
to beagl...@googlegroups.com
Actually jon, what I found was .... when I tried to get 20 KHz from PWM, I got 10 KHz...

Now because of some edge constraint, the value = (reqd pwm frequency / clock frequency) shall be less than 2 at least from the over flow value of the internal timer so i think here there is a division by three of the clock frequency that we can get i.e.

26 / 3 = 8.66667 MHz .... now that should be the value i should get.... but then i get it divided by 2 i.e. 4.3334 MHz.... see my first statement...

Now this is my understanding.... you can put some light to it...

regards

mohit

mohit hada

unread,
Feb 19, 2011, 4:11:54 AM2/19/11
to beagl...@googlegroups.com
correction of error

On Sat, Feb 19, 2011 at 2:40 PM, mohit hada <mohi...@gmail.com> wrote:
Actually jon, what I found was .... when I tried to get 20 KHz from PWM, I got 10 KHz...

Now because of some edge constraint, the value = (clock frequency / reqd pwm frequency) shall be less than 2 at least from the over flow value of the internal timer so i think here there is a division by three of the clock frequency that we can get i.e.

Mark A. Yoder

unread,
Jul 25, 2011, 3:02:53 PM7/25/11
to beagl...@googlegroups.com
I've gotten PWM running on the Beagle [1], but I'm only seeing about 4MHz out.  It could be the ringing caused by my poor wiring is masking the higher frequencies.

--Mark

bluetooth...@gmail.com

unread,
Oct 26, 2013, 2:02:38 PM10/26/13
to beagl...@googlegroups.com
Would be possible for you to share the file  omap3530-pwm-1.1.tar. with me? I cannot download it from anywhere I need to implement PWM backlight display on a OMAP35xx based board and would appreciate it.

Thank you,
Gil

milkyway

unread,
Apr 6, 2014, 1:50:53 AM4/6/14
to beagl...@googlegroups.com, Ben Gamari, andre...@googlemail.com
I am using GPTIMER_PWM_9 to generate a square wave. Following is my code

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

#define MEMORY_BASE_ADDRESS                     0x48000000
#define GPTIMER9_BASE_ADDRESS                   0x49040000
#define GPTIMER9_PADCONF_REGISTER               0x2174/4
#define GPTIMER9_RELOAD_REGISTER                0x002c/4
#define GPTIMER9_COMAPARATOR_REGISTER   0x0038/4
#define GPTIMER9_CONTROL_REGISTER               0x0024/4
#define GPTIMER9_COUNTER_REGISTER               0x0028/4


int main(void)
{

       
int config_fd, j, pwm_fd;
       
volatile unsigned int *config, *pwm;;
    config_fd
= open("/dev/mem", O_RDWR | O_SYNC);
    printf
("Open file descriptor for PADCONFIG\n");
       
if (config_fd < 0)
       
{
      printf
("Could not open PADCONFIG memory fd\n");
     
return 0;
   
}

   
// Pad configuration
    printf
("Setting PAD configuration register\n");
    config
= (unsigned int*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, config_fd, MEMORY_BASE_ADDRESS);
   
if (config == MAP_FAILED)
       
{
      printf
("Pinconfig Mapping failed\n");
      close
(config_fd);
     
return 1;
   
}

    printf
("Setting padconf register for PWM\n");
    config
[GPTIMER9_PADCONF_REGISTER] = config[GPTIMER9_PADCONF_REGISTER] & 0xffff0000 | 0x00000002; // setting 0x48002714 as gpt9_pwm_evt
        printf
("The pin has been succesfully selected as gpt9_pwm_evt\n");
        close
(config_fd);
    printf
("Opening file descriptor for PWM\n");
    pwm_fd
= open("/dev/mem", O_RDWR | O_SYNC);
   
if (pwm_fd < 0)
       
{
      printf
("Could not open GPIO memory fd\n");
     
return 2;
   
}
        printf
("Memory opened for pwm settings\n");
    pwm
= (unsigned int*) mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, pwm_fd, GPTIMER9_BASE_ADDRESS);
   
if (pwm == MAP_FAILED)
       
{
      printf
("PWM Mapping failed\n");
      close
(pwm_fd);
     
return 3;
   
}
    printf
("Setting up PWM\n");
        pwm
[GPTIMER9_CONTROL_REGISTER] = 0;
        pwm
[GPTIMER9_RELOAD_REGISTER] = 0x0000ff; // initial value of pwm during overflow
        pwm
[GPTIMER9_COUNTER_REGISTER] = 0x0000ff; // initial value of pwm during overflow
        pwm
[GPTIMER9_COMAPARATOR_REGISTER] = 0x0fffff; // overflow value
        pwm
[GPTIMER9_CONTROL_REGISTER] = 0x18c3;  //timer control register
    printf
("PWM Started\n");
        close
(pwm_fd);
       
return 0;
}


But I am getting an error as follows

root@localhost:/home/dell/sample_programs# ./a.out
open file descriptor
for PADCONFIG
map PINCONFIG
Setting padconf register for PWM
The pin has been succesfully selected as gpt9_pwm_evt
opening file descriptor
for PWM
Memory opened for pwm settings
setting up pwm
Bus error

Can anybody help me to fix this issue?


On Sunday, 13 February 2011 22:11:36 UTC+5:30, mohit hada wrote:
Hi to all

Thanks a lot Ben for your help in your last mail....

Now I have been able to generate PWM but on beagle board xM, I have been able to generate maximum 4.34 MHz... The code modified is given
below, my added parts are indicated separately. But Now My doubt is why I get so low value of 4.34 MHz with 26MHz system clock. Is it that I am not able to use 26 MHz or ??? Please help. Thanks....

omap3530-pwm-demo.c :

#include <glib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>


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



#include "omap3530-pwm.h"

int
main(int argc, char **argv)
{
int mem_fd;
int i;


  
 /* New addition written by mohit */
volatile ulong *pinconf, *clk_selec;

  mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
  pinconf = (ulong*)mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, 0x48000000);
  if (pinconf == MAP_FAILED) {
    printf("Pinconf Mapping failed\n");
    close(mem_fd);
    return 0;
  }

 pinconf[0x2174/4] = 0x011A011A; //PIN CONFIGURED AS BIDIRECTIONAL
 pinconf[0x2178/4] = 0x011A011A; //PIN CONFIGURED AS BIDIRECTIONAL
 close(mem_fd);


   mem_fd = pwm_open_devmem();
      
    if (mem_fd == -1) {
//        g_error("Unable to open /dev/mem, are you root?: %s", g_strerror(errno));
    }

   pwm_clkfreq_sel(mem_fd, TRUE, TRUE);
   pwm_close_devmem(mem_fd);


/*program end by mohit*/


    mem_fd = pwm_open_devmem();
      
    if (mem_fd == -1) {
//        g_error("Unable to open /dev/mem, are you root?: %s", g_strerror(errno));
    }


////////////////////////////////INCLUSION OF ADDITIONAL FUNCTION CALLS FOR FCLK AND ICLK ENABLE///////////////////////////////////////////////////////

    // ENABLE ICLK CLOCK
    pwm_iclken_clock(mem_fd, TRUE, TRUE);
    pwm_close_devmem(mem_fd);

    mem_fd = pwm_open_devmem();
      
    if (mem_fd == -1) {
//        g_error("Unable to open /dev/mem, are you root?: %s", g_strerror(errno));
    }

    // ENABLE FCLK CLOCK
    pwm_fclken_clock(mem_fd, TRUE, TRUE);
    pwm_close_devmem(mem_fd);

    mem_fd = pwm_open_devmem();
      
    if (mem_fd == -1) {
//        g_error("Unable to open /dev/mem, are you root?: %s", g_strerror(errno));
    }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    // Set instances 10 and 11 to use the 13 Mhz clock
    pwm_config_clock(mem_fd, TRUE, TRUE);
    guint8 *gpt10 = pwm_mmap_instance(mem_fd, 10);
    guint8 *gpt11 = pwm_mmap_instance(mem_fd, 11);

    // Get the resolution for 20 kHz PWM
    guint32 resolution = pwm_calc_resolution(20000000, PWM_FREQUENCY_13MHZ);


    // Ramp up and down a bit
    for(i = 0; i <= 100; i++) {
//        g_print("%3d\n", i);
        pwm_config_timer(gpt10, resolution, i / 100.0);
        pwm_config_timer(gpt11, resolution, i / 100.0);
        usleep(100000);
    }
    sleep(500);
    for (i = 100; i >= 0; i--) {
 //       g_print("%3d\n", i);
        pwm_config_timer(gpt10, resolution, i / 100.0);
        pwm_config_timer(gpt11, resolution, i / 100.0);
        usleep(100000);
    }

    pwm_munmap_instance(gpt10);
    pwm_munmap_instance(gpt11);
    pwm_close_devmem(mem_fd);
}

// vim: set ts=4 et :


omap3530-pwm.c :

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

#include "omap3530-pwm.h"

// Clock configuration registers (TRM p. 470)
#define CM_CLKSEL_CORE 0x48004A40
#define CLKSEL_GPT10_MASK (1 << 6)
#define CLKSEL_GPT11_MASK (1 << 7)


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define CM_CLKSEL_FCLK 0x48004A00
#define FCLKSEL_GPT10_MASK (1 << 11)
#define FCLKSEL_GPT11_MASK (1 << 12)

#define CM_CLKSEL_ICLK 0x48004A10
#define ICLKSEL_GPT10_MASK (1 << 11)
#define ICLKSEL_GPT11_MASK (1 << 12)

#define CLKFREQ_SEL 0x48306D40
#define BIT1 (1 << 1)
#define BIT0 (1 << 0)


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// GPTIMER register offsets
#define GPT_REG_TCLR 0x024
#define GPT_REG_TCRR 0x028
#define GPT_REG_TLDR 0x02c
#define GPT_REG_TMAR 0x038

// Get a guint32 pointer to the register in block `instance` at byte
// offset `offset`.
#define REG32_PTR(instance, offset) ((volatile guint32*) (instance + offset))


// General purpose timer instances.  Not all of these can actually be
// used for PWM --- see the TRM for more information.
static guint32 gpt_instance_addrs[] = {
    0x4903e000, // GPTIMER8
    0x49040000, // GPTIMER9
    0x48086000, // GPTIMER10
    0x48088000, // GPTIMER11
};


// The default Linux page size is 4k and the GP timer register
// blocks are aligned to 4k.  Therefore it is convenient to just
// assume that pages are aligned there for the purposes of mmap()
// (since mmap only maps aligned pages).  This function checks
// that assumption and aborts if it is untrue.
static void
check_pagesize(void)
{
    if (getpagesize() != 4096) {
//        g_error("The page size is %d.  Must be 4096.", getpagesize());
    }
}

// Simply a wrapper around mmap that passes the correct arguments
// for mapping a register block.  `instance_number` must be between
// 1 and 12, or errno will be set to EDOM and MAP_FAILED returned.
// Otherwise the return value is that of `mmap()`.
guint8*
pwm_mmap_instance(int mem_fd, int instance_number)
{
    if (instance_number < 8 || instance_number > 11) {
        errno = EDOM;
        return MAP_FAILED;
    }
    int instance_addr = gpt_instance_addrs[instance_number - 8];
    return mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, instance_addr);
}

// The inverse of `pwm_mmap_instance()`, this is simply a wrapper
// arount `munmap()`.  It returns the underlying `munmap()` call's
// return value.
int
pwm_munmap_instance(guint8 *instance)
{
    return munmap(instance, 4096);
}

// Configure the clocks for GPTIMER10 and GPTIMER11, which can be set to
// use the 13 MHz system clock (otherwise they use the 32 kHz clock like
// the rest of the timers).  Return -1 on failure, with errno set.
int
pwm_config_clock(int mem_fd, gboolean gptimer10_13mhz, gboolean gptimer11_13mhz)
{
    int page_addr = CM_CLKSEL_CORE & 0xfffff000;
    int offset = CM_CLKSEL_CORE & 0xfff;

    guint8 *registers = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
    if (registers == MAP_FAILED) {
        return -1;
    }

    guint32 value = *REG32_PTR(registers, offset);
    value &= ~(CLKSEL_GPT10_MASK | CLKSEL_GPT11_MASK);
    if (gptimer10_13mhz) value |= CLKSEL_GPT10_MASK;
    if (gptimer11_13mhz) value |= CLKSEL_GPT11_MASK;
    *REG32_PTR(registers, offset) = value;

    return munmap(registers, 4096);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
pwm_fclken_clock(int mem_fd, gboolean gptimer10_13mhz, gboolean gptimer11_13mhz)
{
    int page_addr = CM_CLKSEL_FCLK & 0xfffff000;
    int offset = CM_CLKSEL_FCLK & 0xfff;

    guint8 *registers = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
    if (registers == MAP_FAILED) {
        return -1;
    }

    guint32 value = *REG32_PTR(registers, offset);
    value &= ~(FCLKSEL_GPT10_MASK | FCLKSEL_GPT11_MASK);
    if (gptimer10_13mhz) value |= FCLKSEL_GPT10_MASK;
    if (gptimer11_13mhz) value |= FCLKSEL_GPT11_MASK;
    *REG32_PTR(registers, offset) = value;

    return munmap(registers, 4096);
}


int
pwm_iclken_clock(int mem_fd, gboolean gptimer10_13mhz, gboolean gptimer11_13mhz)
{
    int page_addr = CM_CLKSEL_ICLK & 0xfffff000;
    int offset = CM_CLKSEL_ICLK & 0xfff;

    guint8 *registers = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
    if (registers == MAP_FAILED) {
        return -1;
    }

    guint32 value = *REG32_PTR(registers, offset);
    value &= ~(ICLKSEL_GPT10_MASK | ICLKSEL_GPT11_MASK);
    if (gptimer10_13mhz) value |= ICLKSEL_GPT10_MASK;
    if (gptimer11_13mhz) value |= ICLKSEL_GPT11_MASK;
    *REG32_PTR(registers, offset) = value;

    return munmap(registers, 4096);
}


int
pwm_clkfreq_sel(int mem_fd, gboolean gptimer10_13mhz, gboolean gptimer11_13mhz)
{
    int page_addr = CLKFREQ_SEL & 0xfffff000;
    int offset = CLKFREQ_SEL & 0xfff;

    guint8 *registers = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, page_addr);
    if (registers == MAP_FAILED) {
        return -1;
    }

    guint32 value = *REG32_PTR(registers, offset);
    value &= ~(BIT1 | BIT0);
    if (gptimer10_13mhz) value |= BIT1;
    if (gptimer11_13mhz) value |= BIT0;
    *REG32_PTR(registers, offset) = value;

    return munmap(registers, 4096);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



// Calculate the resolution of the PWM (the number of clock ticks
// in the period), which is passed to `pwm_config_timer()`.
guint32
pwm_calc_resolution(int pwm_frequency, int clock_frequency)
{
    float pwm_period = 1.0 / pwm_frequency;
    float clock_period = 1.0 / clock_frequency;
    return (guint32) (pwm_period / clock_period);
}

// Initialize the control registers of the specified timer
// instance for PWM at the specified resolution.
void
pwm_config_timer(guint8 *instance, guint32 resolution, float duty_cycle)
{
    guint32 counter_start = 0xffffffff - resolution;
    guint32 dc = 0xffffffff - ((guint32) (resolution * duty_cycle));

    // Edge condition: the duty cycle is set within two units of the overflow
    // value.  Loading the register with this value shouldn't be done (TRM 16.2.4.6).
    if (0xffffffff - dc <= 2) {
        dc = 0xffffffff - 2;
    }

    // Edge condition: TMAR will be set to within two units of the overflow
    // value.  This means that the resolution is extremely low, which doesn't
    // really make sense, but whatever.
    if (0xffffffff - counter_start <= 2) {
        counter_start = 0xffffffff - 2;
    }

    *REG32_PTR(instance, GPT_REG_TCLR) = 0; // Turn off
    *REG32_PTR(instance, GPT_REG_TCRR) = counter_start;
    *REG32_PTR(instance, GPT_REG_TLDR) = counter_start;
    *REG32_PTR(instance, GPT_REG_TMAR) = dc;
    *REG32_PTR(instance, GPT_REG_TCLR) = (
        (1 << 0)  | // ST -- enable counter
        (1 << 1)  | // AR -- autoreload on overflow
        (1 << 6)  | // CE -- compare enabled
        (1 << 7)  | // SCPWM -- invert pulse
        (2 << 10) | // TRG -- overflow and match trigger
        (1 << 12)   // PT -- toggle PWM mode
    );
}

int
pwm_open_devmem(void)
{
    check_pagesize();

    return open("/dev/mem", O_RDWR | O_SYNC);
}

void
pwm_close_devmem(int dev_fd)
{
    /* This function is useful! */
    close(dev_fd);
}

// vim: set ts=4 expandtab :









On Sun, Feb 13, 2011 at 6:46 PM, Ben Gamari <bgamar...@gmail.com> wrote:
On Sun, 13 Feb 2011 14:14:02 +0530, mohit hada <mohi...@gmail.com> wrote:
> I get the following error :
> *
> root@beagleboard:~#
> ./pwm-demo
>
> [  174.893035] Unhandled fault: external abort on non-linefetch (0x1818) at
> 0x4001e024
> Bus error  *
>
> Please tell me some remedy of this... running a simple gpio program did run
> on the BB-xM fine.
>
A little bit of Googling goes a long ways:

 http://e2e.ti.com/support/embedded/f/354/p/49197/196854.aspx
 http://markmail.org/message/dzcyrbqkeeivesyq
 http://linux.omap.com/pipermail/linux-omap-open-source/2007-November/012094.html

The problem is apparently that your pwm demo doesn't enable the PWM
unit's clocks before accessing the PWM. You should take a look at
section 16.2 to determine which clocks are needed.

- Ben

Przemek Klosowski

unread,
Apr 6, 2014, 2:31:54 AM4/6/14
to beagl...@googlegroups.com
Is it possible that your pwm is an array of ints, and you're indexing
it by byte offsets?
I think pwm[OFFSET] is referring to pwm+4*OFFSET, whereas you need pwm+OFFSET
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to beagleboard...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Muhamed Noufal

unread,
Apr 6, 2014, 5:57:10 AM4/6/14
to beagl...@googlegroups.com, przemek....@gmail.com
I think PWM is an array of integers. If I give pwm+offset, then it will be equivalent to pwm + 4 * offset. Thats why I gave pwm+offset/4 for the correct index of array. Isn't that correct.


You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/7kLlxZ7fg80/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.

milkyway

unread,
Apr 6, 2014, 6:19:33 AM4/6/14
to beagl...@googlegroups.com

Hi Mark,
It would be helpful if you could share the code to get PWM correctly?
Reply all
Reply to author
Forward
0 new messages