Go to Post "He who seeks originality will often find novelty, but not great design." - IKE [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-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 01-28-2008, 11:11 AM
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Program a motor to turn on and off every other second.....

Hello, i'm having a problem.... If someone could help, i would greatly appreciate it. In the user routines.c file, i need to make pwm01 turn on for 1 second and turn off for another second, then turn on for another second, and so on and so forth. I want it to be on p3_sw_Trig.... Does anyone know how i would do it? Please help... thank you very much.
  #2   Spotlight this post!  
Unread 01-28-2008, 12:14 PM
GRS GRS is offline
Registered User
FRC #1764
 
Join Date: Jan 2008
Location: KC, MO
Posts: 34
GRS is an unknown quantity at this point
Re: Program a motor to turn on and off every other second.....

Here's some untested code that should do what you're asking, basically this code toggles pwm01 between 0 and 127 every 44 loops, and makes pwm01 go back to off if the button is not pressed.

A static byte causes the compiler to not delete the data in a variable after it leaves a function, and "loops++" tells it to add 1 to the variable and store it back into itself, essentially saying loops = loops + 1

Code:
void code()
{
  static byte loops = 0; // which loop are we on?
  if (p3_sw_trig != 0)
  {
    loops++; // add 1 to the loop counter
    if (loops <= 44) {
      pwm01 = 127; // motor off
    } else if (loops <= 88) {
      pwm01 = 0; // motor on
    } else {
      loops = 0; // go back to 0
    }
  } else {
    pwm01 = 127; // switch not on, motor is off!
  }
}

Last edited by GRS : 01-28-2008 at 12:17 PM.
  #3   Spotlight this post!  
Unread 01-28-2008, 12:21 PM
Roger Roger is offline
Registered User
FRC #1153
 
Join Date: Jan 2006
Rookie Year: 1900
Location: Walpole MA
Posts: 604
Roger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond repute
Re: Program a motor to turn on and off every other second.....

First of all, I'm getting confused which one you are -- ChrisR_522 or jax1488? And now programmr? jax1488 was asking the same question in this thread, but he thanked me for answering ChrisR_522's question in this thread. No biggie, but multiple names and duplicate questions are confusing at best and wastes time for sure.

Tom Line's answer here is a good starting point. Wrap that if block inside another if that checks for the trigger. Follow each true/false branch by yourself (make a flowchart if needed) to make sure it works.

And tell us all why your robot is doing this -- I think I speak for everybody here that we're curious what the robot is going to do.
  #4   Spotlight this post!  
Unread 01-28-2008, 12:49 PM
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Re: Program a motor to turn on and off every other second.....

It's me using two members' names because i didnt have my own... sorry if i confused you. I'd like to thank you for the code given above. Theres only one thing though, it says syntax error....

void code()
{ IT SAYS THIS IS AN ERROR!!!
static byte loops = 0; // which loop are we on?

Do you know what could possibly be the problem? Thank You.
  #5   Spotlight this post!  
Unread 01-28-2008, 12:54 PM
Roger Roger is offline
Registered User
FRC #1153
 
Join Date: Jan 2006
Rookie Year: 1900
Location: Walpole MA
Posts: 604
Roger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond repute
Re: Program a motor to turn on and off every other second.....

try

void code (void)
  #6   Spotlight this post!  
Unread 01-28-2008, 01:03 PM
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Re: Program a motor to turn on and off every other second.....

hey sorry to keep bothering you guys, but i still says theres a syntax error at that same spot.
  #7   Spotlight this post!  
Unread 01-28-2008, 01:24 PM
JohnC's Avatar
JohnC JohnC is offline
my other name is nigel
FRC #0360 (360 Revolution)
Team Role: Programmer
 
Join Date: Mar 2005
Rookie Year: 2005
Location: user_routines.c
Posts: 100
JohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the rough
Send a message via AIM to JohnC
Re: Program a motor to turn on and off every other second.....

It would be very helpful to know what the error is...in fact, you should ALWAYS post the error.

Looks like, though, you might have a function without a declaration. So open up a header file (your team's, if you have your own library, but user_routines.h will work) and add in:

void code(void);

Or whatever you decide to use for the function's name.
__________________
What place are we at? ... TODAI!
  #8   Spotlight this post!  
Unread 01-28-2008, 01:56 PM
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Re: Program a motor to turn on and off every other second.....

this is the error i get:

"G:\2005\test pulse\user_routines.c:231:Error: syntax error"
  #9   Spotlight this post!  
Unread 01-28-2008, 03:05 PM
Chaos in a Can Chaos in a Can is offline
Joel Spadin
FRC #1736 (Robot Casserole)
Team Role: Programmer
 
Join Date: Mar 2007
Rookie Year: 2007
Location: Peoria, IL
Posts: 58
Chaos in a Can is an unknown quantity at this point
Send a message via MSN to Chaos in a Can
Re: Program a motor to turn on and off every other second.....

Ah yes, the ever helpful "syntax error"...

Try replacing "byte" with "unsigned char". They mean the same thing.
I don't know if byte works with MPLAB.

Also, if you get a syntax error on the last line of a file, make sure to put an extra blank line at the end of the code.
__________________
2006 Xerox Creativity Award
2007 General Motors Industrial Design Award
2008 Judges' Award
2009 Chrysler Team Spirit Award

  #10   Spotlight this post!  
Unread 01-28-2008, 03:08 PM
GRS GRS is offline
Registered User
FRC #1764
 
Join Date: Jan 2008
Location: KC, MO
Posts: 34
GRS is an unknown quantity at this point
Re: Program a motor to turn on and off every other second.....

Oh. Hehe. byte.. yea, that's supposed to be a char. (VB6 vs. C...)
  #11   Spotlight this post!  
Unread 01-29-2008, 05:42 AM
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Re: Program a motor to turn on and off every other second.....

IT STILL SAYS : "G:\2005\test pulse\user_routines.c:232:Error: syntax error"


void code()
{ THIS IS LINE 232 HELP PLEASE....
static unsigned char loops = 0; // which loop are we on?
if (p3_sw_trig != 0)
{
loops++; // add 1 to the loop counter
if (loops <= 44) {
pwm01 = 127; // motor off
} else if (loops <= 88) {
pwm01 = 0; // motor on
} else {
loops = 0; // go back to 0
}
} else {
pwm01 = 127; // switch not on, motor is off!
}
}


Someone please help me try to get this issue resolved. Thank You
  #12   Spotlight this post!  
Unread 01-29-2008, 05:56 AM
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,114
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Program a motor to turn on and off every other second.....

You can't have two else statements like that.

It's

if
else if
else

If you need it longer, it's

if
else if
else if
else if
else
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
Turn off outlining? Justin M. Inventor 11 02-01-2007 08:16 AM
How fast does the Solenoids turn on and off? Generalx5 Robotics Education and Curriculum 2 01-26-2007 12:09 AM
Anyone know how fast the Solenoids on the MINI RC can turn on and off? Generalx5 Control System 1 01-06-2007 06:39 AM
Program machine to turn and stop CharlieWilken Programming 1 02-19-2004 11:50 AM
hanging off off other robots that are hanging off the horiz bar Andrew Dahl Rules/Strategy 15 01-12-2004 06:14 PM


All times are GMT -5. The time now is 03:36 AM.

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


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