Go to Post Whether we realize it or not, we've all been touched by the works of Dr. Kamen - through his TED talks, through his research and scores of publications in pediatric oncology, or perhaps more directly through his daughter. What an incredible life, what an incredible legacy. - Taylor [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 04-12-2003, 17:56
Dave... Dave... is offline
Registered User
#0005 (Robocards)
 
Join Date: Aug 2001
Location: AFL/MHS Melvindale, MI
Posts: 64
Dave... will become famous soon enough
EduBot and USART ports

The 2004 Edubot includes two serial ports (USART): USART1 is the programming port which has voltage conversion for interfacing with an RS-232 port, and USART2 is the TTL port on the Edubot. No dedicated handshaking line is available on the TTL port, although Innovation FIRST states that any of the digital I/O pins could be used for this purpose.

Has anyone succeeded in modifying the code to make use of the TTL USART2 port? I have a USART compatible sensor, but am just beginning to learn C and the Microchip 18F8520.

I miss the days of just hooking up a pot or analog sensor (gyro) and being able to read the value of a byte directly. Mechanical engineers get spooked around all this programming/computer science stuff.

Your help is appreciated.

Dave...
__________________
"...don't worry about that mechanical problem, Dave can fix it in the programming..."
  #2   Spotlight this post!  
Unread 04-12-2003, 18:09
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...
The 2004 Edubot includes two serial ports (USART): USART1 is the programming port which has voltage conversion for interfacing with an RS-232 port, and USART2 is the TTL port on the Edubot. No dedicated handshaking line is available on the TTL port, although Innovation FIRST states that any of the digital I/O pins could be used for this purpose.

Has anyone succeeded in modifying the code to make use of the TTL USART2 port? I have a USART compatible sensor, but am just beginning to learn C and the Microchip 18F8520.

I miss the days of just hooking up a pot or analog sensor (gyro) and being able to read the value of a byte directly. Mechanical engineers get spooked around all this programming/computer science stuff.

Your help is appreciated.

Dave...
Yes, i have some experience with the USARTs. What kind of sensors are you using?
If u need some code i can do that. I can give you some code i wrote to read these sensors.
__________________
1139 Alumni
  #3   Spotlight this post!  
Unread 04-12-2003, 20:14
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: EduBot and USART ports

Quote:
Originally Posted by Rickertsen2
Yes, i have some experience with the USARTs. What kind of sensors are you using?
If u need some code i can do that. I can give you some code i wrote to read these sensors.
I can see using those modified sensors with a Stamp that has no ADC, but why not just buy the GP2D12 and use the ADC on the RC? They're charging you twice as much to make it twice as hard to use.
  #4   Spotlight this post!  
Unread 04-12-2003, 21:07
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 seanwitte
I can see using those modified sensors with a Stamp that has no ADC, but why not just buy the GP2D12 and use the ADC on the RC? They're charging you twice as much to make it twice as hard to use.
I had them on hand(ripped them off an old stamp project).
__________________
1139 Alumni
  #5   Spotlight this post!  
Unread 04-12-2003, 23:38
Don Taylor Don Taylor is offline
Registered User
#0343 (Metal in Motion)
 
Join Date: Dec 2001
Location: Seneca South Carolina
Posts: 45
Don Taylor is an unknown quantity at this point
Re: EduBot and USART ports

I am also interested in using the TTL port on the EDUBOT to communicate with another micorprocessor. If anyone has some code to do this I would really appreciate seeing a copy.

Don Taylor
Team 343
Metal-in-Motion
  #6   Spotlight this post!  
Unread 05-12-2003, 12:22
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 Don Taylor
I am also interested in using the TTL port on the EDUBOT to communicate with another micorprocessor. If anyone has some code to do this I would really appreciate seeing a copy.

Don Taylor
Team 343
Metal-in-Motion
Rigt now im @ school and its lunch. I'll post it later today during my last period class.
__________________
1139 Alumni
  #7   Spotlight this post!  
Unread 06-12-2003, 22:01
Dave... Dave... is offline
Registered User
#0005 (Robocards)
 
Join Date: Aug 2001
Location: AFL/MHS Melvindale, MI
Posts: 64
Dave... will become famous soon enough
Re: EduBot and USART ports

Quote:
Originally Posted by Rickertsen2
Yes, i have some experience with the USARTs. What kind of sensors are you using?
We're trying to use a digital compass (available from Digikey) Honeywell model HMR3100. See the datasheet at: http://www.magneticsensors.com/products.html

The ini_aliases.h header file has the following line:
#define usart2_RX PORTGbits.PORTG2
However, whenever I try to build the project with "usart2_RX" in my user code, I receive the following error:
Executing: "c:\mcc18\bin\mcc18.exe" -p=18F8520 "user_routines.c" -fo="user_routines.o" /i"C:\mcc18\h" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\EduCode\user_routines.c:328:Error [1205] unknown member 'PORTG2' in '__tag_43'
Does anyone know what "unknown member" or "__tag_43" means and how I can resolve this issue?
__________________
"...don't worry about that mechanical problem, Dave can fix it in the programming..."
  #8   Spotlight this post!  
