problem with timer.

S

Sander

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;
}
 
R

Richard Bos

Sander said:
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
 
C

Chris Dollin

Richard said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,269
Latest member
vinaykumar_nevatia23

Latest Threads

Top