hzeller / txtempus

A DCF77, WWVB, JJY and MSF clock LF-band signal transmitter using the Raspberry Pi
GNU General Public License v3.0
443 stars 71 forks source link

Add Nvidia Jetson Series Support #23

Closed pjueon closed 2 years ago

pjueon commented 2 years ago

related to #22

Main differences from Raspberry Pi platform:

hzeller commented 2 years ago

Very nice, thanks! I'll have a first look at the PR.

I think we can't leave out the attenuation feature as some time signals require it; for instance DCF77 has the carrier always on, but specifically calls for attenuation. So for completeness and feature parity with the Raspberry Pi hardware, we need both LOW and OFF.

pjueon commented 2 years ago

Thanks for the detailed feedback! I'll fix it when I get home.

pjueon commented 2 years ago

Facing some troubles in attenuating the signal. example

When I set the attenuation pin as output and set it LOW, the voltage at "A" doesn't decrease at all. And the voltage at the attenuation pin remains ~0.35V not 0V. (output pin is ~1.5V)

I'm assuming that the voltage at attenuation pin is being pulled-up to the output pin, but I'm not familiar with HW stuff, I'm not sure...

If you have any suggestion please let me know.

hzeller commented 2 years ago

If the voltage is 1.8V, this indidcates that the GPIO ports are connected to the internal core voltage of the CPU and they will have issue to drive anything and it will probably dangerous to even connecting the coil, as these tiny mosfets in the output stage will not be able to move the current.

I strongly suggest to connect the GPIO pins via a 1.8V -> 3.3V level shifter to (a) relieve the GPIO pins (b) have enough drive strength for the external components such as coil and pulldown.

pjueon commented 2 years ago

If the voltage is 1.8V, this indidcates that the GPIO ports are connected to the internal core voltage of the CPU and they will have issue to drive anything and it will probably dangerous to even connecting the coil, as these tiny mosfets in the output stage will not be able to move the current.

I strongly suggest to connect the GPIO pins via a 1.8V -> 3.3V level shifter to (a) relieve the GPIO pins (b) have enough drive strength for the external components such as coil and pulldown.

I have too little knowledge about HW stuff to understand what you're suggesting, Sorry. Could you explain with a picture please?

And when I asked this problem to Nvidia developers forum, someone linked this pdf. Maybe it's related. customizing_the_jetson_nano_40-pin_expansion_header_v1.2.pdf.pdf

It's about the "level shifters" in Jetson Nano, but I cannot understand it. I don't even know what "level shifters", "buffers", "driving" mean...

icb- commented 2 years ago

A level shifter translates a signal with one voltage (like 1.8V) to a signal with a different voltage (like 3.3V). A buffer takes a signal and repeats it on its output. Buffers can often do level shifting, depending on their input thresholds.

In the circuit below, you have two tri-state buffers doing level shifting. Tri-state means the output can be driven (set to a low or high signal) or can be set "tri-stated" or "high-Z" and effectively disconnected (not driven high or low). When the output enable signal (the one at the bottom of the triangle) is low, the output signal is driven. When it's high, the output is disconnected. The circle means it's an active-low or inverted signal.

The "PWM" signal is passed through, and raised to a higher voltage. It is always driven.

The "A̅T̅T̅E̅N̅U̅A̅T̅E̅" (the overline means an active low signal) signal causes the output to be pulled lower (attenuate the voltage across the inductor) when pulled low. I haven't read through all of your code, so you may need to invert the attenuate signal in software to attenuate when you need the signal attenuated.

The inductor is the "antenna".

Something like 74LV1T125 should be suitable for this level shifting. They should be powered by a 3.3V supply. A 74LVC125 may work too, but the would be operating out of spec (it wants 2V on its input for a high signal when powered from 3.3V)

Screen Shot 2022-02-15 at 7 50 29 AM
pjueon commented 2 years ago

@icb- Thank you very much. I think I kind of understand.

So a buffer is something like a transistor, right? Fortunately I had a couple of transistors so I tried this setup: new_setup_jetson

I changed the code a bit (setting the attenuation pin to high to attenuate the signal), and It WORKS!!

So I need 2 NPN transistors for this. Is there any better/simpler setup? (ex> works with only one transistor)

icb- commented 2 years ago

So a buffer is something like a transistor, right?

Not quite.

A buffer like in the 74125 can drive the output high, low, or high impedance (not driven, tri-state, high-Z). It's a digital device.

A BJT like you have in your circuit works kind of like a switch. It's not quite a switch, it's a current amplifier, but that's a good enough analogy for now. You should use a PNP BJT on the high side instead of the NPN you have in your diagram.

That might be good enough for how this circuit works.

You're not going to get away with less than two transistors. One is switching the higher voltage across the "antenna" from the PWM signal. The other is switching in a resistor in parallel to the "antenna" to attenuate the signal.

It might help to redraw the circuit more like this to show the two parallel current paths, the "antenna" and the attenuator.

Screen Shot 2022-02-15 at 1 35 28 PM

I say "antenna" in quotes and draw it as an inductor, because I don't think this is really acting as a radio transmitter, but is inductively coupling the signal into the antenna on the clock.

pjueon commented 2 years ago

You should use a PNP BJT on the high side instead of the NPN you have in your diagram.

Why? At the moment I only have NPN transistors. And I thought there would be no difference for our application. Is there any difference?

pjueon commented 2 years ago

If the voltage is 1.8V, this indidcates that the GPIO ports are connected to the internal core voltage of the CPU and they will have issue to drive anything and it will probably dangerous to even connecting the coil, as these tiny mosfets in the output stage will not be able to move the current.

I strongly suggest to connect the GPIO pins via a 1.8V -> 3.3V level shifter to (a) relieve the GPIO pins (b) have enough drive strength for the external components such as coil and pulldown.

