Thursday, 31 March 2016

transistors - How to choose a switch?


There seem to be about 4 major flavors of transistors, and then there are NPN/PNP versions. There are also relays, SCRs, and TRIACs.


When I need an microcontroller-controlled switch, what rules of thumb should guide me in choosing? Are there a few common ones that people like to keep around for use when there are no particular high-performance specs?


I'd like to learn the general rules so I don't end up googling 37 variants of the same question.


For a concrete example, the application I am choosing for right now involves driving a 5 V, 160 mA (80 mA average at 50% duty cycle), 3.1 kHz buzzer with an output from a 3.3V MCU that can sink 8 mA or source 4 mA.



Answer



Bipolar transistors and FETs work about the same on the output side when you are using them as switches in low power applications like you mentioned. Both come in two flavors to make either high side or low side switches. The NPN bipolar and N channel FET are the low side switches, and the PNP bipolar and P channel FET are the high side switches.


The difference between bipolar and FET is mostly how they are turned on and off. Bipolars are turned on by running some current thru the base. This allows a much greater current to flow thru the collector. The ratio of the possible collector current to base current is the gain of the transistor. FETs are controlled by voltage instead of current. A basic N channel MOSFET might require 12-15 volts on the gate to be fully on, with 0V fully off. There are things called "logic level" FETs that can switch between on and off well enough to be driven directly by 3.3V or 5V logic outputs.



I'm going to disagree with Starblue and say that for very simple switching applications for hobby use, get a handful of good logic level FETs like the IRLML2502. They will cost of 10s of cents each, but are very fogiving as long as everything is limited to 20V. I would certainly not start with that for a volume design done by a professional, but if you just want to get started with one answer that serves the most needs, this is a good first part to get used to.


Once you're ready to experiment with bipolars get 100 each of 2N4401 and 2N4403. They are dirt cheap, widely available, and all around pretty robust for their size. They would also be fine for switching 200mA loads, but you need to know a little more to use them well. You can't just connect them directly to a microcontroller ouput in a switching application.


usb c - Connecting two "USB C" hosts, what happens?


Up until USB C all the USB connectors were carefully chosen so that two hosts could not be plugged into each other.


With USB C both the host and device have the same connector. With this setup it is now possible to plug two hosts into each other. USB C does use an active cable which I assume arbitrates connections preventing any electrical damage.


I assume one of three things could happens.




  1. Nothing at all

  2. An error "don't do this" or something like that

  3. A connection is established with one host submitting as a device to the other host. (seems unlikely)


What happens? Is it one of my propositions or something completely different?



Answer



The answer depends on whether the host ports are regular host ports, or "Dual-Role Ports" (DRP), at least one of them.


If both ports are regular host ports, nothing will happen, so (1) is true. (because both ports will have pull-ups on CC pin, and this will not trigger any host reaction, VBUS will not be asserted).


If one of the ports (like in some modern tablets/phones) is DRP, the DRP port will alternate its CC function trying to pretend as host, then as device, and so forth. Depending on the other port, right connection will be established. So the answer is (3).


If both ports are DRP, the (3) is still true, just the role of devices will be determined at random, depending on cable plug-in time relative to CC cycle.



These are SPECIFICATIONS for the Type-C connector.


Parallel 18650 battery pack voltage not stepping-up with Boost converter. Why?


I'm new here and I hope this is the right place to ask!



I have assembled a 6P 18650 battery pack out using Samsung 25R cells, soldered altogether with Nickel strips, effectively giving me 3.7V 15Ah.


I want to increase the voltage, so I hooked it up to a "XL6009 boost converter" module and also on a "250W 10A boost converter" module, both of which would not allow me to go anywhere near or above 5V!


This has lead me scratching my head and pulling hair out, as I do not understand why this is happening. Both lower and higher end modules are not able to "do the job", leaving me very confused. I was wondering if anyone might know why this is the case? And what would I have to do if I want to step-up to 7-10V??


Thanks and I look forward hearing back!




Do you think it's simply because the input voltage is too low??




pwm - Strange Distortion from Second Order Active Low Pass Filter


I'm feeding a 250KHz PWM audio signal from an ATtiny85 into a second order active low pass filter:


enter image description here


The output is then fed into a decoupling capacitor and then into an LM324 amplifier. The output of the LM324 is then fed into a decoupling capacitor and then into an LM386 audio amplifier. The audio generally sounds good but there is some distortion. When I view the waveform on OUT1 I get this (the yellow trace is OUT1, the blue trace is after the decoupling capacitor):


enter image description here


What are the strange "drops" I'm seeing? The top of of the waveform looks ok, but the bottom half has these drops. This is some type of distortion, yes? What causes this? How can this be eliminated?


UPDATE 1: Here's the PWM from the ATtiny85:


enter image description here



UPDATE 2: I stated above that



The output is then fed into a decoupling capacitor and then into an LM324 amplifier.



This is not correct. What I should have said was the output of the LM324 is fed into a decoupling capacitor and then fed into an LM386 audio amplifier.


UPDATE 3: Here's 12ms of the 250KHz PWM input:


enter image description here


UPDATE 4: Here is the complete schematic:


enter image description here


Addressing some of the comments and the suggested solution:





  1. I moved the Vcc for the LM324 from the regulated 3.3V supply to the +6V supply. This did clean up the signal coming from the LM324 (i.e. the recovered audio from the PWM input), but significant distortion can still be heard. I still need to test to see if the LM324 is failing at specific frequencies.




  2. I added a 1K resister from the output of the LM324 to ground. Originally I did this to address a comment suggesting that having the output float was not a good idea. The proposed answer says (if I understood it correctly) that this 1K resister tied to ground should force the LM324 output stage into a class A amplifier, thus avoiding a crossover problem. However, at the time this was suggested to resolve any crossover problem, it was already in place.




Is it possible that the LM324 is just a very bad choice for audio? I've heard it has a relatively slow slew rate that causes distortion. Should I be looking at another op amp (that works with a single +6V supply)?


UPDATE 5:



Here are the traces from the current circuit. Yellow is the output from the LM324. After moving the power supply for the LM324 from the +3.3V regulated to the +6V, you can see that there are no more drops (which technically resolves this question). The blue trace is the output from the LM386 audio amplifier. There is distortion on the bottom of the wave and it's pretty audible. I think if I can resolve this distortion I'm good to go. And this pretty much proves that the LM324 is "good enough" for this audio application.


enter image description here


UPDATE 6:


I stated earlier that the LM324 was "good enough" for my application, and this is true. If you examine the output waveform from the LM324 at higher resolution it can be observed that the signal is "noisy" (I did not include a trace of this). Simply unplugging the LM324 and plugging in an MC34074APG (with no other changes), substantially cleaned up the output waveform. This may become my new favorite single source op-amp.



Answer



The LM324, while a brilliant achievement with 1970s transistors, has one well known bug - actually documented in its datasheet. This answer is based on a guess that you are running into this bug.


Some people sneer at it because of limitations like this - but it is still a fine opamp if you design to its limitations.


Its Class B output stage is specifically designed for low power but it is asymmetric : that is, it can pull up (towards V+) quite strongly, but cannot pull down very effectively. This avoids excessive current consumption where both output transistors might be momentarily turned on together (as in the bipolar 555) - a possibility given the relatively low speed of these transistors.


(See Table 6.5, page 6, Output Current section, in the datasheet - at 5V it can source 20mA but only sink 8 uA, so the pullup is 2500 times stronger)





This combination of circumstances : Class B output stage, slow transistors, asymmetric strength, gives it a particularly bad case of crossover distortion on high frequency signals, there is a region where both output transistors are off and the output voltage is effectively undefined.


Run a sinewave at a few kHz through this filter (unit testing is as valid in hardware as it is in software!) and you'll see large bites taken out of the output waveform.




