473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

problem with timer.

I'm writing a program for testing motors.

I want to use timers for a preset value for sending in and out the
motors.

This is the code I use. (see bottem of the message)

waarde = preset time for sending motors in ms. (works).
the setLeds is the command for steering the motors (works).

The programs works, sends OUT motor one, then StatusM becomes 2;
The motor stops.
StatusM becomes 3, motor one goed IN.

After this the programm keeps sending IN motor one.
StatusM remains 3.

I guess my problem is in the timerReady statement.
The first time the timer is ready, it will give timerReady==true.

But the second time I set the timer, it doesn't.

Does anybody know why ?
// Motor 1 Out
if (StatusM==0)
{
waarde=(Fm1uit*1000.0);
timerSet(1,waarde);
timerStart(1);
u16Value1=1;
setLeds(u16Value1);
StatusM=1;
}

if ((StatusM==1)&(timerReady(1)==true))
{
setLeds(0X0000);
StatusM=2;
}

// Motor 1 In
if (StatusM==2)
{
waarde=(Fm1in*1000.0);
timerSet(1,waarde);
timerStart(1);
u16Value1=2;
setLeds(u16Value1);
StatusM=3;
}

if ((StatusM==3)&(timerReady(1)==true))
{
setLeds(0X0000);
StatusM=4;
}

// Motor 2 Out
if (StatusM==4)
{
waarde=(Fm2uit*1000.0);
timerSet(1,waarde);
timerStart(1);
u16Value1=4;
setLeds(u16Value1);
StatusM=5;
}

if ((StatusM==5)&(timerReady(1)==true))
{
setLeds(0X0000);
StatusM=6;
}

// Motor 2 In
if (StatusM==6)
{
waarde=(Fm2in*1000.0);
timerSet(1,waarde);
timerStart(1);
u16Value1=8;
setLeds(u16Value1);
StatusM=7;
}

Jan 18 '07 #1
3 1307
"Sander" <Sa***********@dancohr.comwrote:
I want to use timers for a preset value for sending in and out the
motors.
I guess my problem is in the timerReady statement.
The first time the timer is ready, it will give timerReady==true.
timerSet(1,waarde);
timerStart(1);
setLeds(u16Value1);
if ((StatusM==1)&(timerReady(1)==true))
Unfortunately, none of these functions are in Standard C. Nor do you
show any definitions or declarations of any of the functions and objects
you use. That makes it impossible to help you, because we have no idea
when timerReady might return true.

Richard
Jan 18 '07 #2
Richard Bos wrote:
"Sander" <Sa***********@dancohr.comwrote:
>I want to use timers for a preset value for sending in and out the
motors.
>I guess my problem is in the timerReady statement.
The first time the timer is ready, it will give timerReady==true.
> timerSet(1,waarde);
timerStart(1);
setLeds(u16Value1);
if ((StatusM==1)&(timerReady(1)==true))

Unfortunately, none of these functions are in Standard C. Nor do you
show any definitions or declarations of any of the functions and objects
you use. That makes it impossible to help you, because we have no idea
when timerReady might return true.
Also the construct `timerReady(1) == true` is deeply suspect. What
was wrong with `timerReady(1)`, if it returns a boolean [1]? And if
it doesn't, why is it being compared to the (unknown [2]) value
`true`?

And why the use of & rather than &&?

Staring at the repetitively repeating code code, why are the
bodies of the ifs so similiar, so screaming out for a loop,
and so denied?

[1] Not necessarily a _Bool-ean.

[2] We don't know where it came from, so although we can hope
it's 1 and/or defined by stdbool, it's just hope.

--
Chris "I have no loop and I must scream" Dollin
"Who do you serve, and who do you trust?" /Crusade/

Jan 18 '07 #3
Solved,

changing to &&, and leaving ou the ==1 did the trick.

Thanks!

Jan 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: tym | last post by:
HELP!!! I'm going round the twist with this... I have a VB6 application which is using DAO to access a database (Please - no lectures on ADO, I know what I'm doing with DAO!!) Ok, problem...
6
by: Antti Laakso | last post by:
Hi i have function like above Public Sub halytystutkinta() Dim ds As New DataSet ds = dl2.HaeHalytys() Dim onkohal As Int16 onkohal = ds.Tables(0).Rows(0).Item("onkohalytys") halid =...
3
by: Kris Palmer | last post by:
hi, can somebody explain this problem? it's driving me crazy! i have a requirement to dynamically create a variable quantity of timers with associated start button based on the contents of a...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
2
by: zamir.khan | last post by:
Hello all, New to the groups, sorry if this the wrong forum/etiquette. I am coding a c++ application that requires the use of a timer-triggered event handler. I decided to use the timer provided...
3
by: ken | last post by:
Hello, I can't figure out how to solve this problem. I modified the timer example given in the help section. It increments a count every 3 millisecond in order to simulate a tank being filled with...
7
by: Fernando Barsoba | last post by:
Hi, After following the advice received in this list, I have isolated the memory leak problem I am having. I am also using MEMWATCH and I think it is working properly. The program does some...
2
by: r norman | last post by:
Please excuse the cross-posting. This question was raised in microsoft.public.dotnet.general but hasn't been answered so I am trying where I can. There are two of us who have the same problem...
6
by: Dave | last post by:
I have a service that has 6 different threads. Each thread has a timer on it that elapses at about the same time (if not the same time). When the timer elapses I am trying to log a message by...
2
by: Johnny Jörgensen | last post by:
I've got a process I want to run in a thread separate from my main application thread, so I've used a backgroundworker component, and in frmMain.Load I invoke the code using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.