Unread 07-12-2003, 12:42
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

Let me appologize for not posting this when i said i would. This stuff was on my MP3 player, which i lost the cable to and just found.

anyway here ya go:
PHP Code:
/*******************************************************************************
* FILE NAME: sensors.c
*
* DESCRIPTION:
*  Contains routines to read DIRRS+ Sensors
*  
*  Function prototypes etc are in sensors.h
*
*  BY: James Rickertsen
*
*******************************************************************************/

#include <usart.h>
#include <stdlib.h>
#include "printf_lib.h"
#include "ifi_default.h"
#include "ifi_aliases.h"
#include "user_routines.h"
#include "ifi_utilities.h"
#include "sensors.h"

#define SENSOR_SIGNATURE 0b10101010

unsigned char sensors[3];


/* ------------------------ This function reads all three sensors ---------------------- */
void Read_Sensors(void) {
    
unsigned char i;
             
char input_buffer[7];
              
char sensor_buffer[3];
    
char signature_pos;

    
printf("test-1\n");
    for(
1<= 3i++)
    {

        
/*configure buffer to selelct desired sensor*/
        
switch(i)
        {  
            case 
1:
                
rc_dig_out14 0;
                
rc_dig_out15 1;
                
rc_dig_out16 1;
                break;
            case 
2:
                
rc_dig_out14 1;
                
rc_dig_out15 0;
                
rc_dig_out16 1;
                break;    
            case 
3:
                
rc_dig_out14 1;
                
rc_dig_out15 1;
                
rc_dig_out16 0;
                break;
        }
        
//printf("test-2\n");
        
Open2USART(
            
USART_TX_INT_OFF &
            
USART_RX_INT_OFF &
            
USART_ASYNCH_MODE &
            
USART_EIGHT_BIT &
            
USART_CONT_RX &
            
USART_BRGH_LOW129); /*initialize serial connection*/
        //printf("test-3\n");
    
        
gets2USART(input_buffer5);    /*Read in data from sensors*/
        //printf("test-4\n");
            
        // Find the sensor signature in the sensor input (input_str)
        
for (signature_pos=0signature_pos<3signature_pos++) {
            if (
input_buffer[signature_pos] == SENSOR_SIGNATURE) {
                break;
            }
        }
        
        
// Copy the sensor data following the sensor signature into temp_str
        
sensor_buffer[0] = input_buffer[signature_pos+1];
        
sensor_buffer[1] = input_buffer[signature_pos+2];
        
sensor_buffer[2] = '\0';
        
        
/*
        if( input_str[1] == 0b10101010) // Fish the data we are looking for out of the input string
        {
            temp_str[1] = (char) input_str[2];
            temp_str[2] = (char) input_str[3];
        } else if( input_str[2] == 0b10101010)
        {
            temp_str[1] = (char) input_str[3];
            temp_str[2] = (char) input_str[4];
        } else if( input_str[3] == 0b10101010)
        {
            temp_str[1] = (char) input_str[4];
            temp_str[2] = (char) input_str[5];
        }
        */

        //printf("test-6\n");
        
sensors[i] = atoi(sensor_buffer); /*convert ACSII string to int value*/
    
}
    
    
#ifdef DEBUG_MODE
        
printf("L = %d, M = %d, R = %d\n", (int)sensors[1], (int)sensors[2], (int)sensors[3]);
    
#endif
}


/******************************************************************************/
/******************************************************************************/
/******************************************************************************/ 

Quote:
Originally Posted by Dave...
We're trying to use a digital compass (available from Digikey) Honeywell model HMR3100. See the datasheet at: http://www.magneticsensors.com/products.html

The ini_aliases.h header file has the following line:
#define usart2_RX PORTGbits.PORTG2
However, whenever I try to build the project with "usart2_RX" in my user code, I receive the following error:
Executing: "c:\mcc18\bin\mcc18.exe" -p=18F8520 "user_routines.c" -fo="user_routines.o" /i"C:\mcc18\h" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\EduCode\user_routines.c:328:Error [1205] unknown member 'PORTG2' in '__tag_43'
Does anyone know what "unknown member" or "__tag_43" means and how I can resolve this issue?
I honestly have no idea whats wron with that. Could you post some more code? Rather than set up the USART config registers and write to the TX and RX registers directly, etc, i would use the built in compiler libraries as in the example above. For more info on these functions see:
http://www.microchip.com/download/to...b18/51297b.pdf
there is also 2 really good whitepapers on using the USART in asyncronous mode at the assembly level:
http://www.microchip.com/download/ap...c16/00774a.pdf
http://www.microchip.com/download/li...oots/usart.pdf
__________________
1139 Alumni

Last edited by Rickertsen2 : 07-12-2003 at 14:14.
  #9   Spotlight this post!  
Unread 07-12-2003, 15:35
Dave... Dave... is offline
Registered User
#0005 (Robocards)
 
Join Date: Aug 2001
Location: AFL/MHS Melvindale, MI
Posts: 64
Dave... will become famous soon enough
Re: EduBot and USART ports

