View Single Post
  #27   Spotlight this post!  
Unread 03-05-2008, 07:58
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,809
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Need help with PWM 1-2ms pulse control

Quote:
Originally Posted by Generalx5 View Post
In the code, in the User_routine file, there is a fuction called Limit_Switch_Max && Limit_Switch_Min && Limit_Mix.

Do I need those? What is the purpose for that to be there? It appears to be some sort of drive system limiter. But is it okay it I delete that? Im using something else instead.


Are the interrupts better digital inputs than making more digital inputs from the 1-16 pins? Im just courious as to if maybe the interrupts may have an advantage over the others since by default the are digital inputs.
You don't need those functions in user_routines.c, so they can be deleted.
The Limit_Switch_Min/Max are examples of how functions work, while Limit_Mix is handy for making a joystick behave arcade-style.

For what you're doing the interrupt digital inputs will behave just like the other digital inputs, so you can simply use them.
The interrupt inputs have some special properties that make them useful in very time critical tasks. Measuring and reacting to things much faster than a hand operated switch. We take advantage of interrupts with special sensors or highly accurate timed events.

------------------
I'd take the parentheses away from your real code as Alan suggested in his previous post, or move them.
In the integer math you're doing it's important to do all your multiplications first followed by any divisions.
Code:
analog input * 127 / 1023   or (analog input * 127) / 1023
// rather than
analog input * ( 127 / 1023)
This starts getting into more quirks of programming, but because of the integer data types we're using, each step in the calculation only allows a whole integer result.

So if analog input = 512 (halfway on the pot)
analog input * (127 / 1023) would be calculated by the EDU as 512 * (0) because 127/1023=0.0254154 which gets truncated to the integer 0

If the parenthesis are removed (or moved) then
(analog input * 127) / 1023 = (512 * 127) / 1023 = 8704 / 1023 = 85.33333 = 85

So the order you do calculations becomes very important.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 03-05-2008 at 08:22.