Go to Post This place is much brighter than most institutions I have seen. It also seems to be lacking straight jackets which I think is a mistake for many of us. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming
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 11-02-2004, 13:31
emusteve's Avatar
emusteve emusteve is offline
Registered User
AKA: Steve Martin
#0470 (Alpha Omega)
 
Join Date: Jan 2004
Location: Ypsilanti
Posts: 66
emusteve is just really niceemusteve is just really niceemusteve is just really niceemusteve is just really nice
Problems reading io pins as a group

I'm trying to read a group of 4 io pins to get a numerical value as the status of an outboard device. I'm trying it out using the edubot controller so I'm looking at io pins 1-4 which translates to PortA bits 0-3. I was trying to do the following:

sensor_value = (PORTA & 0x0f);

iIt compiles ok, but the result is always 0. I double-checked that I have set the pins to INPUT, and have set the number of analog channels to NO_ANALOG. sensor_value is an unsigned char.

I also tried reading the pins individually as rc_dit_in01 through rc_dig_in04 and got the proper values, so I know the hardware is ok. Anyone know what gives here? Any help would be appreciated.


On another note, I often have problems getting the edubot to take to a program upload. Sometimes it takes 2 or 3 tries before it will run. And it won't hold through a power-down. Do I just have a bad machine? this is true for a fresh load of the Default Code as well as my own, and the same behavior with both versions of the IFI Loader.
  #2   Spotlight this post!  
Unread 11-02-2004, 13:57
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Problems reading io pins as a group

worse case scenario, you could always just do this:
Code:
portAvalue = (rc_dig_in01 << 3) & (rc_dig_in02 << 2) & (rc_dig_in03 << 1) & rc_dig_in04;
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #3   Spotlight this post!  
Unread 11-02-2004, 14:35
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
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,856
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: Problems reading io pins as a group

Quote:
Originally Posted by emusteve
I'm trying to read a group of 4 io pins to get a numerical value as the status of an outboard device. I'm trying it out using the edubot controller so I'm looking at io pins 1-4 which translates to PortA bits 0-3. I was trying to do the following:

sensor_value = (PORTA & 0x0f);

iIt compiles ok, but the result is always 0. I double-checked that I have set the pins to INPUT, and have set the number of analog channels to NO_ANALOG. sensor_value is an unsigned char.

I also tried reading the pins individually as rc_dit_in01 through rc_dig_in04 and got the proper values, so I know the hardware is ok. Anyone know what gives here? Any help would be appreciated.
We're doing the same thing with a BCD switch.

I tested this on the EDU controller and it worked.
With unconnected pins you get 0x0F
With dig I/O 1 signal-to-gnd you get 0x0E
With dig I/O 1&2 connected you get 0x0C


Code:
in user_routines.c, User_Initialization()
 
Set_Number_of_Analog_Channels(NO_ANALOG);	 /* See ifi_aliases.h */
 
IO1 = IO2 = INPUT;	 
IO3 = IO4 = IO5 = INPUT;
IO6 = IO8 = IO10 = INPUT; 
 
// IO3 = IO4 = OUTPUT;
// IO5 = IO7 = IO9 = OUTPUT; 
 
IO7 = IO9 = OUTPUT; 
IO11 = IO13 = IO15 = OUTPUT; 
 
// rc_dig_out03 = rc_dig_out04 = 0;
// rc_dig_out05 = 0;
 
 
in user_routines.c, Process_Data_From_Master_uP()
 
	PrintString((char *) "PORTA = ");
	PrintByte(PORTA & 0x0f);
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 11-02-2004 at 14:46.
  #4   Spotlight this post!  
Unread 11-02-2004, 14:38
The Lucas's Avatar
The Lucas The Lucas is offline
CaMOElot, it is a silly place
AKA: My First Name is really "The" (or Brian)
FRC #0365 (The Miracle Workerz); FRC#1495 (AGR); FRC#4342 (Demon)
Team Role: Mentor
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Dela-Where?
Posts: 1,564
The Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond repute
Send a message via AIM to The Lucas
Re: Problems reading io pins as a group

Quote:
Originally Posted by deltacoder1020
worse case scenario, you could always just do this:
Code:
portAvalue = (rc_dig_in01 << 3) & (rc_dig_in02 << 2) & (rc_dig_in03 << 1) & rc_dig_in04;
Shouldn't it be
Code:
portAvalue = (rc_dig_in01 << 3) + (rc_dig_in02 << 2) + (rc_dig_in03 << 1) + rc_dig_in04;
[EDIT]
actually it should be
Code:
portAvalue = (rc_dig_in04 << 3) + (rc_dig_in03 << 2) + (rc_dig_in02 << 1) + rc_dig_in01;
since rc_dig_in01 is in bit0 (least significant) of PORTA
[/EDIT]
__________________
Electrical & Programming Mentor ---Team #365 "The Miracle Workerz"
Programming Mentor ---Team #4342 "Demon Robotics"
Founding Mentor --- Team #1495 Avon Grove High School
2007 CMP Chairman's Award - Thanks to all MOE members (and others) past and present who made it a reality.
Robot Inspector
"I don't think I'm ever more ''aware'' than I am right after I burn my thumb with a soldering iron"

Last edited by The Lucas : 11-02-2004 at 14:50.
  #5   Spotlight this post!  
Unread 11-02-2004, 17:00
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Problems reading io pins as a group

whichever - it depends on what direction you hooked the device up in
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #6   Spotlight this post!  
Unread 11-02-2004, 17:40
emusteve's Avatar
emusteve emusteve is offline
Registered User
AKA: Steve Martin
#0470 (Alpha Omega)
 
