Go to Post Stop. Breathe. Relax. QUIT STATING STUFF THAT YOU DON'T KNOW TO BE TRUE. - Rich Kressly [more]
Home
Go Back   Chief Delphi > Technical > Technical Discussion
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-02-2006, 13:30
Max Brin Max Brin is offline
Registered User
FRC #1943 (Neat Team)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Israel
Posts: 52
Max Brin has a spectacular aura aboutMax Brin has a spectacular aura aboutMax Brin has a spectacular aura about
loop problems

Hey guys,

I had some problems using the timers and I need something that will take time asap, so I did this:

Code:
void pulse(void)
{
pwm06=255;
for (int i=0;i<30;i++)
	{
	if (i == 29)
		{
		pwm06=127;
		}
	}
}
It means the pwm06 will get 255 and when it gets to 29 it will stop.
It will take about 0.5 second right?
anyways I get a syntax error, can somebody help me?

Thanks!
  #2   Spotlight this post!  
Unread 09-02-2006, 13:46
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: loop problems

Four problems jump out at me immediately.

1) This code will execute in a fraction of an eyeblink. It won't even come close to a half second.

2) 255 is not a proper value to send to a pwm. The highest number you should use is 254.

3) You aren't calling Putdata(&txdata) inside the loop. That means the value being stored in pwm06 will not be sent to the hardware until some time after the whole thing is done, so it'll never be set to the high value.

4) Finally, you didn't tell us what the syntax error is, so we can't easily tell you how to fix it.

It's almost never a good idea to put a timing loop like this inside your code, even if you get the loop time set to what you want. If you don't like interrupt-based timers, you can use the fact that Process_Data_From_Master_uP() is called about 39 times per second and maintain a counter to do things after a certain number of calls.
  #3   Spotlight this post!  
Unread 09-02-2006, 14:01
Max Brin Max Brin is offline
Registered User
FRC #1943 (Neat Team)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Israel
Posts: 52
Max Brin has a spectacular aura aboutMax Brin has a spectacular aura aboutMax Brin has a spectacular aura about
Re: loop problems

Ok..
Im passing on to the real timers.
Can somebody explain me shortly how to use them, and what files do I need and where to include them?
I had some problem with this.
  #4   Spotlight this post!  
Unread 09-02-2006, 14:04
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: loop problems

Quote:
Originally Posted by Alan Anderson
4) Finally, you didn't tell us what the syntax error is, so we can't easily tell you how to fix it.
The syntax error is because of the "int" inside the "if" condition.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #5   Spotlight this post!  
Unread 09-02-2006, 14:31
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: loop problems

Max

You can try something like this to set the pwm value to 127 after 30 loops:
Code:
void pulse(void)
{
  static int loop_count = 0;
  if(loop_count < 30)
  {
    pwm06 = 254;
  }
  else
  {
    pwm06 = 127;
  }
  loop_count++;
}
Then, you would want to call this in your main loop. Note that this method never resets loop_count, so this would run for 30 loops at 254 and then stop.
  #6   Spotlight this post!  
Unread 09-02-2006, 14:36
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,187
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: loop problems

Quote:
Originally Posted by Dave Scheck
Max

You can try something like this to set the pwm value to 127 after 30 loops:
Code:
void pulse(void)
{
  static int loop_count = 0;
  if(loop_count < 30)
  {
    pwm06 = 254;
  }
  else
  {
    pwm06 = 127;
  }
  loop_count++;
}
Then, you would want to call this in your main loop. Note that this method never resets loop_count, so this would run for 30 loops at 254 and then stop.
As Dave said.. when you want to keep track of how many times something has looped, use a counter variable. You should try to stay away from while and for loops in your code. Even when you are in your Default Routine, you are still nested within a while loop that will execute the default routine 39 times per second.
  #7   Spotlight this post!  
Unread 10-02-2006, 13:03
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: loop problems

Quote:
Originally Posted by Max Brin
Hey guys,

I had some problems using the timers and I need something that will take time asap, so I did this:

Code:
void pulse(void)
{
pwm06=255;
for (int i=0;i<30;i++)
	{
	if (i == 29)
		{
		pwm06=127;
		}
	}
}
It means the pwm06 will get 255 and when it gets to 29 it will stop.
It will take about 0.5 second right?
anyways I get a syntax error, can somebody help me?

Thanks!
syntax error is caused by trying to declare i in the for loop
in C all variables must be declared at the top of the function.

This still will not do what you want because the pwm value is not sent out until Putdata is called. (see user_routines.c )

One way to accomplish what you want is to use a static counter variable. Increment each time the function is called. When the desired value is reached, change the pwm value and reset the counter variable.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop time for OperatorControl function? Debug blows... Chris_Elston Programming 10 13-02-2006 14:42
Anyone Else Having Problems with Q&A on FIRST? Windwarrior General Forum 6 25-01-2006 10:54
While Loop Require in OperatorControl? Chris_Elston Programming 2 15-01-2006 14:29
Rewriting main loop Max Lobovsky Programming 4 04-01-2005 18:35
laser radar with BS2p using RS232 problems... chei_UCF19 Programming 6 26-02-2004 15:21


All times are GMT -5. The time now is 05:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi