Author Topic: ntpd and gps pps confusion / RS232C, serial, TTL serial  (Read 3183 times)

0 Members and 1 Guest are viewing this topic.

Offline tkamiyaTopic starter

  • Super Contributor
  • ***
  • Posts: 2178
  • Country: us
ntpd and gps pps confusion / RS232C, serial, TTL serial
« on: September 25, 2020, 07:45:47 am »
I believe this question is best fit in metrology section, although one can argue computing section is better....  I see this as time-keeping and GPSDO, so here goes.

If one is connecting GPS to a host running ntpd and gpsd, it is said that RISING EDGE of the pps should indicate beginning of a new second.  From my GPS board, TXD and RXD must go into a level converter board, then to a Com1 port on the computer.  That means TTL level 1 (5V) gets converted to RS232C MARK (-12V ish).  Voltage for TTL and RS232C are backwards. 

PPS typically connects to PIN 1 which is CD (Carrier Detect) on 9 pin connectors.  Now, If I do the same treatment as above, rising edge of the GPS output will now become a falling edge.  What do I do here?  Do I maintain the rising edge by inverting, then level converting OR do I just convert the signal level?

To make things more complicated, most serial ports on modern computers do not do +/-12V.  It's TTL level but it works with regular serial ports.  I've used old modem, so I can see they are compatible to a degree.  (logic wise, not the signal level) 

Now I have 3 different signal method and voltage combination.
Have anyone thought through this and figured it out?
 

Offline thinkfat

  • Supporter
  • ****
  • Posts: 2150
  • Country: de
  • This is just a hobby I spend too much time on.
    • Matthias' Hackerstübchen
Re: ntpd and gps pps confusion / RS232C, serial, TTL serial
« Reply #1 on: September 25, 2020, 08:05:31 am »
You need to run the 1PPS output through an inverter first (like, 74HCT04 or 74HCT14), then into the RS232 level converter (MAX3232, I guess).
Everybody likes gadgets. Until they try to make them.
 

Offline guenthert

  • Frequent Contributor
  • **
  • Posts: 712
  • Country: de
Re: ntpd and gps pps confusion / RS232C, serial, TTL serial
« Reply #2 on: September 25, 2020, 05:38:24 pm »
I believe this question is best fit in metrology section, although one can argue computing section is better....  I see this as time-keeping and GPSDO, so here goes.

If one is connecting GPS to a host running ntpd and gpsd, it is said that RISING EDGE of the pps should indicate beginning of a new second. 
    The manual of your GPS receiver should state on which edge the new seconds starts.  If the output is open collector / open drain TTL, then I'd expect the falling edge.  The jitter on the other edge will be considerably worse (but perhaps not bad enough to matter in the context of NTP).

From my GPS board, TXD and RXD must go into a level converter board, then to a Com1 port on the computer.  That means TTL level 1 (5V) gets converted to RS232C MARK (-12V ish).  Voltage for TTL and RS232C are backwards. 

PPS typically connects to PIN 1 which is CD (Carrier Detect) on 9 pin connectors.
     Not sure, if that is typically, but yes, Linux' PPS driver expects it there by default when using a RS-232 device.

Now, If I do the same treatment as above, rising edge of the GPS output will now become a falling edge.  What do I do here?  Do I maintain the rising edge by inverting, then level converting OR do I just convert the signal level?
     Regardless of raising or falling, only the leading edge is relevant.