Join Date: Jan 2004
Location: Ypsilanti
Posts: 66
emusteve is just really niceemusteve is just really niceemusteve is just really niceemusteve is just really nice
Re: Problems reading io pins as a group

The point was to make the routine as fast as possible by not taking the time and space to read each line individually. I've already got that to work, but it makes for messy code.

Mark's post has the greatest similarity to mine in code structure. I wonder why PrintByte worked for him, but using PORTA to transfer a value to another variable doesn't seem to?

Steve
  #7   Spotlight this post!  
Unread 11-02-2004, 18:33
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Problems reading io pins as a group

All around, False means closed (On) True means open (off).

You can add, or just OR it (| I think), Which makes more sense to me. You're merging bits, not adding values.
  #8   Spotlight this post!  
Unread 11-02-2004, 21:21
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Problems reading io pins as a group

the way it works out, either will work. you're right though, bitwise OR is probably faster.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #9   Spotlight this post!  
Unread 11-02-2004, 22:00
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
Re: Problems reading io pins as a group

The problem is that you are using bitwise and(&), you should be using logical AND(&&).
the difference is this:

"&" (bitwise and) ANDs each corresponding bit individually.
11110000 & 11111111 = 11110000
10101010 & 10101010 = 10101010

"&&" (logical and) ANDs the entire word at a time. (it will only be true if the two arguements are the same.)
11110000 && 11111111 = 00000000
10101010 && 10101010 = 11111111
__________________
1139 Alumni
  #10   Spotlight this post!  
Unread 11-02-2004, 22:14
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Problems reading io pins as a group

Quote:
Originally Posted by Rickertsen2
The problem is that you are using bitwise and(&), you should be using logical AND(&&).
the difference is this:

"&" (bitwise and) ANDs each corresponding bit individually.
11110000 & 11111111 = 11110000
10101010 & 10101010 = 10101010

"&&" (logical and) ANDs the entire word at a time. (it will only be true if the two arguements are the same.)
11110000 && 11111111 = 00000000
10101010 && 10101010 = 11111111
I don't believe that's what he's trying to do - he's using the & to mask off the four bits he's trying to read, which is correct.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #11   Spotlight this post!  
Unread 11-02-2004, 22:37
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
Re: Problems reading io pins as a group

Quote:
Originally Posted by The Lucas
Shouldn't it be
Code:
portAvalue = (rc_dig_in01 << 3) + (rc_dig_in02 << 2) + (rc_dig_in03 << 1) + rc_dig_in04;
[EDIT]
actually it should be
Code:
portAvalue = (rc_dig_in04 << 3) + (rc_dig_in03 << 2) + (rc_dig_in02 << 1) + rc_dig_in01;
since rc_dig_in01 is in bit0 (least significant) of PORTA
[/EDIT]
Technically bit0 would be the MSB, because of the endianness.



Btw jsut wxactly what are you trying to do? mask off bits or compare values?
__________________
1139 Alumni
  #12   Spotlight this post!  
Unread 12-02-2004, 10:09
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
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,856
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: Problems reading io pins as a group

Quote:
Originally Posted by emusteve
Mark's post has the greatest similarity to mine in code structure. I wonder why PrintByte worked for him, but using PORTA to transfer a value to another variable doesn't seem to?

Steve
I originally ran:
Code:
unsigned char port_a;
 
port_a = PORTA & 0x0f;  /* mask off unused bits */
PrintByte(port_a);
to more closely emulate what you were doing. I simplified it to the minimum number of lines before posting.
This works as well, so it isn't an assignment problem.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #13   Spotlight this post!  
Unread 12-02-2004, 11:35
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Problems reading io pins as a group

Quote:
Originally Posted by Rickertsen2
"&&" (logical and) ANDs the entire word at a time. (it will only be true if the two arguements are the same.)
11110000 && 11111111 = 00000000
10101010 && 10101010 = 11111111
I believe that is wrong - && returns 1 if both arguments are true (non-zero). This is because the logical and works on two boolean values, and returns a third. Anything except 0 is treated as true in C.
  #14   Spotlight this post!  
Unread 12-02-2004, 12:22
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Problems reading io pins as a group

steven is correct - anything with a set bit qualifies as the "true" state, the only false state being 0.

you cannot really show how the boolean && works using bits - it's a logical operator, versus the bitwise operator &.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #15   Spotlight this post!  
Unread 13-02-2004, 00:30
Random Dude Random Dude is offline
Oregon State Head FTA
AKA: Chris
no team (Oregon Robotics Tournament & Outreach Program)
 
Join Date: Aug 2002
Rookie Year: 1998
Location: Oregon
Posts: 142
Random Dude will become famous soon enoughRandom Dude will become famous soon enough
Re: Problems reading io pins as a group

Ahh.. I found the problem..

Mark, if you notice, tested his code on the EDU controller, where PORTA0-3, is bits 1-4

However on the fullsize RC, bits1-4 are PORTB2-5. Infact PORTA isn't even used on the outputs at all.

The full size RC uses parts of Ports B,H,& J
The EDU controller uses parts of Ports A,F,H.

And they actually use different halves of Port H, so I really would suggest against using the port names directly.

Hope this helps....
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
TTL pins Dave... Control System 3 07-02-2004 23:59
Joystick problems archiver 2001 3 24-06-2002 02:40
Hits, Misses, & Suggestions -- long message archiver 2000 17 23-06-2002 23:36
Nationals a la NCAA archiver 2000 20 23-06-2002 22:25


All times are GMT -5. The time now is 23:59.

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