The (documented if you look for it ... EDIT ... it's in section 7.4 on page 11, and my memory of the problem is slightly off) fix is to force the output stage into Class A, with a few kilohms of pulldown resistor to V- (I suggest 1K at this low voltage). Now the pulldown transistor never has to turn on at all (though no harm done if it does) and the much stronger pullup transistor is always in control, pulling against the resistor.


Thus the 324 is designed to be used successfully in Class B for low speed low power designs, or Class A for faster designs.


The downside to Class A is obviously increased power consumption - if that matters, nowadays you can choose a better opamp.


Wednesday, 30 March 2016

pic - PIC32 does not get UART RX interrupts in xc32 Compiler


I'm trying to setup a UART channel on my PIC32 MCU (PIC32MX470F512). But the code does not reach the ISR at all.


I have verified that the PPS (peripheral pin select) is configured properly and the UART reception under polling mode works perfectly fine. Also, the transmission part is working without any issue from day one. But I need to get UART rx to work with interrupts for my application.



At first I tried using the plib (which didn't work either) but then decided to hand code it eliminate any issues caused by the library. Here is the configuration that I have done.


void UART1Inint(unsigned long int baudRate) {
ANSELDCLR = 0xFFFF;
CFGCONbits.IOLOCK = 0; // PPS Unlock
RPD11Rbits.RPD11R = 3; // Assign RPD11 as U1TX
U1RXRbits.U1RXR = 3; // Assign RPD10 as U1RX
CFGCONbits.IOLOCK = 1; // PPS Lock

// Baud related stuffs.
U1MODEbits.BRGH = 1; // Setup High baud rates.

unsigned long int baudRateDivider = ((GetSystemClock()/(4*baudRate))-1);
U1BRG = baudRateDivider; // set BRG

// UART Configuration
U1MODEbits.ON = 1; // UART1 module is Enabled
U1STAbits.UTXEN = 1; // TX is enabled
U1STAbits.URXEN = 1; // RX is enabled

// UART Rx interrupt configuration.
IFS1bits.U1RXIF = 0; // Clear the interrupt flag

IFS1bits.U1TXIF = 0; // Clear the interrupt flag

INTCONbits.MVEC = 1; // Multi vector interrupts.

IEC1bits.U1RXIE = 1; // Rx interrupt enable
IEC1bits.U1EIE = 1;
IPC7bits.U1IP = 7; // Rx Interrurpt priority level
IPC7bits.U1IS = 3; // Rx Interrurpt sub priority level
}


And Here is how my ISR looks,


void __attribute__((vector(_UART_1_VECTOR), interrupt(IPL7SRS), nomips16)) UART1_ISR(void)
{
PORTAbits.RA4 = 1; // LED to indicate the ISR.
char curChar = U1RXREG;
U1TXREG=curChar; // Echo back the same character.
while(!U1STAbits.TRMT);
IFS1bits.U1RXIF = 0; // Clear the interrupt flag!
}


I'm doing two kinds of test in the main loop. One will poll for data in rx and then echo it back to the user. The other will monitor the RILDE flag and turn on an LED to show when the rx pin is actually active. It also toggles a bunch of LEDs for the error flags (least significant 3 bits in U1STA register) in UART1 module.


Both the tests are working fine which indicates that the UART module is setup fine. Just the interrupt portion of it is faulty. So I tested this code on Explorer 16 Development Board, Bluetooth Audio Development Board and the Ethernet Started Kit. I did this to eliminate any hardware related issue as all the three boards are microchip certified hardware.


I don't know what I am missing out please help me fix this issue. Any help would be greatly appreciated.




Tuesday, 29 March 2016

embedded - Multiple DTMF circuit interfaced to one microcontroller, will it work?


I already tested this circuit with only one modification, I changed the R2 to 300kOhms which worked in my case. DTMF circuit


I interfaced this circuit to a microcontroller where they shared a common ground. I successfully read the telephone number of the caller as shown in this figure. Apparently, I received the code number (10 2) and the 7 digit phone number. The frame was encapsulated with byte 0 and byte 15.


enter image description here Now, I wanted to create a circuit that contains 3 channels for 3 different phone lines which are then to be interfaced into one microcontroller..


If I'm going to share a common ground for them all (3 DTMF circuits and microcontroller circuit), will it work?


On the sidenote, based on the datasheet, the circuit is in single-ended configuration.



EDIT: I added the entire circuit shown below. enter image description here



Answer



Yes, you certainly can have three of your DTMF decoder circuits connected to your microcontroller.


However, even though the three telephone lines nominally share the same ground (somewhere), you should really treat them as "floating" with regard to your decoders, and use a transformer to couple the audio from each line to the corresponding decoder.


interface - Interfacing an inductive proximity sensor with a Microcontroller using a sort of PNP-NPN transistors combination


I'm trying to repair an old circuit based on the Micro-controller S87C751 interfaced with an inductive proximity sensor similar to one already posted here


NPN Sensor


The sensor is powered +24V.


I followed the circuit paths from the sensor until the input of the Micro controller and i found it wired in the following way:


enter image description here


The uC is powered +5V.


As you can notice, the circuit designer used a PNP transistor combined with an NPN transistor.


My questions are:


1/ What is the purpose of this transistors combination ?



2/ Is it a level shifter ? if yes, is it really necessary ? As i already seen Arduino interfaced with such sensors with only a pull-up resistor not matter power source of the sensor.


3/ During simulation in Proteus ISIS, i simulated the inductive proximity sensor as a switch. the circuit didn't work, and i get always 0V at the uC input, what could be wrong with my drawing?


Thank you in advance for your help.


EDIT:




  • I plan to use the following level shifter using two NPN TRs instead of an PNP-NPN TRs, is it possible ?




  • I would like to include an LED in this circuit that gets ON when there is Metal detected to save one of the pins of the uC, how can this be possible? i tried including it however a voltage drop will occurs so i'll not get the 5V output.





2 NPN level shifter



Answer



Is it a level shifter ?


Yes


if yes, is it really necessary ?


Yes, if the sensor output is push-pull, i.e. it drives the output high as well as low.


Microcontroller inputs generally can not tolerate inputs higher than Vcc + 0.6V, which would either be 3.9V for a 3.3 V microcontroller, or 5.6V for a 5V microcontroller. (The extra 0.6V is due to an internal diode on the input.)


Occasionally you will see 3.3V microcontrollers with "5V tolerant" inputs but that's as much margin as you will see.



If you go above the Vcc + 0.6V maximum, the pin will start to draw excessive current and eventually the microcontroller will be toast.


So a 24V input would fry your micro pretty quickly.


However based on the spec sheet linked to in the comments, it appears the output is open-collector ("NPN NO"). When the sensor is activated, the output is grounded, and if it is not activated, the output is floating and a pull-up resistor is needed to pull the input high. So the supply voltage (24v) never appears at the input.


In this case you don't need any level shifting, just a pull-up resistor to VCC on your microcontroller (+5V or 3.3V) l, NOT to the brown wire like in your drawing. Just to be safe, you should wire up the sensor and when it is activated, you should measure 0 volts between the black wire and the blue wire (ground).


How is byte addressable memory implemented?



How is byte addressable memory implemented? If the max word size is 8 bytes (64 bits), does the memory always read 8 bytes and then use logic to select the bytes you actually need (1, 2, 4, 8 bytes)? Also, how are the writes implemented?



Answer



Generally what happens is you lose the low order address lines and gain byte enable lines. So if you have 4 GB of memory which would require 32 address bits for byte access, you might end up with 30 address bits, 4 byte enables (from the remaining 2 address bits), and 32 data lines for a 32 bit word size or 29 address bits, 8 byte enables, and 64 data lines for a 64 bit word size. Inside the memory, logic will be used to mask which bytes are actually written back during write operations based on which byte enables are selected. Generally the byte enables are only used during write operations, reads will almost always read out the complete word size and whatever is performing the read operation will simply ignore the extra data.


power - PIC circuit won't stay powered


I've built a simple LED sequencer using PIC 18f4550. Outputs are 10 pins on ports C&D. I have now built (soldered) this circuit 3 times and it still only powers on intermittently. I installed a very low current "power on" LED to help troubleshoot. I notice if I touch the chip or certain areas of the board, the circuit works (& power light on). But it intermittently goes out. Almost like there's a loose connection or some capacitive issue. Circuit works fine when the power light is on. Symptoms are the same whether breadboard or soldered. Ideas?


Thanks




please excuse the crudeness of this drawing.
led sequencer for PIC18f4550



Answer



You probably are missing a pullup on the reset pin (/MCLR)


transistors - Why would an op-amp use BJTs over MOSFETs?



I've always been told that ideally, op-amps have infinite input impedance. So when I was looking at the LM741's transistor level schematic, I was confused when they used BJTs instead of MOSFETs.


opamp


Wouldn't using a BJT result in current flowing into the input pins?



Answer



The 741 is an old piece of junk, primarily used to teach basic electronics for cheap. I seem to remember reading somewhere that if every 741 ever made were to be collected, there would be enough to give every person on earth 6 or 8 of them.


Modern op amps fall into several categories.




  1. General Purpose - These op amps are not very fast, have bad non-ideal characteristics (bias currents in the nanoamps), drift, have input impedances in the megaohms, and cost almost nothing. The 741 falls in this category.





  2. FET Inputs - These are a bit faster, have significantly better non-ideal characteristics (bias currents in the picoamps), drift very little, have extremely high input impedances (gigaohms), but may cost a few dollars.




  3. CMOS - CMOS op amps are slow, but have excellent non-ideal characteristics (bias currents in the FEMTOamps), extremely high input impedance (TERAohms), drift about as much as general purpose op amps, and may cost a few dollars. This is the type of op amp that can get its output within millivolts of the rails, but rail voltage is limited.




  4. Chopper Stabilized - This is another form of the CMOS op amp. It drifts very little, and has very low offsets. Take a look at this article for more information





There are other op amps out there that can handle RF frequencys, or handle high output currents, but they don't really fall in these catergories.


As you can see, each type of op amp has different non-ideal DC characteristics, and input impedance. How much current flows into the op amp inputs depends on the input impedance. For most modern op amps, these are very small currents, and can be considered negligible for the majority of applications. Which type of op amp you use is a design consideration, factoring in speed, cost, temperature range, and any precision concerns.


diodes - Why current appears at reverse bias?


I am simulating time-domain graphs of a Schottky diode model.


enter image description here


I am expecting ~zero current at the negative half cycle. But I am seeing negative current. It's only about 3mA, but based on I-V curve, it is about 0. Does anyone have an idea what might go wrong?


enter image description here enter image description here



diode model:(from datasheet) Is=30e15 Rs=8 N=1.05 Tg=1e-9 Cjo=0.1e-12 Vj=1 M=0.5 Fc=0.95 BV=5 IBV=1e-5 Eg=0.69



Answer



At that frequency you have this...


schematic


simulate this circuit – Schematic created using CircuitLab


enter image description here


batteries - Is it viable to power a circuit board featuring an SD card using a coin cell battery?


I'm currently working on an electronics project implementing an SD card. It is also required that this device be portable and small, thus I'm attempting to use a coin cell to power the board.


However, I'm finding out that this is more difficult than I had originally assumed. In my testing, I've been using this Panasonic BSG CR2032. Doing some research, it states that the maximum SD card current is spec'd at 100 mA (which is a lot), however, I am expecting on average that those read/writes only be 30 mA. Furthermore, that will not be a constant 30 mA, but only when doing a read/write.



Now the obvious problem is that even though the coincell is rated at 225 mAh capacity, that's spec'd at the continuous drain current of 0.2 mA. Referring to the data sheet, even if I were to only run continuously at 2 mA, my capacity would drop down to ~175 mAh. The relationship between current draw and capacity does not appear to be linear, thus doing the math at say a continuous current of ~15 mA would be even more drastic than the linear extrapolation...


My tests confirm this that I am only able to interface with an SD card for about 3 minutes before the coin cell does not have enough power to continue communications.


So my question: Is it viable/realistic for me to think I can power a circuit board featuring an SD card using a coin cell? Do they have coin cells rated for higher continuous current drains (in the mA range)? I'm not well versed in the battery types out there, thus I'd appreciate any recommendations!


Also, it is very important that this circuit board be small and compact, thus I'm trying to avoid stepping up to a bigger 'box shaped' battery.



Answer



I gather you need to power a circuit board and you need that board to also support an SD-card interface and you need to do this with a coin cell (or something the size of one.)


You don't mention your supply rail. This is kind of important. The SD specification says:


SD card physical specs


However, the coin cells are all rated down to something like \$2.0\:\textrm{V}\$. They are almost useless, if you expect them to deliver in excess of \$2.7\:\textrm{V}\$. Here's a chart for the CR2477 (taken from a sheet from "POWER GLORY BATTERY TECH (HK) CO., LTD."):


CR2477



That doesn't make me feel good about relying entirely on the coin cell to operate a \$2.7-3.6\:\textrm{V}\$ SD card mode. And you have to support that mode even if you want to get into the \$1.7-1.95\:\textrm{V}\$ SD card modes, because you have to start operating at \$2.7-3.6\:\textrm{V}\$ and request a change to get into \$1.7-1.95\:\textrm{V}\$ operation. There's no getting around that detail.


What are you supporting, exactly? That's one question you should have already answered in your question. But it's not there.



Is it viable/realistic for me to think I can power a circuit board featuring an SD card using a coin cell?



Maybe. It depends on what you want to achieve. You don't say how many writes or how many reads you need to do. You don't say how often you need to do them. Again, a near blank from you about what you need to achieve. It would go a very long way in giving you more definitive answers if you'd provide more definitive questions.



Do they have coin cells rated for higher continuous current drains (in the mA range)?



Coin cells are, by definition, low drain. many are rated for pulsed currents, though. Up to \$10\:\textrm{mA}\$ for the CR2032 and up to \$15\:\textrm{mA}\$ for the CR2477. But you can see what they are rated for, in broad strokes, from the graph above. Not much. Perhaps as much as \$1\:\textrm{mA}\$ might be considered as a continuous drain. Of course, you can do anything you want to them. But then you won't get much energy out of them if you abuse them.





Now, let's take a closer look at the SD card spec:


SD card power


I see here where you got the \$100\:\textrm{mA}\$ figure. But notice elsewhere when it says that while \$XPC=0\$ means \$360\:\textrm{mW}\$, then the speed classes aren't supported. So the performance is essentially up to the device, I suppose. When \$XPC=1\$, or \$540\:\textrm{mW}\$ and up to \$150\:\textrm{mA}\$, the speed class of the device is then supported. Just a note.


While we are at it, keep in mind that we are talking about watts or hundreds of milliwatts! Not microwatts.




You might be able to figure out, though effort and testing and validation work, exactly how much energy is required to get a task done. You haven't said what tasks need doing. But let me just pose one example case to make a point and you can figure things out from there.


To make these results consistent, let's assume for a moment that you have a magical buck/boost converter that sports 100% efficiency, regardless of load, with voltage source inputs from the coin cell all the way down to \$2.0\:\textrm{V}\$ and that it will provide a constant \$2.8\:\textrm{V}\$ on its output (to help minimize total energy required.) We'll also assume you cannot and do not want to support the fancier \$1.7-1.95\:\textrm{V}\$ modes.


This converter will not excessively load your coin cell, since it must treat it well. So, you will not be able to draw too much current from it. Instead, you will use a capacitor to store energy for the high-current moments and you will use this perfect converter to supply a trickle current into the capacitor. And you will have to pace your operations, too.


A CR2032, treated delicately and well, might give you \$2000\:\textrm{J}\$ over its lifetime. (You can compute this by eye-balling the continuous discharge characteristics curves and doing a piece-wise integration.) A CR2477 might give you four times that, or \$8000\:\textrm{J}\$. I'm actually kind of surprised by that because a AA alkaline battery, delicately treated as well, provides \$12000\:\textrm{J}\$, or so. It just does that while providing more current compliance. But it is a lot bigger, too.





ADDED ZINC-AIR SIDEBAR: I just did a quick check on Zn-Air button cells. I don't know a lot about these and the largest I readily found is the 675 size. It is small (\$\tfrac{1}{2}\:\textrm{cm}^3\$) and is rated for a higher loading; around \$5\:\textrm{mA}\$. The CR2032 is a full \$1\:\textrm{cm}^3\$ and the CR2477 is \$2.4\:\textrm{cm}^3\$. So it may be possible to stack some of these Zn-air batteries into your volume requirements. The energy available in the 675 appears to be about \$2500\:\textrm{J}\$. Which is decent, considering.


You might lay them out flat and get perhaps four of them into your requirements. You'd have to check that out, though. (They are about \$5\:\textrm{mm}\$ thick, as well.) If so, this might be about \$10000\:\textrm{J}\$ at a higher load capability, vs \$8000\:\textrm{J}\$ for the CR2477, in about the same area on the board. Less convenient, as it requires four separate mountings, you have to make room for human fingers, and there would be four replacements vs one replacement when you needed to change out the supply. Personally? I'd consider one of these as a replacement for the CR2032. But I'd not mess around with three or four of them as a replacement for the CR2477. It's just not worth the extra hassle.


Keep in mind that having a higher current rating doesn't mean you get to do more SD card operations per battery replacement. The energy available is in the same ballpark. What you do get is faster times between operations! So I really do think that the 675, in lieu of a CR2032, makes a lot of sense. You get about the same available energy -- perhaps a little bit more -- and you get much higher current capability, which reduces the time between operations. It's also smaller and since board space is at a premium, this also argues for using the 675.


But you won't get more operations.


If you do go this route, then you are talking about a boost converter that can accept about \$1.2\:\textrm{V}\$ at its input and produce your required \$2.7-3.6\:\textrm{V}\$ output. This is both easier and harder than the really low trickle case for the CR2032. With inductive boost converters, it's easier because you can operate with higher peak currents and probably find more converters available because of that fact. It's harder because you have a lot less headroom to work with and this puts constraints on the boost converters. (It may also be easier because I think you may need a buck-boost for the CR2032, though you could pick a rail that is higher so that it is only a boost mode operation.) I think Texas Instruments has some fancy switched capacitor voltage converters. But I don't know if they have a tripler. But that might be another option to consider researching.


A note that Russel McMahon brought up, and I'd forgotten about, is that Zn-air devices only last about a week (sometimes two) after opening them to the air. I have to replace my hearing aide batteries all the time, because of this limitation (I use them only occasionally, so if I open up some batteries it's more likely that they will die on their own than I will use them up in usage.) The Lithium coin cell will last almost forever, by comparison. So this is a very important consideration when comparing the two technologies, as well. Good catch, Russel!




Suppose a specific write operation, in non-speed supported \$XPC=0\$ mode, requires \$10\:\textrm{ms}\$ to complete and that it will draw \$100\:\textrm{mA}\$ from your \$2.8\:\textrm{V}\$ supply rail. This works out to \$2800\:\mu\textrm{J}\$. At first blush, this doesn't sound bad because it would seem you can get over a half-million of these out of a well-treated CR2032.


But you have to treat the battery well, which means something like \$400-500\:\mu\textrm{A}\$ current draw, at best. Half that would be better. At \$200\:\mu\textrm{A}\$, this means \$5\:\textrm{s}\$ of time. And at \$500\:\mu\textrm{A}\$, \$2\:\textrm{s}\$ of time.



So, all you have to do is pace your operations! You can do this with a nice capacitor somewhere, which you trickle-charge from your coin cell using your perfect buck-boost converter. Let's say we cannot allow more than \$100\:\textrm{mV}\$ droop from the capacitor during this write operation (\$100\:\textrm{mA}\$ and \$10\:\textrm{ms}\$.) This means a capacitor of \$10\:\textrm{mF}\$. It doesn't need to support much voltage, luckily.




So, broadly speaking... yes, you can do this with coin cells. If you can live with carefully characterizing your SD card support, design your capacitor storage correctly for the worst case transaction, get a very efficient converter at the required trickle currents needed to take good care of your coin cell, and pace your operations, accordingly.




Now, you need to add in inefficiencies of a practical converter and you need to add in additional requirements from your circuit board. But luckily there are a lot of newly minted micro-power systems designed for energy harvesting devices, these days.


There is another "cost" you need to factor in, as well -- the capacitor itself needs to be charged up and when you turn off the device this charge is thrown away, and lost. With a \$10\:\textrm{mF}\$ capacitor (from above example) and \$2.8\:\textrm{V}\$ supply rail, this is about \$40\:\textrm{mJ}\$. So you will need to work out how often that happens, too. It's a real cost and needs to be accounted. (Also, there is leakage.)


If you were bent on the idea of preserving the stored energy on that capacitor, there are even some quite specialized hybridized capacitor/battery devices for energy storage (though I don't think they are appropriate here, preferring to use a capacitor instead for temporary pulse currents.) These have been designed and fielded for energy harvesting usage, which is in the vicinity of where your coin cells are at, I think. (I have one or two of them here.) These can act both as a capacitor, but also can carry energy for a while, as well. Some of them are designed to handle transmitters and receivers, which are in the load area you also are at, as well. So that might also be an option to consider.


sensor - Arduino controlled PWM PC Fan


I am looking at getting 2 Evercool EC8015HH12BP 80x10mm (4-wire) PWM fans. However, I am looking at controlling the fan speed with the arduino via the PWM pins.


I found the following diagram that seems to be what I am looking for in order to hook the fan up to the Arduino:


enter image description here


The code that I think I can use is this:


int pwmPin = 9;      // digital pin 9
int pwmVal = 10;


void setup()
{
pinMode(pwmPin, OUTPUT); // sets the pin as output
Serial.begin(9600);
}

void loop()
{
if (pwmVal != 255) {

analogWrite(pwmPin, pwmVal);
//pwmVal += 10;
Serial.print(pwmVal); // Print red value
Serial.print("\n"); // Print a tab
} else {
Serial.print('at max high'); // Print red value
Serial.print("\n"); // Print a tab
}
delay(1000);
}


I gather that the PWM would be in the range of 0-255 when writing out to it from the ardunio? I will be using the DS18B20 Thermometer Temperature Sensor in order to see how fast I need to spin the fan.


However, the fan speed (max 12V right now) never slows down one bit.


I'm using D9 on the Arduino Nano ATmega 328.


The reference is here for the board (in case i have the board pin wrong): enter link description here


enter image description here


Any helpful feedback would be great!




Monday, 28 March 2016

pcb - Basic voltage divider issue in my amateur circuit XBee


Once again I need your help in my project. I have a 4,5v powered circuit. I put a voltage divider with 2 resistors in series to reduce my initial voltage of 4.5 V to 3.4 V (to feed an XBee module).


The issue is that if I do not connect the xbee, the voltage divider reduces the input voltage to the desired voltage(3.4 V), but when I connect the XBee module, the resulting voltage divider voltage drops to a value very low (0.85 V), making the XBee malfunction. Surely it is a basic mistake, I am asking something that is very clear, but I'm newbies.


Basic Circuit:


Vin(4.5 V)-----R2(10 kΩ)---------R1(33 kΩ)--------GROUND
|
|
Vout desired (3.4 V)
|

|
XBee

Answer



The basic mistake you are making is that you cannot use a voltage divider to power a circuit.


Let's do the maths.


For the sake of the maths I'll say the XBee needs 100mA to run. I don't know what the actual value is, but that seems a reasonable value to me for an RF transceiver.


When unloaded you have a simple divider with current flowing through two resistors. Let's calculate that current:


$$ R_T = 10,000 + 33,000 = 43,000\Omega $$ The current through that at 4.5V is $$$ I=\frac{V}{R} = \frac{4.5}{43000} = ~105 \mu A $$. Ok, so with that current through 10KΩ it drops $$ V=R \times I = 10000 \times 0.000105 = 1.05V $$ so the output voltage would be \$4.5-1.05=3.45V\$


All well and good.


Now let's add the XBee. That's going to draw 100mA through the output. So we have 105µA plus 100mA, or 100.105mA flowing through the 10KΩ resistor now. $$ V=R \times I = 10000 \times 0.100105 = 1001.05V $$ A thousand volts dropped over the 10KΩ resistor?! But, (you say), That can't be! There's only 4.5V available in the first place!



Quite right. So the entire (or certainly most of) the 4.5V gets dropped across that 10KΩ resistor leaving nothing left for the XBee to run on.


So if you want to draw more current than the voltage divider itself consumes, you're on to a loser right away. A divider like this is only good for small signals where you will be drawing minuscule amounts of current. Ideally the resistance of what you're connecting it to should be no less than 10 times that of the lower (33KΩ) resistor in the divider. Perfect for connecting to input pins on microcontrollers, ADC inputs, op-amp inputs, etc, where the input resistance (impedance) is typically in the hundreds of thousands, or even millions, of ohms. Not so good for powering something.


So what do you do then?


Well, the answer is very simple:


Use a low-dropout linear voltage regulator. They're ten-a-penny and usually just need a couple of capacitors with them. Very simple to use.


usb - How to transform 5V into 12V?


I would like to transform 5V 500mA (from USB power) into 12V with a few cheap components.


Is this possible with the help of some generic parts (and not with the help of some expensive transformer, etc.)?


Also, how many milliamps would this provide?




components - Why do Solid State Relays cost so much?



Solid State Relay (SSR) Crydom CN240A24: Eur 10.72



alt text


Same function with basic components



Optocoupler MOC3043 (zero-crossing detect, triac out): Eur 0.726

Triac BTA06-600CWRG (snubberless): Eur 1.16
2 resistors: Eur 0.212



Total for the second solution: Eur 2.10, or 80% less than the SSR solution. Prices from the Mouser catalogue. Similar devices from other manufacturers have similar prices (quick check).


alt text


So, the question is: what's so special about Solid State Relays that they cost so much?


edit
I guess at Crydom the LED and photo-triac are bonded directly to the thin PCB. Packaged components may be used for small production runs, though.



Answer



Principally, you're paying for the testing. UL and CE testing is Very expensive. Also, lifetime and reliability testing (the crydom relays are specced to 100,000 cycles), which means that crydom has actually run a number of the devices through 100,000 cycles at load.



Furthermore, you're also paying for liability insurance. If an appliance fails and kills someone, and the only AC-facing component was a crydom relay, it's crydom's problem. If the AC components are your own, it's your problem.


Lastly, while it's true that a discrete relay solution is preferable in large volumes, you often see SSRs in small-volume or specialty products, where assembly and testing costs dominate the expenses, rather than raw component costs.


Using hard disk motor as generator


I have disassembled 20 broken hard disks and taken out the motors, thinking they might be useful. However, they didn't work using DC current, because they required some kind of control circuit. Now I have a project (electrolysis) that might require to use those motors as generators. I want to know what kind of current these generate (DC or AC)? They were able to power an LED but as LEDs are diodes, I couldn't tell whether that motor generated AC.



Answer



A HDD motor usually is brushless, i.e. it has no commutator. Basically, it consists of three coils arranged around a magnetic rotor. There are three terminals to power the three coils and one common current return terminal:


enter image description here


You can drive the motor by a 3-phase AC voltage, and when you turn it by hand, it will generate a 3-phase AC voltage.


Here is a youtube video of someone who measured the voltage on all three terminals while spinning the motor by hand. This screenshot from the video shows a wonderful 3 phase voltage:



enter image description here


As you need DC, you could use three rectifiers:


schematic


simulate this circuit – Schematic created using CircuitLab


or six diodes, as @jms pointed out:


schematic


simulate this circuit


However, I'm not sure how powerful those motors are, or how much power you get out when using them as generator. @JRE's experience (see comment) is that the power is very low. This may not be enough for your experiments, but if you want to try, choose diodes/rectifiers with low voltage drop (schottky diodes) to reduce the losses in them.


power supply - Is it safe to use a voltage divider for Arduino and DC motor controller?


I have ordered a Dual H-Bridge 12A continuous (30A peak) Polulu motor driver shield for my upcoming (first time ever, a 1.2m long tank made of wood) robot project.


I was thinking about how to supply the power to all the components in the circuit without wasting much power, but the only thing I can come up with is this simple voltage divider connected in parallel to the motor drive:


Schematic


Knowing the Arduino can handle max 5V I did make sure to make it a bit lower.


But my wonders go to the fact that I am suspicious that connecting the motor driver and Arduino to the same power source isn't a great idea? Or am I paranoid?


And what about power waste by the voltage divider, how can I reduce/minimize it? Make the resistors smaller? (15/10 ohm - but more error and higher current)



Is there a formula to find the most effective R1 and R2?


Do I have to worry about current spikes?


Any other things I could miss in this simple-yet-suspicious circuit?


Also, if I wanted to simulate any possible scenario, which components should I choose in the circuit to keep it as simple as possible (for simulating in Multisim 13)?



Answer



Using a voltage divider as a power source for almost anything is a Very Bad Idea. The actual voltage supplied to the load will vary with the load current. I expect that the current drawn by an Arduino will be Much, Much Greater than is drawn by your 10 meg resistor, so the voltage will be much less than you expect.


You should use a DC-DC converter (AKA switching regulator) to drop the 12 volts down to 5 for the logic. A linear regulator such as the LM7805 could also be used, if the 5 volt current demand is low, but a linear regulator will waste the excess power as heat.


Sunday, 27 March 2016

led strip - A led mystery ? how to connect?




We have ordered from a supplier some high power leds - 20W RGB. They dont have any data sheet , and so we where thinking that we would try and find quickly how to connect them .


Everything we tried failed, we even checked a few of them, and nothing worked.


Well, what happens is that sometimes it flashes for a second and then never turn on again, and sometimes we see a very low green light from it .


We have the right voltage and current supply for it (600mA,32V) , but i guess we still had not guess the right configuration.


Please check this image : enter image description here


We tried also to switch the vcc/gnd, we also tried to ground the body and then give ground to one of the rgb pins, but nothing ...


I guess it works in low, so that you give it a vcc, then you ground the r/g/b to get the right color .


What are we missing here ?



Answer




It seems you might have some luck, googling 20W RGB turns up stuff that looks mostly like yours; so go through those links and try to find some info or call/email the sellers: google.com/search?q=20W+RGB&tbm=isch


And I don't think the pinout is much of an issue.


enter image description here


On the other hand you might need different voltages for each color, same here, here, or here.


It seems like your voltage and current spec don't match anything visually similar found in that search; those are generally 300-350mA per chain/color and 18-20V for G & B but only 10-15V for R.




In response to your questions in the comments: In all likelihood, those are simply DC voltages. Each of the three color chains is a series of 6 (it seems) LEDs. These three chains are connected as in the diagram below:


schematic


simulate this circuit – Schematic created using CircuitLab


Are film capacitors affected by DC bias?


After looking around, I have found quite a few things about how DC bias reduces effective capacitance for a ceramic, or electrolytic capacitor, however nothing seems to talk about the effect on film capacitors. I've found a couple of papers about film caps (such as: TDK Film capacitors - General technical information), and they mention frequency and temperature, but I can't find anything about DC bias reducing capacitance.


I have obviously checked the data sheet of the component I plan on using (TDK - MKT Film capacitors), but there isn't anything about DC bias in that (unless I've just failed at spotting it).


This suggests to me that they aren't affected by DC bias, but that seems a bit of a bold claim, and I can't see that stated anywhere.


Are film capacitor values affected by DC bias? If so, can anyone point me to some data about what the roll off is?


I am planning to use some film capacitors in an application with 48-60V DC across the capacitors and a ripple current around 30 amps.



Answer



Film capacitors have a very stable capacitance over DC bias. Look at this:



Film vs. Ceramic


But it comes to happen that film capacitors are not the only ones immune to DC bias:


Capacitor comparison


So, the actual question is why do ceramic capacitor have such a bad behaviour with DC bias? And the answer lies in the dielectric.


In order to achieve high capacitance values in small capacitor sizes, a high-K dielectric materials like Barium Titanate have to be used. Unfortunately Barium Titanate also has ferroelectric properties that reduce its capacitance value under DC bias:



When spontaneous polarization is reversed under no voltage stress (no DC bias), MLCCs achieve a high capacitance. However, if an external bias is applied to the spontaneous polarization process, the free reversal of spontaneous polarization is much more difficult. As a result, the capacitance gained is lower compared to the capacitance before the application of the bias. This is why capacitance decreases when DC bias is applied-hence the term DC bias characteristic.



Sources:


Quote: Understanding DC Bias Characteristics in High-Capacitance MLCCs.



Images: this comparison document from NIC Components.


first step in embedded system






Possible Duplicate:
How to become an embedded software developer?



I'm third year undergraduate computer engineering I and I like embedded system I would like to be my specialize in engineering , but I found it a fast topic , so from your experience what is the best practice toward this target and what is the first step or books needed .thanks




Current through a resistor with diode


If I had something like this, where the forward voltage for the diode is 1.8V, then how would I determine the current through the resistor? Do I use the 1.5 voltage drop through the resistor?


enter image description here



Answer



I'm going to guess that you don't just want a yes/no answer. I see that you wrote that you are a little confused and you asked about the diode resistance coming into play. So I think you want to understand things a little better than just "yes, that's about right."


So here's the answer "in long" rather than "in short":





A diode (or LED or forward biased PN-junctions, generally) behave more like this:


$$I\approx Ae^{k V}$$


where \$A\$ is some constant and \$k\$ is some other constant and \$I\$ is the current through the diode and \$V\$ is the voltage across the diode.


In short, small increases in the voltage result in large increases in the current through the diode.


Also, this means that even with tiny voltages across the diode there will will be some current. It doesn't magically just turn on at some voltage. But it does seem to do that "for all intents and purposes."


So when you wrote "the forward voltage for the diode is 1.8V," this really means "[if the current is sufficiently large, then] the forward voltage for the diode is 1.8V." In reality, it almost never is that voltage. But you can assume it is nearby if you also assume that the current is nearby some assumed value.




The math symbol \$A\$ is usually replaced in electronics by a special symbol, \$I_S\$ or \$I_{sat}\$, called the saturation current. If you draw the current vs voltage curve on a log-lin plot page, the curve will become a straight line over a very wide range of the curve and the y-axis (the current) intercept is this special value. So \$A=I_S\$.


The math symbol \$k\$ is usually replaced in electronics by \$1\$ divided by an expression that includes another special symbol, \$n\$, known as the emission coefficient, times a physics quantity known as the thermal voltage. The thermal voltage is quite fundamental and applies to all bits of matter. So \$k=\frac{1}{n V_T}\$, where \$V_T=\frac{k T}{q}\$ is the thermal voltage. (There is a new constant \$k\$ known as the Boltzmann constant, a new constant \$q\$ known as the charge of an electron or proton, and the absolute temperature \$T\$ usually expressed in Kelvin.)


The thermal voltage at room temperature is very close to \$V_T=26\:\textrm{mV}\$. But we keep it in mind that it depends on temperature. It also turns out that \$I_S\$ is also temperature dependent. So sometimes it is important to remember this detail and to realize that you should expect temperature to affect your results. Temperature is often ignored in cases where the temperature isn't likely to vary much (such as with a wrist-watch, which is always kept near body temperature.) But temperature is often kept very much in mind in cases where PN junctions will be dissipating lots of power and therefore will be heating up a lot.



So, digging just a little deeper into the mathematical equation I mentioned earlier, there is a special diode equation:


$$I_D=I_{S}\cdot\left(e^\frac{V_D}{n V_T}-1\right)$$


[You can look it up as the Shockley equation.]


The \$-1\$ term at the end is there to mathematically adjust that log-lin curve I mentioned so that the curve goes right through (0,0). Or else, so that the current through the diode will be exactly zero when the voltage across it is also exactly zero. It usually doesn't amount to much, so for most practical purposes it can be ignored (and often is ignored.)


Let's re-write the above equation to ignore the \$-1\$ term and to solve it for \$V_D\$:


$$V_D\approx n\frac{k T}{q} \operatorname{ln}\left(\frac{I_D}{I_S}\right)$$


The above will become useful, shortly.




Let's now get back to your question.


You mentioned the idea of a diode whose voltage is \$1.8\:\textrm{V}\$. This will really only be true at some exact current through it, though. So let's say that this current is (you didn't say, so I get to make up a value) is \$20\:\textrm{mA}\$. Assuming temperature is fixed at ambient, there are two adjustable configuration constants in the basic Shockley equation: \$n\$ and \$I_S\$. (There are actually a few more in the temperature-dependent equation for \$I_S\$, but that's another matter.) So let's imagine that \$n=3\$ and \$I_S=2\:\textrm{pA}\$. We'd get \$V_D=1.796\:\textrm{V}\$ using the Shockley equation, which is very close to your figure.



The current through the resistor depends upon the voltage across the diode: \$I_R=\frac{V_{CC}-V_D}{R}\$. But the voltage across the diode, \$V_D\$, depends on the current through the resistor (since \$I_D=I_R\$ and \$V_D\$ is a function of \$I_D\$.) We can therefore write:


$$V_D\approx n\frac{k\:T}{q}\cdot \operatorname{ln}\left(\frac{V_{CC}-V_D}{R\cdot I_S}\right)$$


(Please note that \$V_D\$ is on both sides of that equation and that solving for \$V_D\$, anew, would be tricky.)


Let's use your \$R=1000\:\Omega\$ and your initial value of \$V_D=1.8\:\textrm{V}\$, as well as my \$n=3\$ and \$I_S=2\:\textrm{pA}\$ and \$V_T=26\:\textrm{mV}\$, and see where that gets us.


Using \$V_D=1.8\:\textrm{V}\$, we can compute that \$V_D\approx 1.594\:\textrm{V}\$. Plugging that back in a second time, we get \$V_D\approx 1.604\:\textrm{V}\$. Then \$V_D\approx 1.60355\:\textrm{V}\$. Then \$V_D\approx 1.603575\:\textrm{V}\$. Then \$V_D\approx 1.603574\:\textrm{V}\$.


So you can see that it settles down very fast. And we now have a value for the diode. \$V_D\approx 1.6\:\textrm{V}\$ instead of \$V_D\approx 1.8\:\textrm{V}\$ that we started with. This isn't a lot of adjustment.


The reason I dragged you through all this was to show you that it is practical to assume that the voltage across the diode is \$1.8\:\textrm{V}\$. The actual value will probably be different, too. But if you are using a diode voltage that assumes a current you intend on applying when you calculate a resistor value, then chances are that the final, actual current will be pretty close to your expected value.


But there is also another lesson here. I set up my diode parameters based upon an assumption that the voltage was true when the current in the diode was \$20\:\textrm{mA}\$. However, had we been designing a resistor for this case, the value would have been \$R=\frac{3.3\:\textrm{V}-1.8\:\textrm{V}}{20\:\textrm{mA}}=75\:\Omega\$. Obviously, the value for \$R\$ you gave is a lot different. So, either the voltage of \$1.8\:\textrm{V}\$ was for a different current or else \$R\$ wasn't set right. Either way, the above calculation automatically adjusted things to work it out in the end. We computed a lower voltage (obviously, since I assumed a current that was higher) for operation. And this lower voltage means a lower current (than the \$20\:\textrm{mA}\$ figure.) In this case, we'd get \$I_D=\frac{3.3\:\textrm{V}-1.6\:\textrm{V}}{1000\:\Omega}=1.7\:\textrm{mA}\$. That's a little higher than you'd get just assuming that the diode voltage was still actually \$1.8\:\textrm{V}\$. But again, it's not too far, either.




So all this points up why it is okay to just assume some things to make quick and easy work of a problem. It is reasonable for you to assume that if \$V_D=1.8\:\textrm{V}\$ then the current will be \$1.5\:\textrm{mA}\$. Even if you were using the diode in a circumstance that is fairly far from its assumed operation, you still tend to get pretty close in the end. This is because a diode will shift its voltage by anything from about \$100-200\:\textrm{mV}\$ for each factor of 10 in the current!! You can multiply the current in the diode by a huge amount and only cause a slight change in the voltage drop. It's this fact that makes assuming a fixed voltage for a diode to be fairly safe for many purposes, when considering diodes.



microcontroller - Should I get the PICKit 2 or 3?


Okay, having decided to pitch myself at the PIC family (including dsPIC), I now have a question about programmers. I've been hearing a lot of bad things about the new PICKit 3, and am wondering if I should get that or the apparently more venerable PICKit 2? If I want to be able to use the newest PICs, I think I might need to buy the latest, but I'm not so sure. Thank you!



Answer



I think the main reason behind PK3 hate is from this review by D.L. Jones. If you read (watch?) between the lines, D.L. Jones is upset because, well, the PK3 isn't the PK2. My response: It's a PIC chip programmer for hobby use, not for production work! Yes the physical UI is different between the two, but hey, your'e getting a OEM-supplied programmer for very little money that programs just about everything in their lineup (PK2 doesn't), so I wouldn't complain. Take what they give you! In the not-too-distant past, programmers were waay more expensive.


