Different pull-ups for TWI level shifter

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, community!

I'm developing desktop clock with mini-meteo station. My display is Kingbright CC25-12EWA if this matters. I want to power up the whole system from one 18650 Liitokala battery so I bound to about 3.3 volts. The core MCU is atmega8a running at 8 MHz and BOD set to 2.7 volts.

For my meteo measurements I use Bosch's BMP280 or BME280 (in case when humidity matters). These parts are working pretty good with 3.3 volts. I use not the bare chips but small PCBs from AliExpress (so-called GY-modules for Arduino). They are small, have necessary capacitors and some set of pullups soldered, e. g. for using I2C by default. There are also two 10k pull-ups for SDA and SCL lines. I've tested BMP280 with my current setup running from 18650 and things looks fine.

But for RTC module I've chosen another ready-to-use module from AliExpress. It has DS1307 IC for RTC handling, another EEPROM chip (not needed for my purpose), CR2032 holder for backup battery and all necessary parts such as oscillator, capacitors and pull-ups.

Main problem with this setup is the DS1307 IC - it wants 5 volts for VCC and I2C operation. I decided that with such small power consumption of DS1307 it's more wisely to use DC-DC boost converter and step my 3.3 volts to 5 for higher VCC. I've found appropriate module on AliExpress and already ordered it.

The last thing that I want to use both BMP and DS1307 on the same TWI bus but because of higher VCC for RTC module I won't be able to use direct connection of DS1307's SDA and SCL lines to my TWI bus - RTC module already have 4.7k pullups for these two lines to the higher VCC and I want to avoid resoldering of ready-to-use RTC PCB.

Obviously I need TWI level converter and I've found that there are a lot of different solutions for this problem. As for me using two BSS138 mosfets is the simplest way. But all of examples of level converters utilize symmetric pull-ups at both sides - 3.3 and 5. In my case I have two 10k pull-ups at the 3.3 side (BMP modules have them) and two 4.7k pull-ups at 5 side (RTC PCB module use them).

Finally, there is my question. Is there any pitfalls of using famous two-BSS138 level converter (or any other solution) with different rated pullups at the both sides? May be your own solutions...

Thank you

Viktor Drobot
A.N. Belozersky Research Institute Of Physico-Chemical Biology MSU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not just use an I2c level shifter module?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dviktor wrote:
Obviously I need TWI level converter

What is obvious is the need for a RTC that works at 3.3v! 

Also the choice of the M8 in a battery powered project is not wise.

A better choice would be any of the pico power AVR's.

For low power projects, you need to review any use of power converters/regulators, pull ups, pull downs, cap leakage, etc....

How are you going to recharge your LiPo battery, as these need great care or you end up with a flame thrower!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian, I reviewed these I2C level shifters but the problem is the same- there are pull-ups needed at the both sides. In my case of using ready-to-use inexpensive PCBs there are different pullups on these PCBs- 10k at low-voltage side and 4.7k for high-voltage. So the question persists.

ki0bk, yes, it's the simplest way, but I already have good PCB module with all necessary parts for the few money. As for now I just want to test it and gain more experience so it's the cause of using mega8 and ready-to-use modules from China.

In any case my 7-segment display consumes much more current than mega8- I use dynamic indication and cycles between 4 digits. My average current per single segment is about 5 mA, so in the worst case one digit eats about 35 mAmps which is less than maximum 40 mA per mega8 pin and I decided it's ok. So in the very-very bad case of 40 mA per one digit and 8 mA for mega8 itself and some extra mAmps for modules and boost converter there will be 60 mA of total current consumption. Single 18650 that I use is about 3400 mAh, so it will work for 56 hours. I don't want to use my device in 24/7 manner, only for some hours per day. Also I always can use two batteries in parallel.

As for battery itself I use Li-ion and not Li-pol version. I have proper charger for them so it would be safe.

Viktor Drobot
A.N. Belozersky Research Institute Of Physico-Chemical Biology MSU

Last Edited: Mon. Dec 17, 2018 - 03:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dviktor wrote:

...10k at low-voltage side and 4.7k for high-voltage.

 

