View Single Post
  #10   Spotlight this post!  
Unread 07-12-2003, 16:12
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: EduBot and USART ports

Quote:
Originally Posted by Dave...
James,
Thanks for the info, but it brings a few more questions. You've obviously used this code with the Edubot since you have references to "ifi_..." and "rc_dig...". Where exactly does this code belong? Do I copy it to the user_routines.c file or somewhere else? Also, you use the include directive for "sensors.h" but this doesn't seem to be in one of the directories with the Edubot sourcecode or /mcc18/h folder. If this is a separate header file, can you please post it as well?

The digital compass we are trying to use sends three bytes through the USART. Will these correspond to sensors[1], sensors[2] and sensors[3] directly, or is this just a coincidence?

Your help is appreciated.
First off here is sensors.h :
PHP Code:
/*******************************************************************************
* FILE NAME: sensors.h
*
* DESCRIPTION:
*  stuff for sensors.c
*  
*
*  BY: James Rickertsen
*******************************************************************************/

/*void Open2USART( unsigned char ,config, unsigned int spbrg); */

#define DEBUG_MODE 1

extern unsigned char sensors[3];

void Read_Sensors(void); 
the code i posted previously could be put in user_routines.c, but we have it in a seperate file, sensors.c



I will give a breif description of how this code works:
First let me explain exactly how this code works. We actually have 3 sensors multiplexed to the serial port through some buffer ICs, which are controlled by digital outs 14-16. The output from these three sensors are stored in sensors[1] sensors[2] and sensors[3]. The distance sensors we are using send a 3 byte packet. The 1st byte is always 01010101 the reamaining 2 bytes are ASCII characters, which contain the distance in cm.

The first important thing this code does it to configure the buffers i described above. The majority of the code is in a loop, which runs three times. The first time it reads the first sensor, the second time the second sensor... since you are only using one sensor you can kill the whole loop thing as well as the buffer code.

Next the serial port is configured:
PHP Code:
Open2USART(
    
USART_TX_INT_OFF &
    
USART_RX_INT_OFF &
    
USART_ASYNCH_MODE &
    
USART_EIGHT_BIT &
    
USART_CONT_RX &
    
USART_BRGH_LOW129); /*initialize serial connection*/ 
We are trying to read in a three byte packet. The problem is we have no way to syncronize when we start recieving and when the sensor starts transmitting. The solution is to read in 5 bytes:
PHP Code:
gets2USART(input_buffer5);    /*Read in data from sensors*/ 
Somewhere within these 5 bytes there will always be one whole packet.
since the first byte is always 01010101 we can look for that:
PHP Code:
for (signature_pos=0signature_pos<3signature_pos++) {
            if (
input_buffer[signature_pos] == SENSOR_SIGNATURE) {
                break;
            }
        } 
the rest of the code just converts the ACSII string into decimal, so we can do useful stuff with it and then stores that value in sensors[]
I hope this makes even the slightest inkling of sense. If it does i am glad i was able to help. O am always happy to answer questions.
__________________
1139 Alumni

Last edited by Rickertsen2 : 07-12-2003 at 17:17.