At work, we use ICD2 and ICD3 "hockey pucks" and the main reason we don't use PK2 is because the PK2 didn't support a particular micro we wanted to use in the past (the PK3 supports it now), so they had to upgrade. All of my coworkers said PK3 is probably a good way to start, since the part support problem seems to be resolved.


Saturday, 26 March 2016

opto isolator - Simple light bulb operated by button and optoisolator triac


I'm new to the world of electronics and I have a quite simple question.


Can I control my light bulb with something like this schema?


Schema


Power source is regular AC 230V (~320Vrms) source.


Here is The MOC3052 data sheet.


I want to control this using Arduino but is the underlying principle OK or not?


EDIT:


Modification with respect to Spehro's comments: enter image description here



But now I do not know how to connect the TRIAC :)


EDIT:


Would this circuit be OK?


Now the optocoupler is switching the triac.


enter image description here




opto isolator - Comparator output not fully switching on MOSFET


First Question for me. I have benefited from other answers here but have not fully resolved my problem. Here's my problem...


The LM311 Comparator output does not drive the N channel MOSFET fully on.


The LM311 has a 110mv ref voltage on the inverting input.

The non-inverting input is driven by an opto-isolator output. The Opto-isolator is driven by 1 of 4, AC 60Hz voltages. <1VAC, 9VAC, 55VAC and 115VAC.