To make things more complicated, most serial ports on modern computers do not do +/-12V.  It's TTL level but it works with regular serial ports. 
     I'd say it's wrong and potentially harmful to say it's TTL level.  It might not be +/-12V, but it won't be TTL level (voltages in the range of +/-3V are undefined in the RS232 standard and shouldn't be used).  It might be around +/-5V, which TTL devices wouldn't be keen on receiving.

   I've used old modem, so I can see they are compatible to a degree.  (logic wise, not the signal level) 

Now I have 3 different signal method and voltage combination.
Have anyone thought through this and figured it out?
     You might also want to consider instead of feeding the TTL<->RS232 level shifted (slow) signal to a PC, feeding the TTL<->3V level shifted signal to a GPPIN on a Raspberry Pi (or other embedded computer) for lower latency.
 

Offline tkamiyaTopic starter

  • Super Contributor
  • ***
  • Posts: 2178
  • Country: us
Re: ntpd and gps pps confusion / RS232C, serial, TTL serial
« Reply #3 on: September 25, 2020, 05:45:05 pm »
Thanks!  Yes, that's true:  LEADING edge, not necessary a rising edge is valid.

My concern really is, how is this leading edge perceived by the relieving end.  I've read some more...  Apparently, logic level for TXD and RXD are reversed: meaning -V for mark and +V for space.  But signal pins including DCD are not.  That makes my whole question null and void. 

I should have researched more, but to be honest, there are so many implementation and adaptation of serial RS232C, I could never be sure without really thinking it through and measuring.  I was thoroughly confused last night.

By the way....  this is not a RasPi project.  Host is a intel based low power server running Linux.  I purposely made it this way so that swapping it out is easy.  I bought 5 of these Dell T-20 barebone units when Dell had them on sale.  I have two units as hot stand-by for various uses.  It's T-20 with regular Intel CPU (G3220?), not the Xeons.  Although not as low as RasPi, power consumptions are really low like 35 watts.  (I use a small SSD)
« Last Edit: September 25, 2020, 05:49:20 pm by tkamiya »
 

Offline notfaded1

  • Frequent Contributor
  • **
  • Posts: 559
  • Country: us
Re: ntpd and gps pps confusion / RS232C, serial, TTL serial
« Reply #4 on: September 25, 2020, 07:04:00 pm »
Something like this might help:  https://www.sparkfun.com/products/449
The smallest and easiest to use serial conversion circuit on the market! This board has one purpose in life - to convert RS232 to TTL and vice versa (TX and RX). This will allow a microcontroller to communicate with a computer. Shifter SMD is powered from the target application and can run at any voltage! That's right - power the board at 5V and the unit will convert RS232 to 5V TTL. Power the board at 2.8V and the Shifter board will convert RS232 to 2.8V CMOS TTL. Includes two indicator LEDs for TX and RX. Runs from 300bps up to 115200bps.

Bill
.ılılı..ılılı.
notfaded1
 

Offline syau

  • Frequent Contributor
  • **
  • Posts: 368
  • Country: hk
Re: ntpd and gps pps confusion / RS232C, serial, TTL serial
« Reply #5 on: September 26, 2020, 08:22:24 am »
Never an issue as on the receiver side, same conversion happen again, the -ve RS232 will be convert to +ve TTL (or 3.3v logic high) before get process by the comm chip.
 

Offline thinkfat

  • Supporter
  • ****
  • Posts: 2150
  • Country: de
  • This is just a hobby I spend too much time on.
    • Matthias' Hackerstübchen
Re: ntpd and gps pps confusion / RS232C, serial, TTL serial
« Reply #6 on: September 26, 2020, 03:43:08 pm »
My concern really is, how is this leading edge perceived by the relieving end.  I've read some more...  Apparently, logic level for TXD and RXD are reversed: meaning -V for mark and +V for space.  But signal pins including DCD are not.  That makes my whole question null and void. 

TTL is not compatible with RS232 signaling levels, not for data, not for control signals. 0V is simply not valid, not for data, not for control. Typical converters have inverting outputs (see the MAX3232 data sheet!), if you want to feed a TTL 1PPS into a DCD input, you need a RS232 line driver and if you want to use one of the usual converter boards (e.g. https://www.pollin.de/p/rs232-ttl-wandler-mit-max3232-810358) , you need an additional inverter on the TTL side.
Everybody likes gadgets. Until they try to make them.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16600
  • Country: us
  • DavidH
Re: ntpd and gps pps confusion / RS232C, serial, TTL serial
« Reply #7 on: September 26, 2020, 04:58:04 pm »
Have anyone thought through this and figured it out?

I have dealt with this many times and it is easy; ALL RS-232 LEVEL SHIFTERS ARE INVERTING! ALWAYS! If the outputs from the GPS are logic level and not inverted, THEN THEY ARE NOT FUCKING RS-232!  Sometimes companies deceptively write "RS-232 compatible" in their documentation.

My solution was to build a discrete non-inverting RS-232 level shifter, but most people would do what thinkfat suggests by adding an inverter before the level shifter.
 

Offline tkamiyaTopic starter

  • Super Contributor
  • ***
  • Posts: 2178
  • Country: us
Re: ntpd and gps pps confusion / RS232C, serial, TTL serial
« Reply #8 on: September 27, 2020, 04:25:19 pm »
Got this to work.  GPS is CMOS serial.... not even TTL level but reverse logic.  TXD and RXD went into level converter/inverter and into RS232C port.  Now they are talking to each other.  I had one of those all-in-one module already built, so just used that. 

PPS was different.  Naturally, it's a positive going signal.  I had to connect directly to RS232C, pin 1 (DCD).  I guess voltage was enough to trigger PPS input for kernel NTP, which I'm surprised...  I measured 2.5V high. 

I always have all kinds of issues with serial.  It's a non-standard standard.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf