2009-02-12 03:17:22     Problems using more than one timer in a C program

Document created by Aaronwu Employee on Aug 14, 2013
Version 1Show Document
  • View in full screen mode

2009-02-12 03:17:22     Problems using more than one timer in a C program

John Doe (UNITED STATES)

Message: 69314   

 

I am having issues with utilizing more than one timer in a C progrom on the 537 stamp board. I am not sure what I am doing wrong. I know that I am opening them and setting them correctly, but when I start the timers the watchdog resets the board. I have tried to use just one timer trying to find a median but have not been successfull. I need one timer at 40 kHzto control a servo, and the other timer at 200 kHz. I cant have anyless than one timer running at 5 usec, and i get really good resolution with the other timer at 25 usec for the servo. My ultimate goal is to integrate both timers and controling of each module in a threaded program. When I use one timer for both I get a lock on reading the timer with the servo and would rather have the lock pushed more to the SoDar. I know that its not my coding for a C program or the threaded program. So I am wondering if there is a bug with running timers at different frequencies, or a hardware restriction. I can post my code modified a little if anyone would like to look at it.

 

 

 

Thanks

 

Dustin

QuoteReplyEditDelete

 

 

2009-02-12 12:34:20     Re: Problems using more than one timer in a C program

John Doe (UNITED STATES)

Message: 69353   

 

I could have made this simpler sounding. I cannot open more than one timer on any of the boards that I have. If I open timer0 and timer1 then set timer0 to 2 usec and timer1 to 25 usec, in the same program, thread, or two individual programs, the watchdog timer resets the board. Is this a hardware issue, resolution issue or did I miss that only one of the 8 timers can be used at one time?

QuoteReplyEditDelete

 

 

2009-02-13 02:17:38     Re: Problems using more than one timer in a C program

Yi Li (CHINA)

Message: 69376   

 

Dustin,

 

Do you have a runnable test case to help us to reproduce?

 

Also what is the system configuration info? You can:

 

# cd uclinux-dist

 

# make bugreport

 

And attach the tar ball here.

 

-Yi

QuoteReplyEditDelete

 

 

2009-02-13 18:58:46     Re: Problems using more than one timer in a C program

John Doe (UNITED STATES)

Message: 69431   

 

here is the code that i used

 

#include<stdio.h>

 

#include<stdlib.h>

 

#include<fcntl.h>

 

#include"bfin_simple_timer.h"

 

int main(){

 

int timer1 = open("/dev/timer0",O_RDWR);

 

int timer2 = open("/dev/timer1",O_RDWR);

 

unsigned long value1, value2;

 

ioctl(timer1,BFIN_SIMPLE_TIMER_SET_PERIOD,2);

 

ioctl(timer2,BFIN_SIMPLE_TIMER_SET_PERIOD,50);

 

//this is where the problem seems to happen

 

ioctl(timer1,BFIN_SIMPLE_TIMER_START);

 

ioctl(timer2,BFIN_SIMPLE_TIMER_START);

 

ioctl(timer1,BFIN_SIMPLE_TIMER_READ,&value1);

 

ioctl(timer2,BFIN_SIMPLE_TIMER_READ,&value2);

 

printf("value1 = %lu\tvalue2 = %lu",value1,value2);

 

close(timer1);

 

close(timer2);

 

return 0;

 

}

 

attached: bugreport.tgz

 

image: linux_01262009

 

other necessary files

 

Dustin

 

linux_01262009

bugreport.tgz

bfin_double_timer_test.c

bfin_simple_timer.h

bfin_double_timer_test

QuoteReplyEditDelete

 

 

2009-02-18 10:55:09     Re: Problems using more than one timer in a C program

John Doe (UNITED STATES)

Message: 69569   

 

I am just curious if there has been any progress on the resolution of this issue. If I am doing something wrong with either the way the kernel is set up or in my program I would like to know, or if it is what it is with the timers.

QuoteReplyEditDelete

 

 

2009-02-18 17:57:21     Re: Problems using more than one timer in a C program

Mike Frysinger (UNITED STATES)

Message: 69587   

 

your code seems to run OK for me:

root:/> /a.out

timer_open: device(0) opened

timer_open: device(1) opened

timer_ioctl TIMER_SET_PERIOD: arg=2, period=250, width=125

timer_ioctl TIMER_SET_PERIOD: arg=50, period=6250, width=3125

value1 = 5469timer_close: device(0) closed

        vtlue2 = 285

imer_close: device(1) closed

 

you're using these timers to generate signals right ?

QuoteReplyEditDelete

 

 

2009-02-18 22:45:38     Re: Problems using more than one timer in a C program

John Doe (UNITED STATES)

Message: 69594   

 

yes Mike that is correct. I am generating pulses for servo's. If you can run both timers concurrently on yours that makes me wonder if there is something wrong with my config... or if I received two bogus boards and the one my teacher is lending is also bogus (which there is a possiblity but I highly doubt). It would be great if I could get this timer issue fixed on our boards before we demo. That way I can re-write my code to utilize two timers and set up threads on each board. The only thing that I am doing in addition to opening a timer is this:

 

(on our sodar board)

 

int sPin = open("/dev/gpio6",O_RDWR);

 

int mPin = open("/dev/gpio7",O_RDWR);

 

//next line is based on 4 micro second tick off of a timer for a 20 millisecond period

 

unsigned long period = 5000, start = 0, finish = 0, beg = 0, end = 0;

 

if(!sPin || !mPin)

 

return -1;

 

if(write(sPin,"I",1) != 1)

 

return -1;

 

if(write(mPin,"O0",2) != 2)

 

return -1;

 

ioctl(timer1,BFIN_SIMPLE_TIMER_READ,&start);

 

write(mPin,"T",1);

 

do{

 

ioctl(timer1,BFIN_SIMPLE_TIMER_READ,&end);

 

if((end - start) >= 425 /*example*/)

 

write(mPin,"O0",2);

 

}while((end-start)<=period);

 

//do other stuff as fast as the board can then from the first read to the end just loops and a servo rotates from -90 to +90 while in between updates we get readings from a sound module

 

 

 

So any Ideas would greatly help... could it be that i am trying to do too much with io? I know this positively wont work with threading because I need a dual core for that, or it would be preferred seeing that I dont have too much time to learn scheduling for threads right now.

 

Dustin

 

PS: thanks again mike for putting up with some of my questions...;-)

QuoteReplyEditDelete

 

 

2009-03-09 10:14:35     Re: Problems using more than one timer in a C program

marat gafarov (RUSSIAN FEDERATION)

Message: 70612   

 

Hi

 

At me a similar problem, somebody knows as it to solve?

 

bf537-stamp, 2008r1.5rc3

Outcomes