Go to Post Honestly though, having a cave would be one of the greatest places to build a robot. There's already lack of light and lots of floor space! Well, if you have a good cave sponsor, that is. - Bryce Clegg [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #12   Spotlight this post!  
Unread 31-01-2008, 12:14
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,854
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: IR_Sensor Programming

Quote:
Originally Posted by Red Mage View Post
...a mysterious port j. We found where it is in the code but cannot understand how to use it.
Here's the background on the mysterious PORTJ.

The robot system variables we use (e.g., rc_dig_in18) are just aliases for connections or "windows" into the real PIC hardware. In the hardware, 8-bit registers are wired to hold the constantly sampled state from the pins (or the output state we want) and our aliases are just simpler ways to look at individual bits within these registers, one bit per digital I/O pin.

If you look in the file ifi_aliases.h you'll see these aliases defined for our 18 digital inputs:
Code:
#define rc_dig_in01 PORTBbits.RB2 
#define rc_dig_in02 PORTBbits.RB3 
#define rc_dig_in03 PORTBbits.RB4 
#define rc_dig_in04 PORTBbits.RB5 
#define rc_dig_in05 PORTBbits.RB6 
#define rc_dig_in06 PORTBbits.RB7 
#define rc_dig_in07 PORTHbits.RH0
#define rc_dig_in08 PORTHbits.RH1
#define rc_dig_in09 PORTHbits.RH2
#define rc_dig_in10 PORTHbits.RH3
#define rc_dig_in11 PORTJbits.RJ1
#define rc_dig_in12 PORTJbits.RJ2
#define rc_dig_in13 PORTJbits.RJ3
#define rc_dig_in14 PORTCbits.RC0
#define rc_dig_in15 PORTJbits.RJ4
#define rc_dig_in16 PORTJbits.RJ5
#define rc_dig_in17 PORTJbits.RJ6
#define rc_dig_in18 PORTJbits.RJ7
You'll notice all the values we use come through some register, such as:
-- PORTB for the interrupts on digital inputs 1-6
-- PORTH for inputs 7-10
-- PORTJ for inputs 11-13 and 15-18
-- PORTC for input 14

We can use any of these registers we wish or just use the aliases everyone's accustomed to. PORTH also has four pins grouped together that we could easily use by masking out (using the "&" operator) the other upper four bits in that register.

The demo code wants only the last four bits of PORTJ (15-18), so a simple way to eliminate the other unwanted values is to just truncate them by shifting the four bits we want to the right thereby pushing the four bits we don't want out of the variable altogether, e.g., 10001111 >> 4 becomes 00001000

The trick demonstrated with PORTJ allows the code to capture all the pin values at once in an instant of time. It just illustrates the potential window of error that could occur if the IR sensor changed the signals while we were testing them one at a time.

P.S. The excrutiating detail on PORTJ is described in the PIC18F8722_data_sheet.pdf that came on the CBOT compact disk in the KOP.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 01-02-2008 at 10:23. Reason: tense
 


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
Programming in Python and Explaination of Programming roboxking Programming 22 07-01-2008 16:08
programming motors with programming kit BorisTheBlade FIRST Tech Challenge 4 01-11-2005 19:03
programming great_one411 Programming 2 15-02-2003 08:59
programming great_one411 General Forum 1 14-02-2003 11:28
Programming archiver 2000 1 23-06-2002 22:34


All times are GMT -5. The time now is 19:11.

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