There is nothing special about those numbers. Most engineers just use what's laying around on the bench. If you want to get technical, you chose a resistor value that best suits your finished design to balance the rise-time of your I2C signal against power consumption.

 

Being open-collector/open-drain the I2C bus needs those resistors to generate the logic 1 level. When moving from a 1 to a 0, the drivers can quickly pull the bus down but, when moving from a 0 to a 1 the resistors will need to overcome the capacitance of the PCB and of the connected chips. On a typical 100kHz I2C bus, you can use anything in the range 1k to 10k and it will work.

 

One thing to note is that you only need one pair of resistors for the whole bus, not a pair for every device.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I operate I2C exactly at 100 kHz.

Thank you for noticing that there are two pair of resistors! But I thought that it would influence only I2C comms with no level shifter.

 

If I understood that correctly: for example, if I have simple system Master + Slave1 + Slave2 on the single bus operating at the same VCC. Slave1 have 10k resistors and Slave2 have 4.7k resistors. Actually they are connected in parallel so final pullup is 10k * 4.7k / (10k + 4.7k) = 3.2k (approx). I think this value still not big enough for using in I2C comms. But I'm not sure for the case of using BSS138 level converter on any other IC...

Viktor Drobot
A.N. Belozersky Research Institute Of Physico-Chemical Biology MSU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dviktor wrote:

...if I have simple system Master + Slave1 + Slave2 on the single bus operating at the same VCC. Slave1 have 10k resistors and Slave2 have 4.7k resistors. Actually they are connected in parallel so final pullup is 10k * 4.7k / (10k + 4.7k) = 3.2k (approx). I think this value still not big enough for using in I2C comms.

 

When you say 'not big enough' what do you mean?  A total of 3k2 is fine. 10k would be fine, 4k7 would be fine.

 

dviktor wrote:

But I'm not sure for the case of using BSS138 level converter on any other IC...

 

Simples...

 

 

 

...4 resistors, almost any value will do. Something between 1k and 10k.

 

If you want to verify your result, build the circuit and put a scope on the SCL and SDA lines and check that they return from 0 to 1 in under 1us.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, I meant 'not small enough' instead of 'big enough'. IIRC there are some limitations on lower bound of pull-up resistors value.

 

I've seen this circuit in NXP's appnote. The only thing that confused me is symmetrical resistors values. In my case I have no symmetrical resistors and this puzzled me. Anyway, thank you. I will test as soon as I buy MOSFETs.

Viktor Drobot
A.N. Belozersky Research Institute Of Physico-Chemical Biology MSU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Attached is what Ti has to say about pullup resistors.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great article, thank you!

 

Are there any rules of thumb how to get (approximate) bus capacitance?

Viktor Drobot
A.N. Belozersky Research Institute Of Physico-Chemical Biology MSU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Battery powered devices have their own learning curve.  A two day class can be easily filled. 

That said here are a few tips:

If you must use LEDs (instead of LCD) then you can pulse them.  For the same energy consumption, the human eye will sense a pulsed light as brighter than continuous light.

Check the data sheet for max current when pulsed.  The drive them hard for short pulses.

While the ATMega8 may not be the best for low power it has some useful sleep modes that range from light cat nap to comatose to dead.

At a minimum turn off unused systems like ADC, Analog Comparator, unused timers, whatever.

CMOS power use goes up by the square of speed, so run your processor at 1MHz not 8.  There is a clock divider function so you need not change crystals.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

KirkCharles wrote:

For the same energy consumption, the human eye will sense a pulsed light as brighter than continuous light.

 

Wow, did not know this.  Do you know the percentage of pulsed

power versus constant power to achieve the same perceived

brightness?  Does it depend on duty cycle and/or frequency?

Thanks,

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, KirkCharles! Very useful explanation! If I understand it right, I could make segment outputs as PWM pins and drive them with needed duty cycle, am I right? And what about maximum current per I/O pin or port of ATmega8 in PWM mode? I can't find any info about it anywhere, while for LEDs it's the common thing in datasheet...

Viktor Drobot
A.N. Belozersky Research Institute Of Physico-Chemical Biology MSU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dviktor wrote:
Are there any rules of thumb how to get (approximate) bus capacitance?