The goal of the design is to have the FET fully turn on the 12VDC fan when there is appreciable AC voltage. So fan fully On for the 9, 55, and 115VAC voltages. It seems it should work because I measure voltages on the non inverting input of 1.6, 2.2 and 3VDC respectively for the 3 appreciable AC voltages. And my ref voltage on the inverting input is 110mv.


So it "almost" works because the fan is off at the <1VAC, but not fully "On" for the other AC voltages. I believe this is because Vgs is 167mv, 6.1V, 7.7V and 9.9 Volts for the 4 AC voltages listed above. And the fan is only getting 7, 8 and 10VDC instead of a desired 12VDC. Would really like to be able to fully turn this FET all the way on. So Close!


Any input or guidance is appreciated.


Ps-Things I think I've done right? Flyback diode across the fan. Putting N channel FET to switch to ground on low side of fan. LM311 has Open collector output using correctly?


PSS-I realize that the pinouts for the LM311 are not right in my schematic. I have them right in my protoboard circuit. Its a single device. Pin 2 is noninveritng and pin 3 in Inverting


Thanks Again.


enter image description here


The suggested duplicate question and answer doesn't help for the following reasons: Both diagram and schematic are"No file found" making it pretty difficult to follow the answers. I am not using any positive feedback in my circuit as I don't think I need one. I have a simple pull up resistor to my 12V supply, not a voltage divider to the power supply as is mentioned in the answer. Thanks.