After reading the following document many times( and thanks to icb-'s explanation) ,I think I'm just starting to understand it.

customizing_the_jetson_nano_40-pin_expansion_header_v1.2.pdf.pdf

According to this document, the Jetson Nano's GPIO pin headers are already connected to the level shifters (TXB0108).

image

When I set the GPIO output to HIGH, the pin is being pulled up to 3.3v by 4k ohm internally. And when I set it to LOW, it is being pulled down to the GND with 4k ohm internally.

When I said the output pin voltage was ~ 1.5V, I connected 4~5k ohm to the pin. If I connected ~25k ohm to the pin and set the pin HIGH (without PWM) I got ~3V.

From the document:

The TXB0108 devices are not intended for use in open-drain applications or to drive low impedance (i.e. directly driving an LED) or high capacitive loads (i.e. driving a long wire, or multiple loads).

So maybe I should use more registers. The reason why I couldn't pull down the signal to the GND even if I set the pin to LOW from my first setup, it's probably because the pin is internally pulled down to GND with 4k ohm. I'll give a try again with higher registers !

icb- commented 2 years ago

You should use a PNP BJT on the high side instead of the NPN you have in your diagram.

Why?

That's just how transistors work. To fully turn an NPN BJT on (saturate), the base needs to be at a higher voltage than the collector. If you have it on the high side of the circuit, you can't ever reach that. There are lots of explanations of why on the Internet, like this one and this one and the linked resources from them.

Technically, you should also have a resistor between the control pins and the base of each transistor to limit the base current, but it looks like your level shifter is already doing that for you.

If you need to use only NPN transistors, it would be better to drive it from the low side like this.

Screen Shot 2022-02-16 at 7 35 13 AM

The TXB0108 devices are not intended for use in open-drain applications

This is why you can't drive the attenuate signal directly from the level shifter. You need to be able to drive it low, but not high. That's what open-drain is (or open-collector with BJTs). You may be able to drive the PWM signal directly from the level shifter, and the ATTENUATE signal with a transistor like this, if the level shifter can source enough current.

Screen Shot 2022-02-16 at 7 59 23 AM
pjueon commented 2 years ago

@icb- I just tested the second image you posted, and it DOES work!

Screen Shot 2022-02-16 at 7 59 23 AM

That's just how transistors work. To fully turn an NPN BJT on (saturate), the base needs to be at a higher voltage than the collector. If you have it on the high side of the circuit, you can't ever reach that.

I see! I really didn't know that. Thanks again for your kind explanation. I truly had zero knowledge about this kind of stuff, haha.

Please forgive me to ask one more basic question. I found this setup from this video: https://youtu.be/6SHGAEhnsYk?t=596

image

This setup looks like switching the signal instead of attenuating it. Is my understanding correct?

icb- commented 2 years ago

This setup looks like switching the signal instead of attenuating it. Is my understanding correct?

It's doing both. It's operating the transistor in its active region, where it's amplifying the base-emitter current.

When GPIO4 is high, a small current flows into the base, resulting in a large current flowing through the transistor collector-emitter. This is because R3 is a relatively high value, so a relatively smaller current flows into the base.

When GPIO17 is high, a larger current flows into the base resulting in an even larger current flowing through the transistor collector-emitter. This is because R2 is a relatively low value, so a relatively larger current flows into the base.

When both GPIO4 and GPIO17 are high, you have a still larger current.

pjueon commented 2 years ago

This setup looks like switching the signal instead of attenuating it. Is my understanding correct?

It's doing both. It's operating the transistor in its active region, where it's amplifying the base-emitter current.

When GPIO4 is high, a small current flows into the base, resulting in a large current flowing through the transistor collector-emitter. This is because R3 is a relatively high value, so a relatively smaller current flows into the base.

When GPIO17 is high, a larger current flows into the base resulting in an even larger current flowing through the transistor collector-emitter. This is because R2 is a relatively low value, so a relatively larger current flows into the base.

When both GPIO4 and GPIO17 are high, you have a still larger current.

I see. Thank you very much!

pjueon commented 2 years ago

@hzeller I've just pushed some commits to this branch. Could you check if I properly fixed everything I need to?

pjueon commented 2 years ago

Oops, I almost forgot to update the .gitignore file. Fixed it now!

JDat commented 2 years ago

Pardon my electronics! 1st schematic (two transistors in series) doesn't looks good, because if lower transistor is closed, upper will get negative bias on base relative to emitter.

Las schematic (different GPIOs on one transistor base) looks fine, but need some fine tuning with base resistors. Not for beginners.

What about this schematic? More components, but... Fine tune R6 (set and forget + share to community) and that's it! PS: Even if I like R2 and R4, they can be omitted.

2022-02-16-194657_1366x744_scrot .

pjueon commented 2 years ago

Pardon my electronics! 1st schematic (two transistors in series) doesn't looks good, because if lower transistor is closed, upper will get negative bias on base relative to emitter.

Las schematic (different GPIOs on one transistor base) looks fine, but need some fine tuning with base resistors. Not for beginners.

What about this schematic? More components, but... Fine tune R6 (set and forget + share to community) and that's it! PS: Even if I like R2 and R4, they can be omitted.

2022-02-16-194657_1366x744_scrot .

Thanks for the advice! Hmm, then how do you think about this one? Personally I like it because it only requires 1 transistor and looks relatively simple for me.

Screen Shot 2022-02-16 at 7 59 23 AM

I tested this setup and it works well. So if you think this setup has no big issue, I think it would be good enough for this project.

pjueon commented 2 years ago

Reminder. @hzeller Could you check this please?

What I fixed:

pjueon commented 2 years ago

Reminder again. @hzeller

Could you check this please...?