Not sure myself.  Can I just put a capacitance meter on the SDA and SCL pins of the complete circuit to measure it, or do I disconnect the devices on the bus and measure the capacitance of the bus lines alone?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are tables to calculate capacitance of pcb tracks, ribbon cables, ...

 

Or you can just use rules of thumb e.g. 20pF per device.   Max bus capacitance = 400pF e.g. 20 devices. 

Time constant  = RC.    So 3 devices @ 20pF with 4k7 pullup = 282ns.   A 400kHz bus is 2500ns period.   282ns is good risetime.

 

You can even get an approximate measurement of capacitance with an Arduino Uno.   You know the pullup resistance.   Use the ADC to read the shark-fin.

 

David.

Last Edited: Tue. Dec 18, 2018 - 12:02 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suggest dropping the 1307 board and using a DS3231 module board instead.  It runs at 3.3v; it is cheaper (most likely, considering both the IC and the battery), and more accurate.  It has an alarm that the 1307 doesn't have, but not the internal SRAM bytes that the 1307 does.   Here is an eBay link: https://www.ebay.com/itm/DS3231-...

 

I have made prototypes with this DS3231 board and had them in the closet for about a year.  When I powered-them-up to see if they would still work, the DS3231 clocks were running and accurate to about a minute.

Last Edited: Tue. Dec 18, 2018 - 12:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why do you need an RTC chip?

You have a processor with timers, interrupts, and everything you need to make a clock!

The RTC is wonderful when you need to save every microamp; however your LED displays will probably take 1000x of the power compared to the micro.  So whether the micro sleeps or not, the savings might be minuscule.

Just program up a clock in an hour & if you don't like it, you can always add an RTC.

 

http://danyk.cz/avr_hod_en.html

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Dec 18, 2018 - 04:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avr-mike wrote:

KirkCharles wrote:

 

For the same energy consumption, the human eye will sense a pulsed light as brighter than continuous light.

 

Wow, did not know this.  Do you know the percentage of pulsed

power versus constant power to achieve the same perceived

brightness?  Does it depend on duty cycle and/or frequency?

Thanks,

 

--Mike

 

No I'm not sure of all the variables. Perhaps some google research on "Persistence of Vision" will reveal useful info.  The few times that I have done this I just picked a value and went with it. 

There is a balance.  Driving LEDs super hard makes them less efficient. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dviktor wrote:

Thank you, KirkCharles! Very useful explanation! If I understand it right, I could make segment outputs as PWM pins and drive them with needed duty cycle, am I right? And what about maximum current per I/O pin or port of ATmega8 in PWM mode? I can't find any info about it anywhere, while for LEDs it's the common thing in datasheet...

I would probably pulse the common of the LEDs.  You will probably need a transistor or driver chip to get enough current to switch all the LEDs.

For current look under - Electrical Characteristics - Absolute Maximum Ratings - There will be a max for individual pins and a max for all pins (less than MAX * num pins)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies, I need my clock to keep working while main power is cut so I think RTC module is good enough for this task.

KirkCharles,
I drive my led segments at 5 mA so the total current via common cathode is about 35 mA. I drive commons via atmega8a pins so with the limitation of 40 mA per pin it is safe, I think

Viktor Drobot
A.N. Belozersky Research Institute Of Physico-Chemical Biology MSU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow, did not know this.  Do you know the percentage of pulsed

power versus constant power to achieve the same perceived

brightness?  Does it depend on duty cycle and/or frequency?

Effective Intensity is another useful search term for information on this effect.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you thought about using the ds3231 for your I2C clock?

No need for level conversion, this critter runs from Vcc > 2V3.

This chip is a bit more expensive, but you get a lot better accuracy for it.

The cheap clones from China do sometimes seem to have a bug, where they loose accuracy if you read the time via I2C very often, but I have not used these myself (yet).

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta, Paulvdh:

I already purchased one test module with DS3231, will test soon. I'm not very experienced in part search so I usually begin my experiment with well-known and described modules/chips

Viktor Drobot
A.N. Belozersky Research Institute Of Physico-Chemical Biology MSU