-2

I have a relay contact closure event that needs to be timestamped accurately ( 1 msec) with a GPS and the PPS output... I am not sure how to feed the relay contact output to a microcontroller and then synchronize the microcontroller clock to the GPS ...plus how to get the UTC afterall? Can you please help me. thanks

Rastin
  • 1
  • 1
    the nmea is well documented. and the exact shape and location of the gps pulse for that receiver is also documented with the rest of the interface for that receiver. then you just write some code. – old_timer Feb 08 '16 at 14:49
  • can you please explain more? – Rastin Feb 08 '16 at 21:56
  • google nmea. then look at the gps module you have or the receipt or page you bought it from and google the model/part number. – old_timer Feb 09 '16 at 00:16

1 Answers1

0

If your microcontroller has at least two interrupts based on hardware pins, you could connect the relay to one of the interrupt-generating pins, and the PPS to the other interrupt-generating pin.

You will need to connect the NMEA (or other proprietary protocol of your GPS) to the corresponding port in your microcontroller. Some common buses are UART or SIP.

Then, every time that you get a PPS interrupt, you enable a global flag that can be used in the main loop to reset a counter. This counter will tell you how far apart from the PPS the relay switched (if it happens within that second). If you know the base frequency of your counter, you can convert the counter into fractions of seconds. Note that if both edges of the relay state change have to be detected, you will need an interrupt source capable to interrupt on both edges (or use two interrupts)

Then, if the Relay interrupt goes off, you can get the value of the counter upon interrupt, and save it in storage, send it to host, etc. (Note, it would be best to save the value in RAM, lift a flag of "value present", and leave the sending/storing to the main loop, then turning off the flag).

Finally, when you receive a complete NMEA message (this could be being parsed in your main loop by a state machine for instance), you can send this information to the host or storage along with the counter that you saved to time your relay state change. Note please that the NMEA message will be generated and decoded with a certain delay from the PPS, so you will need to compensate for that.

Jorge Torres
  • 1,426
  • 12
  • 21
  • Thanks Jorge. That 's a perfect answer but I have lots of questions! I have not worked with mcs and electronics for a few years and need to understand this properly before buying the elements...do you have any recomendation for the mc? – Rastin Feb 09 '16 at 05:26
  • The ATMega or the PIC24 series could be good choice. They are simple, inexpensive, and readily available from almost any electronics supplier. Some of them have internal oscillators, so you can keep you component count really small at the prototyping stage (a concern you listed in your previous comment). I would though use a good oscillator for the final implementation since your application is somehow time bound. You could also consider prototyping first with an Arduino and then getting the components that you need after. Please don't forget to upvote if you found the answer useful – Jorge Torres Feb 09 '16 at 05:40
  • Hi again Jorge. I wish to use Arduino as some researchers have experience with it ... but I am not sure what board I need to buy... I saw a tutorial but this does not use the PPS which is vital for my application... I have a source that is triggered with an encllosure and need to capture the precise closure time.,, https://quaxio.com/arduino_gps/ – Rastin Feb 09 '16 at 06:06
  • Does Arduino boards use the ATMega or the PIC24 series or not... I am confused as I cannot find the specification of the microcontrollers installed on Arduino products and find out if they have two interrupt inputs. any advice? – Rastin Feb 09 '16 at 07:27
  • Can you please explain this a little more "Note that if both edges of the relay state change have to be detected, you will need an interrupt source capable to interrupt on both edges (or use two interrupts)" – Rastin Feb 09 '16 at 07:57
  • Arduino uses the atmegamicrocontroller series in most boards. Depending on your microcontroller, some can only detect one edge of logical change at a time (you can program them to interrupt only either on rising or falling edge). Some other microcontrollers allow you to program some of their pins on any logical change, interrupting on both riding and falling edge. Depending on your application you might need unidirectional put bidirectional detection – Jorge Torres Feb 09 '16 at 13:04