System clock and analog level translation questions

Status
Not open for further replies.

emarsh

Member
I'm an experienced professional software engineer but a hardware noob. For decades I've felt that pure software is too abstract - it's lives in it's own domain but is isolated from directly interfacing with the real world. Now that I'm retired and have some free time I've picked up Arduino and and have been working on some proof of concept projects for my racing motorcycle. I'm quickly moving beyond the capabilities of the standard 8/16mhz Arduino and purchased a Teensy 2.0 and 3.1 for future development.

My current project is a turbocharger boost controller that will be integrated with a data logger. I'm kicking around the idea of controlling the boost based on data acquisition (for example, the faster the rear wheel turns the greater the amount of boost.) I'll be open sourcing the work when I'm satisfied with it.

The 3.1 looks like a wonderful device for my purposes. It's powerful, small and inexpensive. There are just a couple questions that I have since I'm still coming up to speed on the hardware side.

First of all, the real time clock appears to be something that I'd like to use. I see that there are a variety of 32.768khz crystals for sale on the web. Do you have a specific form factor/model/vendor that you recommend? Better yet, do you have some to sell?

I'm looking at the 3.3v - 5v level translation issue. I bought some of the Chinese Sparkfun designed digital converters and after reading some of the threads here have also ordered a handful of 74HC245N chips. My understanding is that those are all for digital applications. My data logger is going to need to work with 5v analog. I'm thinking that 180ohm/330ohm voltage dividers is the right solution for bringing the voltage down. Thinking for future scenarios, is there a good strategy for 3.3v->5v analog out signals? Also, lets say that I used the divider and my voltage in was higher than 5v - say 5.5 or 6. At what point do I need to worry about accidently killing the Teensy?

When I'm designing a project I alway like to account for unanticipated future scenarios. So rather than hardcoding data logger pins I'm coding to make them software configurable. A logging configuration is downloaded with JSON (see below) then stored in EEPROM and loaded at boot time.

I'm trying to work out a good solution for dealing with the fact that some devices which are plugged in might be 5v and others 3.3v. I could just create specific pins for each voltage, i.e analog pin 1a takes 5v and runs through a divider but 1b goes straight to the Teensy. This doesn't seem like a particularly elegant solution and if a user hooks things up to the wrong pin it will kill the board. Any ideas on a better way to approach this?

Thanks - Eric Marsh

{ "cmd":"config-channels", "data":[
{"name":"tach", "enabled":true,"id":0,"type":tachometer},
{"name":"counter","enabled":true,"id":1,"type":counter},
{"name":"bin","enabled":true,"id":22,"type":switch},
{"name":"value","enabled":true,"id":0,"type":analog}]
}
 
Hi and welcome.

The cfs206 RTC crystal has been specified for the teensy - digikey carries them for about $0.7 ea. I've used those RTC crystals with great success. For more accurate (temperature -independent) timing, you could use a DS3231 or similar temperature-compensated RTC.

As for the external voltage issue on pins, the teensy 3.1 is 5v input tolerant on digital pins. However, I'd still consider the use of either the BSS138 approach popularized by rocket number nine or the TXB series of TI level converters. They work bidirectionally. The key would be creation of banks that are 5V vs. 3V.

The voltage divider approach is certainly one way to get a analog signal into the teensy at the allowable 3.3v voltage. You can crib off the the ruggeduino schematics to see how to clamp excess voltages above 3.3V, i.e. using an appropriate current-limiting resistor and a Zener/TVS diode to clamp the input. If you can live with the impact on ADC range, you could certainly treat all analog inputs as if they potentially have a 5V signal on them and then only use 2/3 of the ADC range when the signal is 3.3V max.

A more complicated approach could include the use of an Op-amp whose output range is controlled by the Teensy. The teensy would analyze the signal, determine whether it's a 5V-max or a 3.3V max signal and then toggle the op-amp feedback resistor network to adjust the output of the op-amp accordingly. The additional benefit here would be the op-amp also buffering the signal for the Teensy ADC. The downside is the additional hardware needed and the additional pins required to sense the incoming voltage and interact with the op-amp.

A simpler incarnation of this idea could be a transistor that shorts part of the voltage divider for 5v operation. That is, instead of consisting of just two resistors, the voltage divider would feature 3, one of which gets shorted to reduce the resistance of the leg between the analog pin and AGND for 5v operation. For 3.3v operation, the transistor is shut off and a higher voltage will present itself at the pin. Without external protection, this simpler approach should only be attempted on the digital/analog pins (not the analog-only pins) as the digital/analog pins are 5v tolerant.

Since the analog voltage system (other than the dedicated DAC channel on the Teensy 3.1) uses a PWM approach to generate a quasi-analog signal, a sufficiently fast translator or transistor toggling the higher voltage may very well work. However, to get a smooth output signal, you'd likely have to invest in some passives on the output side. Additionally, there are voltage doubling chips out there.
 
Last edited:
If you are not doing something that needs to as fast as possible (but is fast enough for human reaction times), another alternative to using hardware dividers, etc. is to use an off board processor for analog reads that runs at 5v, and do the normal i2c level shifting to connect the 5v device to the Teensy. The TI ADS1115 is one such chip that provides 4 inputs (or 2 differential inputs) at 16 bits precision. You can have 2 ADS1115 boards on an i2c bus. Adafruit sells ADS1115 breakout boards, but there are other sources as well. There is a cheaper ADS1105 part that only does 12 bits of precision.
 
Last edited:
Status
Not open for further replies.
Back
Top