Just for the record I wanted to post a more accurate schematic and thanks for the response on using a Cap to hold up the opto isolator output. I actually have a full wave input to the phototransistor but I'm sure the cap will help anyway. To answer the last question, the Pin 7 comparator output has a pullup resistor to 12v. The issue is still that Vgs is only 10v when the comparator has 3v on pin 2 and 110mv on pin 3. I would have expected the LM311 output to go much closer to 12v (Vcc) with those inputs. The intent is for the FET to go completely on for pin 2 voltage > pin 3. enter image description here





Why use DC motors for driving elevators?


This New York Times article says that on November 14, 2007 Consolidated Edison Company was going to end supplying direct current to the remaining several buildings that used those to run elevators.


I don't get why there would be DC-powered elevators.


Yes, at the end of 19th or the beginning of 20th century DC equipment was rather popular, but it's unlikely that an elevator would last a century and all the elevators I could find information for now run on AC.


Also DC is typically preferred for easier RPM control (like in trains, tramcars, etc) but this is not a problem for elevators - they typically use two-speed three-phase AC motors and speeds are changed by switching the number of poles.


Why would there still be elevators running on DC?



Answer



Century old motors were well built! And probably conservatively designed because electricity was new; they didn't know which corners you could safely cut.


In those days, everything mechanical was designed for easy maintenance; nuts, bolts, taper pins; simple tools to take the whole lot apart, adjust to take up wear, reassemble and use for another 10000 miles. Run out of parts? Turn another one to fit!



