CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

GPS code help, PIC 16F877A
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
talhahs



Joined: 14 Oct 2010
Posts: 14

View user's profile Send private message

PostPosted: Tue Mar 08, 2011 12:26 pm     Reply with quote

Hi John,

Yeah its a remote controlled UGV and I would like to add GPS to it so that I can get its lat and long tracked...just to make it look comprehensive...I would then show it up on satellite view using google maps in my VB GUI.

I am already done with its drive part, it currently uses Xbee modules and Hardware USART was in use. Data packets are small as you have seen the chars up in the code, VB 6 sends a char for every move.

Ok, I would have to change PC port to soft USART, i am still thinking whether I can buffer GPS sentences and extract lat,long so that its drive mechanism would remain unharmed (bcz it is in real time).
tr6coug



Joined: 31 Oct 2011
Posts: 1

View user's profile Send private message

PostPosted: Sun Nov 06, 2011 12:14 pm     Reply with quote

ezflyr wrote:
Hi,

You might want to consider using a GPS "engine", rather than the eTrex unit. A number of good modules can be found at Sparkfun.com for around $50 USD. These modules typically have TTL interfaces, and the NMEA data stream can be configured.......

To exclude all but the desired string from your circular buffer, you can implement a "state machine" in your serial interrupt handler. It starts with a State = 0, and stores no characters in this state. Once the '$' character is received, this character is stored, and then State is incremented. With State = 1, the next character must be a 'G', and if so, the character is stored, and the state is incremented. With State = 2, the next character must be a 'P', and if so, the character is stored, and the state is incremented. If at anytime, you don't have a match, reset State = 0. Keep doing this until you have enough of the NMEA string to ensure you've got the correct one. At that State value, just store all the incoming characters until the 'CR' character is received, and then start all over.

You'll learn a lot more if you code it yourself, but here is a small code fragment from my ISR to get you going:



Code:

   TempChar = fgetc(GPS);
   
   switch (RxState)
   {
      Case 0:
         if (TempChar == '$')
            RxState++;   //"$" received, so RxState = 1
         break;

      Case 1:
         if (TempChar == 'G')
            RxState++;   //"G" received, so RxState = 2
         else
            RxState=0;   //wrong character received, so we reset RxState
         break;





John


Wow, thanks. That really solved my problem of filtering out the GPRMC sentence. Smile
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Nov 06, 2011 12:31 pm     Reply with quote

For what it's worth...

I do something very similar in my GPS Serial ISR where I start saving the string at the start when the $ is received... (rather than just a ring buffer)

When the string is done, the ISR sets a flag and stop collecting.. (I use more than one string, so I can't use the ISR to filter unless I want to make it arguably long - remember, ISR's should be simple!)

My entire ISR looks like this:
Code:

#INT_RDA
void isr_gps ( void ) {
   unsigned char c;

   gps_timeout = GPS_TIMEOUT_VALUE;

   c = rcreg;

   switch (gps_state) {
      case 0: if (! gps_have_packet) {
               if (c == '$') {
                  gps_index = 0;
                  gps_string[gps_index] = c;
                  gps_index = 1;
                  gps_state = 1;;
               }
            }
            break;
      case 1:   gps_string[gps_index] = c;

            if  ( (c == 0x0A) || (c == 0x0D) ) {
               gps_have_packet = 1;
               gps_string[gps_index + 1] = 0;
               gps_state = 0;
            }

            if ( gps_index >= sizeof(gps_string)-1 ) {
               gps_string[gps_index + 1] = 0;
               gps_have_packet = 1;
               gps_state = 0;
            } else {
               gps_index++;
            }

            break;

      default:   gps_state = 0;
               break;
   }
}


if life were timing critical, I would set up 2 buffers to allow the ISR to ping-pong between them.

but it's not..

So....

In the main loop, an IF catches the signal and sends the string to be processed.

From there, The processing function immediately makes a copy and releases the ISR to continue capturing.

Then compares the first field all the $GP strings of interest) against a const string array with the items I want to process and I copy them to a temp string one by one and then use strcmp() via strtok().

From there, based on which string found, process the rest of the fields accordingly.

A little different, definitely more code, but then I'm also processing more strings.

Cheers,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group