Quote:
Originally Posted by Rickertsen2
anyway here ya go:
PHP Code:
/*******************************************************************************
* FILE NAME: sensors.c
*
* DESCRIPTION:
*  Contains routines to read DIRRS+ Sensors
*  
*  Function prototypes etc are in sensors.h
*
*  BY: James Rickertsen
*
*******************************************************************************/

#include <usart.h>
#include <stdlib.h>
#include "printf_lib.h"
#include "ifi_default.h"
#include "ifi_aliases.h"
#include "user_routines.h"
#include "ifi_utilities.h"
#include "sensors.h"

#define SENSOR_SIGNATURE 0b10101010 
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.
__________________
"...don't worry about that mechanical problem, Dave can fix it in the programming..."
  #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.
  #11   Spotlight this post!  
Unread 07-12-2003, 16:37
Dave... Dave... is offline
Registered User
#0005 (Robocards)
 
Join Date: Aug 2001
Location: AFL/MHS Melvindale, MI
Posts: 64
Dave... will become famous soon enough
Re: EduBot and USART ports

Quote:
Originally Posted by Rickertsen2
...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.

...We are trying to read in a three byte packet. The problem is we have no syncronize when we start recieving and when the sensor starts transmitting.
James,
This actually makes quite a bit of sense. Even though we have only have one sensor, it too sends three bytes in a row. If the digital compass has a clk, it will send data in sync with the clk signal. If we tell it to operate in conitunous mode, it sends the three bytes and then waits 480ms before sending the next packet.

I'll try adding the sensors.h file to our workspace.

Dave...
__________________
"...don't worry about that mechanical problem, Dave can fix it in the programming..."
  #12   Spotlight this post!  
Unread 07-12-2003, 21:55
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
Re: EduBot and USART ports

Quote:
Originally Posted by Dave...
We're trying to use a digital compass (available from Digikey) Honeywell model HMR3100. See the datasheet at: http://www.magneticsensors.com/products.html

The ini_aliases.h header file has the following line:
#define usart2_RX PORTGbits.PORTG2
However, whenever I try to build the project with "usart2_RX" in my user code, I receive the following error:
Executing: "c:\mcc18\bin\mcc18.exe" -p=18F8520 "user_routines.c" -fo="user_routines.o" /i"C:\mcc18\h" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\EduCode\user_routines.c:328:Error [1205] unknown member 'PORTG2' in '__tag_43'
Does anyone know what "unknown member" or "__tag_43" means and how I can resolve this issue?
That seems to be an error in their default code. Here is the PORTGbits struct from ifi_picdefs.h:

Code:
extern volatile near union {
  struct {
	unsigned RG0:1;
	unsigned RG1:1;
	unsigned RG2:1;
	unsigned RG3:1;
	unsigned RG4:1;
  };
  struct {
	unsigned CCP3:1;
	unsigned TX2:1;
	unsigned RX2:1;
	unsigned CCP4:1;
	unsigned CCP5:1;
  };
  struct {
	unsigned :1;
	unsigned CK2:1;
	unsigned DT2:1;
  };
} PORTGbits;
It looks like they wanted
Code:
#define usart2_RX       PORTGbits.RG2
or
Code:
#define usart2_RX       PORTGbits.RX2
etc...

which is the receive port for USART 2.

The error just doesn't show up if you don't use usart2_RX because the preprocessor doesn't insert PORTGbits.PORTG2 anywhere in the code and the compiler never sees it.
  #13   Spotlight this post!  
Unread 11-12-2003, 22:57
Dave... Dave... is offline
Registered User
#0005 (Robocards)
 
Join Date: Aug 2001
Location: AFL/MHS Melvindale, MI
Posts: 64
Dave... will become famous soon enough
Re: EduBot and USART ports

Quote:
Originally Posted by Jay Lundy
That seems to be an error in their default code. Here is the PORTGbits struct from ifi_picdefs.h:
You're right. Innovation First corrected this in their latest release of the Edubot sourcecode posted on their website (12/8/2003). They responded back to an email I sent and acknowledged the error. Rolling out a new control system with so many new features and having to write new code for the more powerful chip was no small task. All in all, I think they did an outstanding job (as always).
__________________
"...don't worry about that mechanical problem, Dave can fix it in the programming..."
  #14   Spotlight this post!  
Unread 01-02-2004, 00:02
Gene F's Avatar
Gene F Gene F is offline
FIRST Fanatic
AKA: Gene Falendysz
#0343 (Metal in Motion)
Team Role: Engineer
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Oconee County, SC
Posts: 218
Gene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to behold
Send a message via AIM to Gene F
Unhappy Question and Re: EduBot and USART ports

First, thanks to all that have posted to this thread, it has helped us greatly. We are still having one problem though. Our code works great on the EDU Bot controller but will not work on our Robot Controller. We have looked at the signals with a scope and think there might be something wrong with our controller(it appears there is something driving the line from the controller). Our question is this! Is there any differences in using the TTL port on the EDU Bot controller and the Robot Controller?
__________________
- Gene Falendysz
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


All times are GMT -5. The time now is 09:35.

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