I had a 1910-era lathe still capable of turning within about 0.002" (traded it for a 1928 model!) and my 1840s watch is keeping very good time.


In an era of relatively cheap labour and expensive materials, this made sense. Who knows, we may end up back there some day!


Meantime it's worth studying how things from another era are made; partly to keep the skills alive and partly because good engineering is good engineering, from any era.


Just to clarify because this seems to have hit a nerve : I'm not simply equating long life with good engineering. What makes these motors good engineering is the skill with which they met their design goals using materials and techniques available at the time.


And long life was almost certainly one of them; reliability (not measured as MTTF but the ratio between MTTF and MTTR) i.e. easy repair, and efficiency. Swapping motors for a fix is not the issue; replacing brushes, re-lining bearings or (major job!) rewinding the motor was what happened - and what the motors were designed for. It's NOW we kinda-sorta-fix things by replacing motors.


We haven't improved THAT much on 92% efficiency in a motor in the last hundred years, but we do it with a lot less copper and iron. We can equally well admire a modern brushless motor with sealed bearings and no maintenance for ten years; they can both teach us something.


rtc - ds1307 drift too big


I have a RTC ds1307 mounted on a prototype board ( the one with 3 pin stripped ), and I'm experiencing a delay of about 5 sec/day, far too big compared to some research I did. Can that delay be caused from extra capacitance added by the prototyping board or is just the crystal? This is the crystal I'm using.



