Which is better for inverted logic?? - Page 1
Forum section: electronics / general

author: SmallHuz
author_rank: Contributor
timestamp: May 23, 2021, 09:18:52 am
content: Hi,I am in dilema with inverted logic form my project. I am trying to sense when HC-05 module is connected with micro controller and after then just one send once EEPROM data. I am thinking about useing BJT as a switch ore optocupler. HC-05 gives me 3 volts when it is connected and micro controller is Atmega16. I know that mega16 can use 3.3 volts for logic level (High or low state correct me if I am worng pls) but best way to sense changes on pins is by useing pull-up resistors. So which is better BJT switch or optocupler. Thanks in advance.

author: ledtester
author_rank: Super Contributor
timestamp: May 23, 2021, 12:55:59 pm
content: What supply voltage will the atmega16 be powered with?How will your code detect the signal from the HC-05? Interrupts? Polling?Can you provide a schematic of what you are proposing in each case, BJT and optocoupler?

author: SmallHuz
author_rank: Contributor
timestamp: May 23, 2021, 02:10:19 pm
content: Atmega16 will operate at 5V. Detection of connection will be constant without interrupts state pin of HC-05 module will be connected to PD4 and after detection of connection mega16 will send eeprom data just once. Right now I am not able to provide some schematics I could do it tomorrow. Bassicly connecting state pin of HC-05 modlue to base of BJT via resistor and conectin PD4 to colector of BJT and emmiter to GND so basicaly when state pin is high PD4 will be low same for optocupler.

author: ledtester
author_rank: Super Contributor
timestamp: May 23, 2021, 02:31:29 pm
content: From what you described a BJT will work just fine. This shows an internal pull-up being used:Is there anything else we should know about your application that would warrant the use of an opto-coupler?

author: SmallHuz
author_rank: Contributor
timestamp: May 23, 2021, 03:14:54 pm
content: Only thing for use of optocupler would be complete electrical isolation of the module. But since vcc, gnd, txd and rxd pins of hc-05 module are already connected to MC a think that wouldnt help. But in short I was just curious about this 2 ways of connecting 2 circuts with diferrent voltage levels.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 23, 2021, 07:37:09 pm
content: Just connect it directly, 3v talking to 3.3v, where's the issue?Put a 10K resistor in series if you want further protection.Also, a lot of 3.3V MCUs have 5V-tolerant GPIOs.What you're doing is only required when the signal voltage is beyond limits.

author: ledtester
author_rank: Super Contributor
timestamp: May 23, 2021, 10:06:59 pm
content: QuoteThe OP said the ATmega8 is operating at 5V.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 24, 2021, 10:36:16 am
content: Yep, my mistake.Search in the ATmega datasheet for the input voltage high/low threshold levels. 3V is usually more than enough. So the same thing.

author: Siwastaja
author_rank: Super Contributor
timestamp: May 24, 2021, 06:34:37 pm
content: Quote from: DavidAlfa on May 24, 2021, 10:36:16 amNo, it almost never is for a 5V powered part. Typical CMOS thresholds being 30-70 (or sometimes 35-65) and typical 5V regulator accuracy being some 3%, minimum even remotely reliable hi level is 5V*1.03*0.7 = 3.6V.3.3V may work quite well on a lab table but tends to be marginal, just don't do it. 3V as you suggest is almost guaranteed to be non-operational.--For level conversion 3V3->5V, any logic gate (inverter, buffer...) in 74HCTseries works. This is my preferred solution. As already explained, an NPN, with emitter on ground, collector pulled up with a resistor, works as well. Or a small logic-level NFET if you have that around. Level conversion won't get much easier than that, but as a side effect, the transistor inverts the signal.Signal polarity is likely unimportant, you are connecting it to a microcontroller, so rest is software regardless of what '1' and '0' mean. In AVR, a Pin Change Interrupt registers both transitions anyway.Isolation makes no sense if you don't isolate the power as well. Why would you need isolation is another question. You likely don't in this circuit.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 24, 2021, 06:53:24 pm
content: It depends. That why I said check the datasheet.