Answer



Well, I solved the drift. After checking the crystal capacity and seeing it is correct as the frequency, I decided to power the Arduino power from an external power supply, my DS1307 uses the +5v from the Arduino board. With the new power supply the clock is accurate ( I can't see a drift of second in 24 h ). I don't know if it was a problem in having a barely enough voltage with the USB or if that supply was "dirty", but in any case the single cause was the power supply.


pcb fabrication - PCB coating for a high temperature environment



What PCB coating is good for a high temperature environment (my environment is about 30-70 C), and is available in a spray can or so that is easy to implement without need of a device/machine?



Answer



There are silicone based conformal coatings, available as spray. They should bear this temperature range easily. Polyurethane based sprays may be used, too. We had tests running with PU. It proved usable up to 90°C. But all depends on the actual use. You can buy those materials manufactured by several companies like CRC industries, electrolube etc.


If you want to increase creep resistance by using a conformal coating, you will have to do several tests anyway.


soldering - What is the purpose of a PCB with no copper tracks, but only unconnected copper rings?


I have a PCB which has the perfect size for a project of mine, so I would like to use it if possible. However, the copper plating on the back side of PCB only surrounds the individual holes (that is, no holes are interconnected). See picture right here:


Strange PCB


I find this strange. How can this be useful? I would definitely need some copper tracks with interconnected holes in there because some components need to be connected to each other. Am I supposed to make my own tracks somehow?


I saw some stuff online about people who would insert multiple wires in the same hole to make interconnections, but this seems undesirable. I'd rather avoid that if there is some way to make tracks.



Answer



What you've got is called a prototype board. It is available at electronics suppliers everywhere and is obviously not meant for production. Join things together any way that is convenient for you. Many methods have been pictured. Another common way is inserting a component lead beside its next connection and just bending it over to fit.


The results are typically quite messy, but it can take a lot more handling than a breadboard prototype. Thus it is a common step before getting printed and etched boards made.


You can also find prototype boards in the same circuit pattern as the push-in breadboards, so you can simply transfer your circuit from one to the other, solder, and install.



Friday, 25 March 2016

microcontroller - Internal or external oscillator


I always use the internal oscillator that pics have as I have never found the need to run anything at higher frequency than 8 MHz (which is the fastest the pics I use tend to be able to go). Are there any reasons, beyond going above 8 MHz, that mean I should use an external oscillator? It just seems like one more thing to go wrong to me but I'd be interested to hear what others do.



Answer



As others have said, accurate frequency and frequency stability are reasons to use a external ceramic resonator or crystal. A resonator is several times more accurate than the internal R-C oscillator and good enough for UART communication. A crystal is much more accurate, and necessary if you are doing some other types of communication like CAN, USB, or ethernet.



Another reason for a external crystal is choice of frequency. Crystals come in a wide range of frequencies whereas the internal oscillator is usually one frequency with maybe a choice of 4x PLL enabled. Some newer 24 bit core PICs have both a multiplier and divider in the clock chain so you can hit a wide choice of frequencies from the single internal oscillator frequency.


There are of course various applications that inherently require accurate frequency or timing other than communications. Time is the property in electronics that we can measure most accurately cheaply, so sometimes the problem is transformed into one of measuring time or producing pulses with accurate timing.


Then there are applications which require some long term synchronization with other blocks. A 1% oscillator would be off by over 14 minutes per day if used as the basis for a real time clock. Accurate long term time may also be needed without having to know real time. For example, suppose you want a bunch of low power devices to wake up once every hour to exchange data for a few seconds and then go back to sleep. A 50ppm crystal (very easy to get) will be off no more than 180ms in a hour. A 1% R-C oscillator could be off by 36 seconds though. That would add significant on-time and therefore power requirements to the devices that only needed to communicate for a couple of seconds every hour.


resistors - Photodiode - circuit questions


I am a bit confused on a few things regarding photodiodes. Here are two circuits that I am referring to:


Circuit1


or  


Circuit 2


For the second circuit the capacitor is not of importance.


Here are my fundamental questions:



  1. Why do we need an external voltage?


  2. Why do we need a resistor?

  3. What is exactly happening to the resistor when light hits the photodiode?

  4. Why is the voltage measured between the photodiode and the resistor?

  5. Why doesn't the external voltage influence the voltage from the photodiode (assuming the voltage from the photodiode is relatively low compared to the external voltage)?

  6. For the second photo: what would be the need for a capacitor here? What would it change?


I don't expect all the questions from one user to be answered but I would definitely appreciate some insight or perhaps some recommendations what I should read to fill in some of the gaps. I know the questions seem rudimentary but I need those "Aha!" moments right about now.



Answer




Why do we need an external voltage?




Because it makes the photodiode more sensitive, it lowers its capacitance, and it makes its capacitance more predictable.



Why do we need a resistor?



Because a photodiode acts like a current source in parallel with a diode. So when it is reverse-biased, it just acts like a current source.


schematic


simulate this circuit – Schematic created using CircuitLab



What is exactly happening to the resistor when light hits the photodiode? Why is the voltage measured between the photodiode and the resistor?




Current flows through the photodiode when light hits it. It then flows through the resistor and generates voltage.



Why doesn't the external voltage influence the voltage from the photodiode (assuming the voltage from the photodiode is relatively low compared to the external voltage)?



There is no "voltage from the photodiode". There is current from the photodiode, that develops voltage across the resistor.



For the second photo: what would be the need for a capacitor here? What would it change?



It shorts out high-frequency current from the photodiode, so the RC combination acts like a low-pass filter.



battery charging - What happen with cells with different current rating put in parallel?


I don't understand how cells behave when connected in parallel. So what if I have two Li-Ion cells: one ist "rated" at 15 amps (which means that the cell is able to discharge at 15 amps without problems , right?) The other cell ist rated to 5 amps. Now assume both have appropriate same Voltage to connect them both in parallel. What happens if you connect a load which would draw 10 amps now? Would both cells try to discharge with the same 10A (and thus the 5A-cell would overheat and fail...), or would the current be spread up eavenly? Is it actually forseeable at all what would happen, since it depends on the internal resistance of both cells, doesn't it? Does someone know what would happen?


Then another question: what if you put two cells of different capacity in parallel? Isn't the cell with the higher capacity supposed to give more current? Because the discharge curve of the high-capacity-cell is above the discharge curve of the low-capacity cell. So the high-capacity-cell would have to discharge more of its current until it decreases its voltage to the same level as the low-capacity-cell? So would that mean that the internal resistance gets lower with a higher capacity, is it proportional?


Hopefully my explanations aren't to confusing and hopefully there are people who are bothered by the same question :) Thank you!




digital logic - 3-bit multipliers - how do they work?



I need to understand how 3-bit multipliers work and then I must design one. I've read through Wikipedia's binary multiplier but I just can't wrap my head around it. I don't understand where to start. Could you please explain to me what happens when two 3-bit numbers are run through a 3-bit multiplier? Maybe then I can reconstruct each step in a circuit on paper. Alternatively, could you outline the relevant sub-concepts I need to grasp?


In general, I'm thankful for any help in understanding 3-bit multipliers.


EDIT: Thank you to everyone who contributed to this Question. You all helped me understand the relevant concepts, and so I wish I could accept all answers as solutions.



Answer



If you're a EE/CPE student and you're just starting to learn logic, maybe you haven't learned this yet but you will.


Arithmetic and logic functions are essentially realized in circuit form by starting with a truth table and filling in the values that implement the function you want. For 2x2 bit multiplication, this is the truth table:


Logic Friday From the program Logic Friday


Go through each row, and you'll see how it implements it. It is in the form A0,A1 * B0,B1 = F0,F1,F2,F3


Sorry, it's backwards as typically the LSB is A0 or B0, I numbered it wrong. Anyways, take for instance the last row. It says 11 * 11 = 1001. In decimal, that's just 3 * 3 = 9


After the truth table is complete, you could fill this into a karnaugh map, and derive the equations for each output of the circuit. In this case, I let this handy program do it for me.



The output came to this.


Logic Friday


At this point, you can see that I have an equation for F0 through F3 based on the inputs. Now I just need to throw in the logic gates to match those equations. And voila, you have a circuit that performs binary multiplication.


This is the simplistic side of it. Real processors and the ALUs inside of them don't exactly do it this way. For instance on a 64-bit computer, the amount of combinational logic necessary to perform 64x64 bit multiplication would be insane. Instead, as the wikipedia article you read states, they multiply one of the 64-bit operands by each individual bit of the 2nd operand, each time shifting the result. Finally, they add all of the partial sums together. That is the absolute most simplistic method of performing the multiplication sequentially. Some processors though have even faster multiply implementations that make use of wallace trees


Also, if you'd like a little more insight on the sequential type multiplier, here you go. This may be a little more difficult so don't worry about understanding how each of the components works underneath, because you will learn it soon. I leared shift registers, ALUs, and all that by the end of my first digital logic course.


http://faculty.kfupm.edu.sa/COE/mimam/files/COE200experiment13.pdf


This image comes from http://faculty.kfupm.edu.sa/COE/mimam/files/COE200experiment13.pdf


This is a simplified 4x4 bit version, and it goes sort of like this:


1) The 4-bit multiplier is loaded and stored in the P shift register, specifically Pl. Also, the 4-bit multiplicand is stored in the B-register. Ph is all 0's


2) On each clock cycle, the P register is shifted to the right, and the rightmost bit, P0, is sign-extended (not shown, to make it 4 bits), and ANDed with the multiplicand in the B-register. If you go back to the binary multiplier page on wikipedia, under multiplication basics, the 2nd grey area, you can see this happening with each staggered row, it is an AND operation that essentially does the multiplication since each time it is either multiplicand x 0, or multiplicand x 1.



Since the ALU is performing the add operation, the result of the 1 bit multiplication is added to the previous partial sum, in this case 0 since this is the first step, and stored in Ph.


3) On the next cycle, the P register is again shifted, and so you can see how the Ph output gets shifted and added again to the result of the 1-bit multiplication.


4) At the end, you have an 8-bit result stored in the p register.


power - Phase Difference


$$i_1 = sin(wt +45^0) $$ $$ i_2 = -sin(wt +60^0)$$


Question : what is the phase difference dows i1 lead i2


My method


1 ) Eliminate minus sign that is i2 = sin(wt + 60 + 180 ) = sin(wt + 240 )


My answer is that i1 leads i2 by 45 - 240 = -195


but correct answer is i1 leads i2 by +165 deg




8085 - Why in HL pair, H is stored after L register


Why in 8085, during LHLD and SHLD instructions L is used first while in BC and DE, B and D are used respectively?




Thursday, 24 March 2016

arduino - Why this pair of IGBT's died silently?



Before some days I have taken a look at circuit which controls AC current's frequency. That circuit was a VFD which looks like:


schematic


simulate this circuit – Schematic created using CircuitLab


But this circuit is for controlling 3 Phase motor.


So, I tried to make a similar one that can control a single phase load, like a bulb.


So, I created the below shown circuit:


schematic


simulate this circuit


And here is the sketch of arduino to give pulses to Gate of IGBTs:


int Phase1TransistorA = 2;

int Phase1TransistorB = 3;
int Phase2TransistorA = 4;
int Phase2TransistorB = 5;

int t = 4; //time in seconds
int T = 1000 / t;
int p = 1028; //number of duty cycles of pwm to create half ac-cycle.

void setup()
{

pinMode(Phase1TransistorA, OUTPUT);
pinMode(Phase1TransistorB, OUTPUT);
pinMode(Phase2TransistorA, OUTPUT);
pinMode(Phase2TransistorB, OUTPUT);
}

void loop()
{

for (int i = p; i >= 1; i--)

{
digitalWrite(Phase1TransistorA, HIGH);
digitalWrite(Phase2TransistorA, HIGH);
delay(T / (p * i * 2));
digitalWrite(Phase1TransistorA, LOW);
digitalWrite(Phase2TransistorA, LOW);
delay((T/ (p * 2)) - (T / (p * i * 2)));
}

for (int i = 1; i >= p; i++)

{
digitalWrite(Phase1TransistorA, HIGH);
digitalWrite(Phase2TransistorA, HIGH);
delay(T / (p * i * 2));
digitalWrite(Phase1TransistorA, LOW);
digitalWrite(Phase2TransistorA, LOW);
delay((T/ (p * 2)) - (T / (p * i * 2)));
}

for (int i = p; i >= 1; i--)

{
digitalWrite(Phase1TransistorB, HIGH);
digitalWrite(Phase2TransistorB, HIGH);
delay(T / (p * i * 2));
digitalWrite(Phase1TransistorB, LOW);
digitalWrite(Phase2TransistorB, LOW);
delay((T/ (p * 2)) - (T / (p * i * 2)));
}

for (int i = 1; i >= p; i++)

{
digitalWrite(Phase1TransistorB, HIGH);
digitalWrite(Phase2TransistorB, HIGH);
delay(T / (p * i * 2));
digitalWrite(Phase1TransistorB, LOW);
digitalWrite(Phase2TransistorB, LOW);
delay((T/ (p * 2)) - (T / (p * i * 2)));
}

}


When I tried to power up the bulb, the first pair of IGBTs died silently even without heating. I would like to know Why this happened and the steps to solve the problem.


The pair of IGBTs that died:


enter image description here



Answer



Multiple problems. It sounds like you don't really understand HV electronics, and I suggest you stop before you get injured or worse. Your circuit is dangerous (to you, your Arduino and your computer).


Your 1N4001's are only rated to 50 V -- you should use 1N4007's if you need diodes.


You have nothing to limit inrush current when plugged in to the mains -- likely will blow the bridge rectifier also.


But - you don't need diodes to drive IGBTs. You only need the anti-parallel diodes if you are driving inductive loads (or very long wires).


The IGBTs won't turn off fast enough -- there is nothing to discharge the gate.



You can't drive the high-side IGBTs like that. You need a level shifter.


3.3 V isn't enough to drive an IGBT. Most need 5 .. 10 V.


You don't need an H-bridge to drive an incandescent light -- just a single low-side switch. That could be an IGBT, MOSFET (need rated > 450 V for US 110 V applications, > 700 V for 220 V mains supplies), or a triac (which is commonly used, but is best with a different type of controller).


I RECOMMEND THAT YOU STOP DOING THIS UNTIL YOU UNDERSTAND THE HAZARDS INVOLVED.


arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...