Friday 31 May 2019

Best way to control 75 LEDs with Arduino


I need to control 25 groups of 3 LEDs or 25 RGB LEDs. Each group will be dismissed from the uC by up to 20 cm (about 8 inches). 20 cm is very safe assumption but I think it will be 10 cm or less.



However, I think If it be even 5 cm, it will be hard to create in matrix way, so I think using MAX7219 likie IC (http://www.arduino.cc/playground/Main/MAX72XXHardware) is not best idea.


I will probably use shift registers (http://www.arduino.cc/en/Tutorial/ShiftOut). I can connect multiple 74HC595 or use something like STP16C596.


I prefer STP16C596 but they are obsolete. I found SCT2026 (http://zefiryn.tme.pl/dok/a04/sct2026.pdf) but I'm not sure is It right choice.


One more note. My current project requires only "2 bit control" over each group (3 LEDs off, or selected and turned on only one of them), but I don't think it make my project easier or cheaper, also controlling each LED separately will give much more flexibility in case of changes.


What solution will be fit best for my requirements.


It will be nice if parts will be available in this shop - http://www.tme.eu/en/katalog/?&page=1,20#main or http://eu.mouser.com/ (but i prefer first one).



Answer



I would suggest going the matrix route with a driver like the MAX7219 you mentioned or maybe, if you wanted a lot more control, the TLC5951DAP, a TI LED driver meant for RGB leds that will give you 24 channels with a 12 bit resolution (4096 different steps of brightness for each channel). This will allow you to turn on each of the R, G, and B LEDs to different brightnesses to mix the colors to what you want.


You could use ribbon cable for the wiring to each of the LEDs (I'm assuming wiring is why you do not like the idea of the matrix) and have all of the cables plug into a controller board. For something like this, I would definitely recommend that you make a pcb for the controller because that's a lot of connections to try to do by hand. That's just what I would do though.


The STC2026 looks to be directly compatible with the STP16C596, so that's a perfectly good replacement if you want to use it. I would agree that controlling each LED individually will probably be cheaper and easier than trying to use some sort of MUX to have 2bits control which LED is on.



Hope that helps.


What are rubbery, conductive strips called on the sides of an LCD screen?



I found a component attached to a PCB inside one of my old $5 devices. There are pink, rubbery things attached to either side of the LCD that can bend and were firmly attached (glued?), and there are a lot of exposed conductive traces where the pink things were attached on the PCB.


I would like to know what these pink things are. Pictures are shown below.


LCD


The front side of the LCD ^


LCD


The back side of the LCD ^


PCB


The front side of the PCB. This is where the LCD is connected to. ^


PCB


The back side of the PCB ^



Again, I would like to know what the pink things are.



Answer



Often called Zebra strips (or Elastomeric connectors). They have very thin vertical conductors that connect between flat PCB pads and things like LCD pads on glass.


Here is a link with a similar pink component.


http://en.wikipedia.org/wiki/Elastomeric_connector


microcontroller - What happens when an embedded program finishes?


What happens in an embedded processor when execution reaches that final return statement Does everything just freeze as it is; power consumption etc, with one long eternal NOP in the sky? or are NOPs continuously executed, or will a processor shut down altogether?


Part of the reason I ask is I am wondering if a processor needs to power down before it finishes execution and if it does how does it ever finish execution if it has powered down before hand?



Answer



This is a question my dad always used to ask me. "Why doesn't it just run through all the instructions and stop at the end?"


Let's take a look at a pathological example. The following code was compiled in Microchip's C18 compiler for the PIC18:


void main(void)

{

}

It produces the following assembler output:


addr    opco     instruction
---- ---- -----------
0000 EF63 GOTO 0xc6
0002 F000 NOP
0004 0012 RETURN 0

.
. some instructions removed for brevity
.
00C6 EE15 LFSR 0x1, 0x500
00C8 F000 NOP
00CA EE25 LFSR 0x2, 0x500
00CC F000 NOP
.
. some instructions removed for brevity
.

00D6 EC72 CALL 0xe4, 0 // Call the initialisation code
00D8 F000 NOP //
00DA EC71 CALL 0xe2, 0 // Here we call main()
00DC F000 NOP //
00DE D7FB BRA 0xd6 // Jump back to address 00D6
.
. some instructions removed for brevity
.

00E2 0012 RETURN 0 // This is main()


00E4 0012 RETURN 0 // This is the initialisation code

As you can see, main() is called, and at the end contains a return statement, although we didn't explicitly put it there ourselves. When main returns, the CPU executes the next instruction which is simply a GOTO to go back to the beginning of the code. main() is simply called over and over again.


Now, having said this, this is not the way people would do things usually. I have never written any embedded code which would allow main() to exit like that. Mostly, my code would look something like this:


void main(void)
{
while(1)
{
wait_timer();

do_some_task();
}
}

So I would never normally let main() exit.


"OK ok" you saying. All this is very interesting that the compiler makes sure there's never a last return statement. But what happens if we force the issue? What if I hand coded my assembler, and didn't put a jump back to the beginning?


Well, obviously the CPU would just keep executing the next instructions. Those would look something like this:


addr    opco     instruction
---- ---- -----------
00E6 FFFF NOP

00E8 FFFF NOP
00EA FFFF NOP
00EB FFFF NOP
.
. some instructions removed for brevity
.
7EE8 FFFF NOP
7FFA FFFF NOP
7FFC FFFF NOP
7FFE FFFF NOP


The next memory address after the last instruction in main() is empty. On a microcontroller with FLASH memory, an empty instruction contains the value 0xFFFF. On a PIC at least, that op code is interpreted as a 'nop', or 'no operation'. It simply does nothing. The CPU would continue executing those nops all the way down the memory to the end.


What's after that?


At the last instruction, the CPU's instruction pointer is 0x7FFe. When the CPU adds 2 to its instruction pointer, it gets 0x8000, which is considered an overflow on a PIC with only 32k FLASH, and so it wraps around back to 0x0000, and the CPU happily continues executing instructions back at the beginning of the code, just as if it had been reset.




You also asked about the need to power down. Basically you can do whatever you want, and it depends on your application.


If you did have an application that only needed to do one thing after power on, and then do nothing else you could just put a while(1); at the end of main() so that the CPU stops doing anything noticeable.


If the application required the CPU to power down, then, depending on the CPU, there will probably be various sleep modes available. However, CPUs have a habit of waking up again, so you'd have to make sure there was no time limit to the sleep, and no Watch Dog Timer active, etc.


You could even organise some external circuitry that would allow the CPU to completely cut its own power when it had finished. See this question: Using a momentary push button as a latching on-off toggle switch.


Thursday 30 May 2019

led - What resistor to choose for circuit?



I'm not good at physics, but I'm trying to make a lantern. So I have an LED with this characteristics:




  • N = 3 Watt

  • I = 0.7 Ampere

  • U = 3.4-3.6 Volt


So I connect it to 6V battery, but need ~3.5 V. What type of resistor do I need?


I calculated internal resistance with R = U / I and got 3.6 / 0.7 = 5.14 Ω. And using this formula I = 𝛆 / (R + r) I got total resistance of 6 / 0.7 = 8.57 Ω. Here 8.57 - 5.14 = 3.42 Ω of external resistor. Am I right?



Answer



Powering an LED with a battery and using a current limiting resistor is not recommended. Especially for a lantern where you want a more consistent luminous output.


You could use a buck/boost DC-DC converter to keep the voltage consistent and adjust the output voltage for a high efficiency current liming resistor.


You must first measure the actual Vf then adjust the output voltage



The TI High Efficiency Single Inductor Buck-Boost Converter TPS63030DSKR was made especially for this type of application (i.e. battery powered white LED).


enter image description here






I'm connecting two 3V CR2032 Lithium batteries in series.



A CR2032 has a capacity of only 235 mAh and that capacity is for a much lower load than 700 mA, if you can get 700 mA.
Source: DATASHEET ENERGIZER CR2032


with your proposed design the LED will light up for a few minutes then dim to 20% of the original intensity a few minutes later.



I would recommend using Panasonic or Samsung 18650 Li-ion cell(s).







An LED being driven with 700 mA will need some thermal management. You may do better with a higher efficacy LED driven at a lower current.


Your Vf of 3.5V is too high. I recommend the highest efficacy LEDs available today (August 2018)



  • High power Cree XP-G3 (2.7V-3V) or

  • Mid power Samsung LM301B (2.6V-2.9V)






A constant current regulator made for battery operation is recommended. This does not work with your 6V battery. This circuit was designed for a single or dual cell supply (e.g. AA, NiMH). With this circuit the battery voltage should not exceed the LED's Vf


Microchip MCP1643
Very simple inexpensive ($1 single qty) made to drive a single white LED.
0.5V - 5.0V input, 5.0V, 550 mA output.
Works well with mid and high power LEDs.



MCP1643 is a compact, high-efficiency, fixed frequency, synchronous step-up converter optimized to drive one LED with constant current, that operates from one and two-cell alkaline and NiMH/NiCd batteries. The device can also drive two red/orange/yellow series connection LEDs.




enter image description here
enter image description here


Proper inrush current limiter 50A universal motor


We have one dental equipment with one universal motor  in 2000W and 220V range shown below:


enter image description here


And we gave two corruption in selled device to customers which have inrush current problem by switching the universal motor, so one of the switch poles has been burned like this ( 220V 16A):


enter image description here



And 


enter image description here


So i searched the internet for solution and seen the ntc in this inrush current :


2200÷220=10A >> 3×10A ~ its inrush current!!


Like MS35 NTC with this shape:


enter image description here


But it is expensive (~5 €), so what is any other way with ...?


Thanks for your attention.




Best Electronic Kits



I would like to compile a list of all the best electronics Kits you have come across.


"Best" can be because you





  • learnt something from them




  • found them very satisfying




  • had something very cool at the end




Personally I loved the Lilypad Kit - cause it gets you started without actually having to make something specific and the Herbie Kit cause its fun to play with when its done.





adc - Use BBB analog inputs with 0..5V or 0..10V


I plan to use the BeagleBone Black analog inputs for sampling of analog data. But there are some major problems for this:



  • BBB allows a maximum of 1.8 V analog input voltage while I have 5 V or 10 V max


  • there are two lines AGND and VDD_ADC where I don't know how they are involved here and what to do with them

  • my knowledge in electronics is very limited


My only idea: a voltage divider with two resistors (that's within my range of knowledge), but there I see some problems:



  • resistor tolerances which make measured data inaccurate

  • in case of tolerances being at the wrong end it may be possible the maximum 1.8 V analog input may be exceeded and the BBB can be killed

  • when I choose values of resistors in a way where this can't happen, I lose a part of the limited 12 bit sampling range


So...what could I do to solve this? How can I measure 0..5 V or 0..10 V ranges with the 0..1,8 V ADC range of the BBB?



It would be really nice when somebody could provide a schematic I could use for setting up my hardware (yes, soldering some components is within the range of my electronic possibilities ;-)


Thanks!



Answer



Use a voltage divider to attenuate the signal. Sometimes its advantageous from an impedance perspective to buffer the signal with an amplifier (but is harder to wire). The attenuation is for 0 to 5V in the schematic. You can use the link to calculate it for 10V.


Input protection is included on most devices, but usually cannot handle large currents. If the source connected to the ADC has large currents, you can protect inputs of downstream devices with diodes or other methods


If resistor tolerances are an issue, then use better resistors (they can be bought in 0.1% or sometimes 0.01%) which is sufficient for most applications.If you need more absolute accuracy, then you'll have to calibrate the resistors.


You can find the accuracy by using the resistance tolerance and plugging into the equation:


$$ \frac{Z_2}{Z_1+Z_2} = \frac{5.6k}{10k+5.6k} = 0.359$$


And then you plug in the highest and lowest tolerances for a 5.6k resistor with a 1% tolerance you would get 5656Ω and 5544Ω


$$ \frac{5656}{10100+5656} = 0.358$$



so if both resistors were at their maximum tolerance you'd be 0.64% off in your software with 1% resistors.


One problem with microcontroller ADC's is they are more susceptible to noise because the voltage range is smaller and usually have a lower resolution.


schematic


simulate this circuit – Schematic created using CircuitLab


Vin would be from the 0 to 5V range and Vout would be your 0 to 1.8V range


I forgot to answer about the power. The beaglebones VDD_ADC is just the digital 1.8V line with an inductor and capacitor for a filter (to filter out digital noise) The AGND is a separate ground to give a return current that is noise free also. So any analog signals\circuits should be referenced from AGND. The VREF is also tied to the VDD_ADC so the ADC's are going to be noisy. If you really need accuracy switch to a dedicated ADC and reference.


Wednesday 29 May 2019

motor - Explanation for Differing Stator Winding Orientations


As a layperson, I'm trying to understand the basic configuration for an induction motor or generator. I've looked at many diagrams and photos/cutaways of stator wiring and I've noticed two different orientations for the windings:


All the diagrams/photos I've seen show an individual winding in the shape of a rectangle with rounded corners.




  1. Type One - The axis of the winding points toward the shaft of the rotor.

  2. Type Two - The axis of the winding points 90deg away from the the shaft of the rotor.


The difference between these two orientations is making it difficult for me to conceptualize the "rotating electromagnetic field" that exists in motors/generators. I am looking for an explanation of the pusposes behind these two winding orientations.


[EDIT]


45deg orientation:


enter image description here


0deg orientation:


enter image description here


90deg orientation: I can't find one right now.




Answer



I think you may have found a good example of something that I've been looking for which came up in my answer to this question. Namely, the difference between a sinusoidally wound motor and a trapezoidally wound motor.


The way in which a motor is wound controls the distribution of the magnetic flux density throughout the motor. Which in turn controls the shape of the Back-EMF, which in turn dictates how best to drive the motor (i.e. which commutation method you choose). The different control methods can be read about in the aforementioned answer.


The below diagrams are taken from the master's thesis of James Mevey. This first diagram shows two simplified motors. Each has only a single winding. The motor on the left has "sinusoidally shaped" magnets and the motor on the right has "trapezoidally shaped" magnets.


sine versus trap magnets


The resultant flux densities look like so:


sine versus trap flux densities


Having magnets of the shape in the right hand motor and modifying the distribution of the windings would have a very similar effect.


I think that your "45° orientation" motor is sinusoidally wound. And if you were able to look at how the windings are connected and overlapped you should be able to see how the magnetic field would get stronger and weaker in a sinusoidal pattern.


And I think that your "0° orientation" motor is trapezoidally wound. Which you can almost see since the windings are distributed in just a few big blocks.



As for your "90° orientation" motor, I think you mean this:


LEAF motor windings


Which is a whole different beast. That is a picture of Shane Colton's Less Epic Axial Flux (LEAF) motor.


The motors shown at the top of my answer and in the OP are radial flux motors. In this design, the rotor is on the inside (or occasionally on the outside) of the stator windings. In an axial flux motor, the rotor is in front of the stator windings.


axial versus radial


The benefits of an axial flux motor are that it can be made thinner and lighter allowing it to fit better into certain geometries and change direction quicker.


Visualization of the rotating magnetic field can be difficult without good software.


flux density software


But usually a good motor manufacturer will provide you with all the details on how best to drive their motor on the side of the box. Still, the references in the answer I linked above and in this answer provide a wealth of information (perhaps too much) on what exactly is going on inside a motor as it's driven.


pcb - Blind/buried vs. through hole vias?


I'm trying to learn PCB design and, from what I've read and seen, there appear to be three different types of vias:



  1. Through hole - goes all the way through the board

  2. Blind - goes from the top or bottom layer to some layer in between the top and bottom, but not all the way through


  3. Buried - is between the top and bottom layers


It seems like most semi-complex boards I've had the opportunity to look at are 4-layer boards, and that usually one layer is dedicated to GND, another to VCC, and then the other two have traces. My question is what kind of via is most appropriate when trying to connect a pad or trace from one layer to the GND or VCC layers? I ask because I would have thought that a blind or buried via should be used, but it seems like most boards I've looked at use through hole vias and that there's just a stop around the via on the layers it's not supposed to be connected to. Is there a reason to use that method instead of using a blind or buried via?



Answer



Blind and buried vias add a lot to the cost of a multi-layer board, and are only used on high-density, high-performance systems. The increase in cost is because the layers have to be drilled separately, assembled, and then the holes are plated. Blind vias are sometimes back-drilled (the unwanted plating is removed with a slightly larger drill from the back) which reduces the cost, as the layers are stacked before drilling.


How to calculate minimum gate current and voltage of a TRIAC


I want to use this TRIAC: http://www.littelfuse.com/data/en/Data_Sheets/Littelfuse_Thyristor_Lxx06xx_Qxx06xx_Qxx06xHx.pdf


but only the maximum Igt and Vgt are given (25mA and 1.3V). How much current at what voltage do I need to trigger a TRIAC?




Tuesday 28 May 2019

protocol - Rolling Code Explanation


Could somebody explain how rolling code protocols such as KeeLoq work? I understand the basic premise that they use a different code each time so you can't just use replay attack, but I don't understand how one side verifies the correct code etc.


Furthermore, how do they perform an initial synchronization if the index into the rolling codes isn't known/shared beforehand?


If you have to use Keeloq as an example to explain that is fine, but I would rather a general explanation of rolling codes.



Answer




Rolling codes require several part to function correctly. Here I'll describe a generic implementation that uses all the parts in a specific way. Other systems are variations on this theme, but generally employ many of the same techniques in a similar way. Rather than try to describe the complete implementation and how it works at once, I'll describe a simple system, and add complexity as we go until we reach a cryptographically secure system.


A non cryptographic rolling code is simply a transmitter and receiver that both use the same pseudo random number generator (PRNG). This generator has two pieces of important information: a calculation, and the previously generated number. The calculation is generally a linear feedback equation that can be represented by a single number. By feeding the PRNG with the previous number, and keeping the feedback number the same a specific sequence of numbers is generated. The sequence has no repeated sequences until it's gone through every number it can generate, and then it starts over again with the same sequence.


If both remote and transmitter know the feedback number, and the current number, then when the remote transmits the next number, the receiver can test it against its own generator. If it matches, it activates. If it doesn't, it rolls through the sequence until it finds the number the remote sent. If you press the remote again, then it should match, and it'll activate because the previous transmission already synchronized the number generators. This is why you sometimes have to press the unlock button twice - your receiver or transmitter are out of sync.


That's the rolling part of the code. If the PRNG is long enough, it's very hard to find out the feedback number without many numbers in the sequence in a row, which is hard to obtain in normal use. But it's not cryptographically secure.


On top of that you add typical encryption. The vehicle manufacturer uses a specific secret key for the transmitter and receiver. Depending on the manufacturer you might find that each model and year have a different code, or they might share the code among several models of vehicles and over several years. The trade off is that each one then requires a different remote to be stocked, but the problem with sharing a code over many models is that if it's broken then more cars are vulnerable.


Behind the encryption you have button info, the PRNG generated number, and a little information about the feedback number. Not enough to make the PRNG from scratch, but enough that after a certain number of button presses, and with some inside information about the limited space a feedback number can involve (again, manufacturer, line specific) then the receiver can, after several training transmissions, determine the feedback number, and start tracking the PRNG for that remote.


The rolling code is meant only to stop replay attacks. The encryption is meant to secure the rolling code to avoid it being broken. With only one or the other the system would be too easy to break. Since the manufacturer controls both the transmitter and receiver, training doesn't involve public key cryptography or anything particularly involved. It also prevents aftermarket fobs from working in cars with this type of system.


Rolling code isn't impervious, though. The old keeloq system was successfully attacked just a few years ago (after a decade of use) so the manufacturer encryption code can be found, and the rolling codes can be found more easily. Earlier than that it has been attacked in ways that allowed people to take vehicles without actually breaking the code. In response the new encryption key is 60 bits. Not as secure as many modern encryption systems, but secure enough that it'll probably last many more years before it's broken.


operational amplifier - What's wrong with this circuit to convert 0-5V to +10/-10V


I'm trying to come up with a solution to use the analog output of a DAC to drive the X-Y axis control of a commercially available laser 'closed-loop moving magnet' driver.


I found an explanation on how to use an op-amp to create a differential amplifier here and a calculator here, but I can't get that to work without a 2.5V reference voltage.


I also found a simpler design for such a circuit here, but when I try that in a simulator (I use iCircuit on my iPad) it doesn't swing from -10V to 10V but from -8V to 12V (approximately). This is the circuit:


enter image description here


This is my testing in iCircuit:


enter image description here


Tried it with the included circuit simulator, don't know how it works exactly:


schematic


simulate this circuit – Schematic created using CircuitLab



My question is, is this simpler design the way to go, but are my resistor values wrong? Or do I need to go with the first circuit design but need to add something to get a 2.5V reference?


I have very little information on the exact electrical requirements of the scanner, but I'm assuming it's a product designed to be used in an ILDA laser device and fairly compatible to that standard.


UPDATE In iCircuit, I replaced the lower 10K resistor with 20K and the feedback resistor from 15K to 30K, and it looks like I'm getting the desired output now. Still, I don't know if this is trustworthy or not.


Bonus question: I have an ST LM324N opamp lying around from an old lab kit. Do you consider this device suitable for this task, if I supply +12V/-12V to it?



Answer



Your circuit is incorrect. What you are trying to do is a gain+offset (negative offset) so you want to gain it up and offset the virtual ground point. You don't need that 10k/10k voltage divider as you've drawn it to provide a 2.5V reference.


Since your full scale output from the DAC is 5V, and you want a full scale output from the opamp of 20V (-10 to +10) then you need to have a gain of 4 in the opamp. That gives you 0-20V. So you want (DAC x Gain) - Offset.


In a non-inverting op-amp, the + input has a gain set by the (feedback resistor/input resistor)+1. However, the negative input has a gain of simply the (feedback resistor/input resistor). So a non-inverting input with a gain of 4 will have a a gain of 3 from the negative input. You can use the negative input to offset the fullscale 20V to -10 to +10. So you want 10/3 = 3.33 volts at the negative input.


schematic


simulate this circuit – Schematic created using CircuitLab



At the point I marked 3.333V, for a standard non-inverting op-amp configuration, that point would be GND. But you want to add the negative input's gain to the output too, so you need 3.333V there.


The LM324 will work fine,but it's not a precision opamp and has some significant input offsets itself, and you might lose precision of the DAC input, but it can be trimmed out if you need to. If you don't want to trim anything then you can use a precision opamp with good DC characteristics.


components - MC68000 Modern Equivalent (or can/should I use NRND/EOL chips)


I am designing a SBC that will feature the Motorola 68000 (or one of its descendants) but am having trouble finding new chips. The only chips that I have been able to find on Mouser or Digi-Key are the MC68SEC000AA10 and MC68SEC000AA16, both of which are NRND.



My questions are as follows:
1. Is there a modern (and non NRND) replacement for the MC68000? If so, what is it. 2. Should I (as a hobbyist) even worry about NRND/EOL parts for a system that I will build (at most) a handful of?



Answer



The natural successor of the 68000 range of CPUs are the ColdFire microcontrollers designed for embedded platforms. They have sort of the same ISA, but some instructions are removed and some have been added. This means that they are mostly binary compatible, at least in user mode, but some instructions have to be trapped and emulated if you want to run completely unmodified 68000-code. The removed instructions are notably a lot of the byte/word addressing modes, meaning that it is more focused on 32-bit applications. They also have some very nice new instructions, for example the EMAC unit for doing DSP operations.


It is unclear to me what you mean to be the difference between an MPU and an MCU. I assume you mean that you want to attach external RAM, which is certainly possible with a lot of the ColdFire MPUs and MCUs. There are too many devices to list here, and you haven't given much to filter on, so you just have to search for a device that suits your needs.


I'm currently designing a computer based on the MC68060 CPU, long gone. I expect to source the few I need on the second hand market. If you're just building a handful, I don't see why you should worry about ICs which are marked end-of-life.


digital logic - How is 'specific' data found and taken from a Semiconductor Memory Source?


In a semiconductor memory chip, each bit of binary data is stored in a tiny circuit called a memory cell consisting of one to several transistors. Volatile type.


Suppose an application stored its data in a particular segment on the computers RAM.


How would the CPU know what data to extract and how would it sort through the other data to get to it. If everything in its core level is 0 or 1 its hard to distinguish what purpose 'x' memory has.



Answer



Typically, a memory is controlled by several address inputs, as well as a read/write control signal and some inputs that control when the read or write operation should occur.


Given n address inputs, 2n locations in the memory can be distinguished. These are the "specific" locations that the computer is able to access. Usually each location contains more than one bit. It could be a byte (8 bits, or memory cells), or a multi-byte word, which could be 16, 32, or 64 bits wide.


If you have a megabyte of memory, with single-byte access, you will need 20 address bits (individual input signals) to control it. For a gigabyte of memory, you would need 30 address bits.




How would the CPU know what data to extract and how would it sort through the other data to get to it?



Generally it's up to the programmer (if using assembly language) or the compiler (when using a higher-level language) to keep track of what data is stored at what address.


For example, if you write a C program with a global variable x, then the compiler will decide what location to store it at, and take care of generating instructions that access that location whenever your program needs to use x.


If you create a local variable y within a function, the compiler will actually keep track of that variable relative to the value held in a special register called the stack pointer (SP). Each time the function is called, SP might hold a different value. But y will be created anew with each call and stored at the same offset from SP (which is kept track of by the compiler and generally not seen by the programmer).


A third possibility is heap allocation. Meaning the storage space is allocated from a "heap" of available memory. In some languages (Java, for example) the compiler might do most of the work of tracking heap memory. In C, the programmer is responsible for keeping track of heap memory. This is done with pointer variables, which basically encode the address where the program should access to get that particular data.


led - Constructing a simple emergency light kit


This is my first adventure in the electronics world and, as I'm a CS student, you can expect a lot of associations that maybe aren't that right.


The main feature of my circuit is:


If there isn't energy coming from the transformer (220v to 9v), turn on the leds (using a 6v battery), else, let the leds off.


Recently I met transistors and it seems to me that a pnp transistor would do the job. You can see a diagram that I'm going to use to explain what I thought (to make it simple, I'm not showing the transformer and the rectifier bridge):



enter image description here


So, if there isn't energy coming from the transformer part and, as I'm (trying to, actually) reducing the voltage from the battery in the base of the TIP127. The voltage in the base will be lower than the emitter, which will turn the leds on.


Doubt



  • Unfortunately, I discovered that the idea of using a resistor to reduce the voltage from the battery won't work. Do you have any suggestion to put me in the right direction?


This is my first circuit. I'm pretty sure that it have a lot of design problems. Any kind of suggestion or critic will be appreciated!



Answer



For your first circuit, you did pretty good. However, as it is, the left side of the circuit is not electrically connected to the right side of the circuit (using the transistor base as the dividing line). They need to share a ground connection, or they will not interact appropriately. The negative terminal of the battery should be connected to the common return of the transformer circuit (the 9V side).


Secondly, you are using a PNP BJT. This type of transistor is current controlled, meaning you typically need a resistor connecting the voltage source to the transistor base to control the current - a 1k resistor is appropriate here. Also, you are right in thinking that a LO voltage would saturate the PNP transistor to turn it on; however, you have it "pulled high" with the resistor R2. So if the main power goes out, the base will be pulled HI by R2 because I'm not sure as though the main power going off will do anything to the transistor. Lack of power does not usually equal zero volts; more commonly it equals high impedance. You should use R2 to pull the transistor base LO to the negative battery terminal - a 10k or even 100k resistor is more appropriate here. That way, when the main power is ON, the base will see the 9V (through a 1k resistor) and be OFF. When the power goes out, the "weak pull down resistor" R2 will pull the base LO, turning the transistor ON. More commonly, you would do as you did - use R2 to pull the base up to ensure it is turned off. To turn it on, you would connect it directly to 0V, but you aren't doing that.



Lastly, I know you purposely didn't show it, but if you are using a transformer and a bridge rectifier, this will convert the AC voltage to a pulse, not a DC voltage. It will also need a capacitor to smooth the pulse out. Otherwise, the voltage will still be returning to 0 with every cycle of the AC line, hence, the circuit would pulse on and off repeatedly (50 or 60Hz, depending on your main power frequency) - seen as the LED on, but dimmed. This is explained well in the other answer.


Be careful with that high of a power source - it can really do some damage to you! Otherwise, the best way for you to learn how these things work is to play around with the circuit. If something doesn't work quite right, turn off the power, move a resistor somewhere else or replace it with a different value, and turn it back on to see if it does what you want it to do. Have fun with it!


Industrial construction of pn-junction diodes?


I was just doing a project for a website and my team member excavated a standard pn-junction diode to see that inside the ceramic casing, the semiconductors of p and n doping merely abut together in close alignment. Shouldn't the case be that a single length is variably doped with n and p type impurities to form the junction? If I remember correctly, then textbooks tell that simply joining the two by their boundary does not make it a p-n junction since there are always irregularities on microscopic scale. Any insights on this?




Monday 27 May 2019

Why change microcontroller's PWM frequency?


What are exactly the pros/cons of changing the PWM frequency?


I don't think I need to change any PWM frequency at this very moment - but since I don't know the benefits of doing it, how can I really know if it's useful for me?


I'd like a general answer (which I and other people reading this post can apply in different situations), but if someone wants some data to answer, here are those of the project I'm working on at the moment:



  • ATmega328 microcnotroller @16Mhz (it stands alone, it's not in an Arduino board)

  • 4 independent small brushed motors, each with a propeller (propeller's diameter: around 6 cm), on pins 3,5,6,11, controlled by a BUK9840-55 trasnsistor (datasheet)

  • a simple RF receiver is placed nearby and needs to receive a 433MHz signal (the RF comminication is quite slow (500bits/sec), and doesn't need to be very reliable).


EDIT: how does the PWM speed influence the RF communication?




Answer



PWM units, typically, work the following way, or equivalent¹.


Set up:



  1. an initial output value, ie. either high or low and

  2. the "counter reset value", to which the counter is reset after reaching

  3. the "counter maximum value", as well as

  4. the "counter flip value", where the output state is toggled


After that, you just let the counter run – for example, you might set




  • initial state high,

  • reset value 0,

  • max value 100,

  • flip threshold 25


Then your counter would start at 0, and increment once every clock cycle, and at 25, the output would be set to low, until the counter reaches 100 and is reset to 0. That way, the output would be high for 25 time units, and low for 75 – a duty cycle of \$\frac14=25\%\$.


Now, the PWM frequency is typically defined as the time between the reset and reaching the maximum.


So, this inherently is one aspect of choosing a PWM frequency: if there's 100 time units (which, by the way, are typically clock ticks of something like the CPU clock divided by some \$N\$), your duty cycle "granularity" cannot be better than 1%.


On the other hand, if you let's say set the max value to 106, then you might get super nice resolution on the duty cycle, but that doesn't help you, because now the output might be low and high for so long that whatever you drive with the PWM simply sees "on" and "off", unless you go through great lengths (build a mechanically large low-pass filter) to "smoothen" things out, and then you'd lose all ability to quickly adjust the duty cycle (because the filter will also smoothen out your adjusting).



PWMs are used for very different things – for example, to generate an analog voltage, as mentioned above, by low-pass filtering. In that case, using a high frequency might be beneficial, because your low-pass filter, needing to cut off the PWM frequency, is much easier to build when that frequency is high. On the other hand, in circuits where you work with sensitive analog voltages, having a fastly switching PWM signal is dangerous, due to that signal potentially coupling over.


Other uses are, and that's probably what your motor does internally, more digital: the PWM simply controls for how long something is switched on or off, for example, the internal power supply in DC brushless motors (which are, in fact, 3-phase AC motors that have a supply that generates three sine signals from the DC voltage it takes). For these applications, as said, the PWM frequency mustn't be too low, because then your motor will stop, start, stop,…, but it mustn't be higher than the frequencies the internal supply uses to generate the AC voltages.


Yet other uses are actually signal generation usages – for example, assume you have a microcontroller with a CPU clock of 16 MHz, and you want to generate a set of different frequencies (for example, you have a Modem that uses frequency shifting as modulation, so one frequency means "0", the other one means "1") – in that application, you might use a fixed duty cycle, and what you're really interested in is the PWM frequency!


There's also devices that communicate measurement values by PWM duty cycle – or take PWM duty cycle as input, for example these "neopixels" that you might have heard of. Of course, their interface controller has a specific timing range, so you have to configure your PWM frequency to make things work.




¹ this, for example, assumes you can both set the upper and lower limit, and that the counter counts up – there's no reason that all of that is true, you can implement PWM by counting down, or by not having a variable upper limit, but that's details.

serial - Is it possible to send AT commands through TCP?


I have a SIM900 GSM/GPRS device, I can send AT commands through HyperTerminal and everything is fine. I can configure GPRS connection through AT commands:


AT+CGATT=1
AT+CIPMUX=0
AT+CSTT="INTERNET","",""
AT+CIICR
AT+CIFSR
AT+CIPSTART="TCP","IP","PORT"

With these configuration I can make it connect my PC (using port forwarding on the home router). I created a TCP server in C# and the server accepted the TCP connection from the device. My question is, is it possible to send AT commands through TCP and execute them ? The server sends AT commands to the device and they are received but as data not commands.





pic - magnetics for ethernet PIC18f


I need to add ethernet connectivity to a PIC18f66j60.


The datasheets tells about magnetics. But I know only very little about that.


Do you know any surface-mount magnetics suitable for this use ?


I look for external magnetics. MagJacks are not an option.


Thanks



PIC18f ethernet magnetics schematics PIC18f ethernet magnetics requirements


EDIT :


I've found a lot of parts such as H1102 or H2019, but they feature a kind of coil beetwen the two output pins. Will that work ?


H1102 internals



Answer



I have used the H2019 in the past. Here is a snippet of a schematic of it connected to a PIC and a RJ45 jack:



voltage - Series vs Parallel termination load for transmission lines


I have a source with 5V 10Mhz Squarewave output, then I have an OR logic gate then 20m coaxial cable and then I have another OR logic gate. I guess I will need a matched load (now it is 100Ohm (random resistance)) for this system. Should I add the termination load in series or using voltage divider?


I must note - I do not need any numbers, I am just curious about pros and cons in the two following systems.


Here is the updated picture. Coaxial cable: 20m, 50Ohm Voltage Source: 5V, 10Mhz, Square Wave


enter image description here


enter image description here



Answer




I would series terminate the line assuming the receiving end is a single receiver, if its hitting multiple devices you basically have to end terminate.


Your source resistor should be output_impedance + R = Transmission_line_impedance. You may need to fiddle with this as your going to have to compensate for impedance changes caused by the connectors, etc. Side note, are you sure your logic gate can drive this load? Most can't, you may need a line driver on the sending side.


As for your pictorial end termination, its not correct. That resistor should be as close to the receiver as possible, you should also consider Thevenin termination as it uses much less power than the parallel termination.


In general (this can vary a bit by application):


Source Termination: Lowest power, slowest rise/fall times, single destination only.


Parallel Termination: Highest power, only 1 resistor


Thevenin Termination: Middle power, 2 resistors


Parallel AC Termination: Middle-low power, fastest rise/fall times, 1 resistor, 1 capacitor


For most signals what i would say is this:


If its point to point and rise/fall times are not required to be especially fast (most point to point applications): source terminate



If its point to multiple point: Thevenin terminate AFTER the last device.


If rise/fall times are absolutely critical (this is fairly rarely needed): Parallel AC terminate.


If your boss is bitching about cost and your not running on batteries: Parallel terminate


Sunday 26 May 2019

MOSFET selection for 5V LED Circuit


This is a follow up question to my previous one,(Transistor selection for 5V LED circuit) where I was (kindly) guided to using a MOSFET to switch on this circuit.


My intention to switch this circuit on/off using a capacitive sensor IC such as this: http://www.mouser.com/ds/2/42/iqs904_datasheet-8785.pdf


At moment I'm still testing on the breadboard. In the diagram below I'v replaced the IC with a simple switch+resistor to represent the output of Pin 3 (presumed to be 3~5 mA @ 5v) The LEDs are 3.6v @ 20mA


The circuit now looks like this:


schematic


simulate this circuit – Schematic created using CircuitLab



I'm new to MOSFETS (and actually electronics). From a quick look around it looks like a 2N7002K would work.


Is this the correct choice?



Answer



Let's go over the main specs of the MOSFET...


Drain-Source Voltage (Vdss)=60v. You will be subjecting it to 5v, so you're good!


Gate-Source Voltage (Vgss)=20v. You're at 5v, so good.


Drain Current (Id)=300 mA continuous. You are at 100 mA (20 mA for each of the 5 LED's). Good!


Gate Threshold Voltage (Vgs(th))=1.0-2.5v. You'll be driving the gate with either 0.0v or 5.0v, so here again you are good.


I ignored some of the more esoteric specs, which could come into play if you were driving an inductive load like a motor or relay, or needing to have fast switching or high-frequency switching. But for turning some LEDs on or off, this MOSFET will be just fine.


boost - What type of voltage booster circuit is this?


I'm wanting to research the theory of operation for this type of voltage booster circuit, does this design have a particular name? Early days for me, don't yet understand difference between buck boost, flyback etc. Any help appreciated.



This particular circuit is from an old home computer that only has a single line +9V (unregulated) supply, but also requires +12V to power a couple of video ICs. This circuit takes the +9 and provides +12.


Circuit diagram



Answer



It's a non-isolating self-oscillating flyback converter.


Pin 5 from the transformer provides positive feedback to make TR106 oscillate.


When the transistor stops conducting Pin 3 goes positive, D101 conducts and charges the output capacitor, C116. L104 and the following capacitors filter the output.


When the output voltage reaches the set point (12v), zener diode ZD101 starts conducting causing TR107 to divert base current from TR106 and either stop or reduce the level of oscillation.


It is surprising that a transformer would be used for such a small step-up.


A non-isolating booster would normally use just an inductor in the collector of the main switch transistor (TR106). It is not so easy to make it self-oscillating though and would require a different arrangement.


Alternatively with the same circuit D101 could be fed from the collector of TR106 and reduce the number of windings on the transformer.



One advantage of a separate winding for the output is that in the case of a short circuit on the output the circuit stops oscillating and the fault current is low. With the conventional step-up the short circuit current can flow directly from the incoming power supply (9V in this case) through the diode to the short.


Saturday 25 May 2019

led - Amplifying an audio signal



Preface


Essentially, I want to use the analog signal coming out of my smartphone when I play music to modulate LEDs and piezo electric elements. Initially, I thought that if the raw power output is enough to power small headphones and such, then it should be enough to make a piezo and LED do something. However, nothing happens when I plug them in.


I have two piezos which are much larger in diameter than my other ones, but they seem to work (i.e. I can hear the music, albeit it's very tinny). I guess diameter is not really a good metric though, but the one which works best has a voltage range of 3-24V, whereas the smaller one which I want to use (but isn't working) has an input range of 3-6V. I tried playing with the volume (which I imagine increases/decreases the amplitude of the signal in terms of its output voltage), but no luck.


So I need to get a piezo working, and a LED. A secondary problem I see with the LED (which is my suspicion as to why it's not working) is the fact that it can only really be on or off ... it's not an analog device. So in order for it to respond the way I want it to to my music, I think I would have to digitize the signal? Though, my signal from the mp3 player is a square wave, so in a sense it should be digital anyway.


Now, on to my question:


How can I achieve what I want (that is, to modulate a piezo and a few LEDs based on the input from my mp3 player)? I have been reading about signal processing, and it seems like I can do this analog or digital. I have a pretty good amount of experience with AVR microcontrollers and embedded systems in general, but not so much with signal processing. Would the simplest way to do this be to use an op amp? I have no problem using an external power source for the piezos and LEDs and modulating that. Or would I need to do a whole DSP thing with an ADC to DAC.


Another way to amplify the signal (even if the gain is unity, I just need to modulate these things) I found is described here using something called an "audio output transformer". I have no idea how this works, but it seems to do the job.


I know an oscilloscope would help a lot, and mine is on its way. I tried to figure out what the audio signal looks like with my multimeter, but I think the response time simply isn't good enough.




Answer



Capcom, while this isn't an odd question it is one that we are tired of answering. Please don't take this as an offence or insult. I only mean to inform you of why people are not answering it. Then, I will "somewhat" answer it! Do not let people's response to your question at all discourage you from perusing your goal.


This question, in many different forms, gets asked every couple of weeks. It has been answered, a lot. Well, the part about driving an LED with audio has been asked/answered a lot. It is also a difficult question to answer, because almost always the people who ask it are in a little over their heads. I am not saying that you are in over your head, only that most people who ask this are. So to answer this question properly, we usually have to start with the basics of electronics and audio. This takes a lot of time, and we get tired of doing it over and over for essentially the same question.


I suggest that you search for previous questions/answers for the information you need. I also suggest that you do a Google search for "color organ".


As for the piezo problem... You describe your results so far as sounding tinny. All practical piezos will sound tinny. The way you get around that is to not use a piezo. Piezos also are not very loud. Odds are that the small piezo that you used did make a sound but it was too soft to be heard. The third problem is that piezos are only good for making noise in a small frequency band, which is great for making beeps but terrible for reproducing audio.


The normal way to make a piezo work is to use some sort of amplifier. It doesn't have to be a particularly powerful amp, but the output voltage needs to be a range similar to what the piezo is expecting and the amp needs to be able to drive a capacitive load. For the most part, that means that the amp is actually a bit more powerful than what would normally be required.


But really, the best way to fix your piezo is to not use a piezo. Use a normal speaker instead. When you do that, you'll probably still need an amplifier to drive it, but there are many chips and circuits that you can find to do that. TI makes a bunch of amp chips that are easy to use.


ac - What is the Thévenin equivalent of the mains power supply?


Thévenin's theorem says that any voltage source can be modeled as an ideal source in series with some complex impedance. How does one quantify this model for AC mains supplies? What parameters are relevant? And are there any broad assumptions that can be made about these parameters on AC mains supplies worldwide?




digital logic - How to get a FPGA design that will definitely work on actual hardware


I have just started learning digital logic design with FPGA's, and have been building a lot of projects. Most of the times (since I am kind of a noob), I have a design that simulates perfectly (Behavioural simulation) but does not synthesize properly.


So, my question is "what are the design steps that I can incorporate in my workflow, that will ensure that I have a working design that will work right on my FPGA ?"



I have two main areas where I expect advise, but this is absolutely based on a very narrow viewpoint of mine as a beginner, and more are welcome :



  • What all steps (viewing RTL schematic, post synthesis simulation, ...) should I undertake learning for the best practice.

  • What all things should I keep in mind while designing my logic (say FSM's or sequential circuits) to avoid any unexpected results.


I am using a Xilinx Spartan 6 FPGA, and Xilinx ISE Design suite for my work.




power supply - How to improve load transient response of an LM317 voltage-regulator powering an audio amplifier?


I am building a voltage regulator circuit for powering a pair of mini-speakers (about 3-5W) with built in amplifier and an old mp3-player/FM radio. The power source is an old mobile phone charger (switching PSU) with a no-load DC voltage of 7.3V, which is regulated to 4.2V by the LM317. I use the standard circuit exactly as recommended by the TI datasheet:


enter image description here


Besides the 2 resistors there are three capacitors, Cadj = 10uF, Co = 1uF electrolytic, Ci = 0.1uF ceramic.



The circuit works OK, noise levels are low. However, using an oscilloscope in AC coupling mode and testing the regulated voltage output by actually playing back music on the system, I see a significant variation in voltage that follows the audio signal’s transients. A kickdrum can drop the voltage by around 0.5V (i.e. about 12% of Vs) and I'm measuring peak-to-peak voltages of around 1V (24% of Vs). Adding a 1000uF electrolytic cap on the input side in parallel with Ci reduces peak-to-peak voltage swings drastically, to about 200 mV. Subjectively, the basses also sound fuller and deeper if I add this large capacitor.


My questions are the following:




  1. Is it correct to assume that an ideal (theoretical) PSU for audio applications should produce a constant voltage regardless of load variations (i.e. it is a voltage source)?




  2. In practice, what are acceptable levels of supply voltage variation due to transients in an audio application (in percentage of Vs or mV)?





  3. What is the correct approach to improve load transient response? Should I place a capacitor on the INPUT or OUTPUT of the regulator? Is there a rule of thumb/calculation for the required capacitance? Are electrolytic capacitors OK, or should I use polyester or tantalum caps (i.e. something with a lower ESR)?




UPDATE:


Regarding the input and output capacitors I found the following info on some hi-fi audio blogs and forums:




  • Large caps are recommended on the input for amplifier voltage regulators, i've seen LM317 schematics with around 2000uF and upwards. Cadj could also be somewhat larger for extra noise suppression (someone recommended 20uF or even 100uF).





  • The output capacitor should not be overly large, as this can cause stability issues with the LM317, however it could be higher than the 1uF in the datasheet (I've seen 100uF, someone stated that he uses 1000uF, however with a 0.33ohm series resistor for increasing ESR, see below).




  • The output and adjust caps should have a high ESR (i.e. they should be electrolytic caps, not polypropylene or tantalum ones), because low ESR caps introduce ringing, possibly in the audible range. Larger caps have lower ESR, so this consideration limits the size of the output cap. A possible solution to this problem is adding a small (0.2-0.3ohm) resistor in series with the caps to compensate for the lower ESR of larger caps.




  • If using higher Cadj and Cout caps, protection diodes D1 and D2 are strongly recommended to discharge the caps when powering off.




  • The issue described in my question (large transient voltage drops) was in part caused by transient voltage drops on the PSU, rather than the regulator circuit as pointed out by Peter Bennett. The regulator's input voltage fell a few hundred mV below the necessary input of the LM317 (Vout + 2.5V). These transient drops did not show up on the multimeter, but a scope revealed them:





transient voltage drops on a scope


Replacing the PSU with another unit that stays well above Vout + 3V still results in some transients on the regulated output, however the voltage drops are much smaller (60-90mV compared to 200-700mV). Replacing the 1000 uF input cap with 2x 2200 uF did reduce the transients further, but only by a fraction (to about 70 mV from 90 mV). Subjectively this 2% voltage fluctuation is not very noticable on this small amplifier so I consider this problem solved.




Friday 24 May 2019

switches - can you explain me the working of this circuit in detail?



reed switch(occupancy light) this circuit is a occupancy light circuit i want to know the working of the transistor regarding base,collector and emitter in the transitor



Answer




You really should use component designators in your schematics. Lack of them makes it more difficult to talk about the circuit, so I'll be more brief.


Consider what happens when the reed switch is open. The first transistor is on, lighting the first LED. The collector being low also turns off the second transistor, which keeps the second LED off.


When the reed switch is closed, the first transistor is forced off, so the first LED will be off too. The second transistor is then turned on, which lights the second LED.



In summary, one LED is always lit. The reed switch state governs which one.


electricity - What happens if we connect a led to a monopole antenna?(on a transmitting antenna)


To my understanding, electrons flows towards a lower potential so if current(oscillating) flows through a monopole antenna does it mean we can connect a led anywhere on the antenna and get it to blink ?


my question is about a transmitting monopole antenna, since i find it difficult to understand how current can flow when nothing is connected at the end of the antenna.



Answer



A diode attached to an antenna plus tuned LC circuit is the basis of the simplest possible radio: http://sci-toys.com/scitoys/scitoys/radio/homemade_radio.html


But the amount of energy available is tiny. It wouldn't be a visible glow, it would be at best something that you could just about detect with sensitive instruments.


Edit: OK, a transmitting antenna! My antenna theory is a little rusty, but I think the best way is to start by understanding a transmission line. Wires are not the simple objects of pure theory; between every conductor and the corresponding ground is a capacitance. We can consider the capacitance divided into little pieces for each corresponding tiny piece of wire segment. When a changing signal enters a wire, it has to fill up all the little capacitances along the way.


The antenna connected to an AC signal has a electric field wavefront travelling up it; when the wave enters it doesn't "know" that there's nothing on the end of the antenna. It reflects off the end of the antenna, and then if the antenna is designed correctly forms a standing wave in the antenna.


So what happens if you stick an LED in the way? I think the diode property stops this working, because it only allows current flow in one direction. You charge up the (tiny) capacitance of the antenna, and then it's full and no more current will flow at that voltage.


power - Isolation provided by transformers


I have a few questions about transformers and isolation. I will describe my understanding (maybe wrong) and questions about them.



  • Transformers provide safe isolation by disconnecting two circuits electrically. So now instead of touching one hot wire on the isolated circuit, you must touch both to get shocked.


  • Why don't my wall outlets work this way? I know there are many transformers used in the power distribution network. Is this because they are referenced to ground (with a center tap or something)?

  • If the power lines are referenced to ground, why? Wouldn't it be safer to keep the power lines floating w.r.t. ground, so that for a shock to occur a person would have to touch two wires?

  • Could I provide this protection at my home by putting a 1:1 isolation transformer between the power grid and my house?



Answer




Could I provide this protection at my home by putting a 1:1 isolation transformer between the power grid and my house?



Consider these scenarios: -




  • If one wire (called neutral) is earthy, then touching the live side will give a shock but, that shock isn't going to push hundreds of mA through you and kill or burn you.

  • If you touch live and neutral together then that is going to push potentially hundreds of mA through you and give burns or worse.



Transformers provide safe isolation by disconnecting two circuits electrically. So now instead of touching one hot wire on the isolated circuit, you must touch both to get shocked.



Consider the relative benefits of scenario 1 and the advent of the earth leakage circuit breaker. If a current is taken from the live wire through your body to earth that current does not flow down the neutral wire and this can be detected at a low level and trip a circuit breaker.


Modern devices use residual current devices (UK) or ground fault circuit interrupters (in the US). All developed countries use something. So, the RCD passes live and neutral through a magnetic core and the resultant flux in that core is zero because, under normal load conditions live current and neutral current are equal and opposite.


A detection coil (also on the core) generates a signal to trip the breaker if the difference between live and neutral currents is ~30 mA. It trips fairly quickly so if you touch live in a meaningful way, within a few tens of milliseconds, the circuit is rendered safe: -


enter image description here



Without having neutral connected to earth there is no intermediate semi-safe method of preventing full circuit contact and a much higher risk to health.


Thursday 23 May 2019

led - Make adjustable mosfet constant current source


I want to modify this circuit below so the current can be trimmed.


The problem is the variations in base-emitter voltage of the NPN transistor. According to datasheets, it is between 0.55V and 0.7V with a collector-emitter current of 2mA. I need to trim the current through the LEDs to 0.35A, using a potentiometer of 100 ohms or greater.


How could I modify this circuit? The supply will be well regulated.


schematic



simulate this circuit – Schematic created using CircuitLab


Thanks



Answer



Do you have enough headroom to increase the current sensing resistor slightly an drive the BJT from a potmeter in parallel?


schematic


Of course you could optimize R3 to a series of resistors with ratios 270:100:180, where 270 is near ground, 100 is your pot and 180 at source.


switches - Is there a better way to plan a circuit to square a 3 bits binary number?


I need to plan a circuit that will square a 3 bit binary number: $$\{Y_2, Y_1, Y_0\} \rightarrow \{S_5,S_4,S_3,S_2,S_1,S_0\} $$



I thought of the common way we multiply numbers and used it to plan the circuit (as you can see in the top left of the attached picture)


circut


What do you think? Is there a better way to do the following using the basic gates, FA, HA and MUX?



Answer



Of course there is.


First we write out the truth table:


 Y    S
000 000000
001 000001
010 000100

011 001001
100 010000
101 011001
110 100100
111 110001

We notice right away that S0 = Y0, S1 = 0, and S5 = Y1 * Y2. Let's remove those.


 Y   S
210 432
000 000

001 000
010 001
011 010
100 100
101 110
110 001
111 100

And now we see that S2 = Y1 * !Y0, S3 = Y0 * (Y1 ^ Y2), and S4 = Y2 * (!Y1 + Y0) = Y2 * !S2. Since you now have all 6 equations for the bits in S, building a logic circuit for it is easy, and left as an exercise for the reader.


switch mode power supply - modify 30W LED driver for variable current output


I have a typical flyback converter for an LED chip rated at 30W output.


My goal is to change the brightness of the LEDs using a microcontroller.



If I am not mistaken (please correct me if I am wrong):



  • The white SMD part on the right side on the picture is also a resistor.
    I have measured the resistance to GND and measured 0.4 Ohm in total (13 Ohm || to the white resistor). The measurement was taken using a battery and another transistor. The current was 83mA and the voltage drop 32mV. The 13 Ohm -- through hole -- resistor is behind the capacitor in the image. Is the 13 Ohm resistor really for fine tuning the resistance?

  • There is no voltage sense like in the FL7732 circuit. The transformer loop is only used to power the chip. (Why is the RS1M diode so big? It should only power the IC.)

  • Using PWM on the output will not work, as the driver will try to output ~1A. The LEDs would get a much higher current when the PWM turns them on, and the current would on average be the same.


Assuming that the switching frequency is high enough I could simply PWM the signal to the FET.


If this is not possible my idea would be to replace the sense resistor with an analog switch, but this other question was unsuccessful in this regard.


Is there an easy way to achieve what I want? How is this usually implemented?



Here is my reverse engineered circuit (the capacitor with the question mark in || to the 13 Ohm resistor is probably also a resistor): enter image description here


Here is a very similar circuit from an FL7732 application note, which is probably much easier to read: enter image description here


Here is a picture of the LED driver: enter image description here


EDIT: I would like to point out, that the IC used in the driver is not an FL7732. The FL7732 circuit is simply very similar. (Not that I think that the used IC behaves differently.)


Apparently changing the current isn't as simple as I thought. I guess it's easier to switch between different drivers with different output ratings than to modify an existing driver.



Answer



I don't think the schematic from the application note is intended for high power LED driving. Usually for LED driving, this is done with a power converter configured as a constant current source.


Depending on your experience with power electronics, I'd caution you moving forward with this circuit. There are a couple things you'll need to think through before you even do this:



  • You'll want an isolated power source of some sort so you're not directly connected to mains for safety purposes and measurement (unless you have differential probes)


  • Do you need the isolation that the flyback provides? There are boost converters that are specifically made for constant current driving LEDs with a CTRL pin for dimming. You could have your microcontroller interface with a DAC and drive this pin.

  • If you do need isolation, you could always take the output of your circuit and connect it to the input of an LED driver designed for this type of circuit.


Example LED Driver (Boost Converter)


enter image description here


Here is the LED current vs. CTRL voltage I was talking about.


If you are set on using this circuit, then you can read this paper on implementing a constant current source:


https://www.fairchildsemi.com/technical-articles/Low-Cost-Isolated-Current-Source-for-LED-Strings.pdf


I think you'll realize quickly that it's not going to be as simple as you thought.


transistors - H-Bridge with emitter followers


I am currently reverse engineering a circuit which requires controlling of a magnetic field. For that, the circuit has a pair of D882 and B772 each. The PCB traces suggest that the transistors are arranged as shown in the picture below: Transistor arrangement This arrangement does not make any sense at all for me. Wouldn't applying a voltage to any of the control signals result in current through both transistors rather than through the coils?




Answer



That is called an "H-Bridge."


It is often used to drive motors forwards as well as backwards.


In your case, it allows you to generate a magnetic field whose polarity and intensity you can vary using "control signal 1" and "control signal 2."


When both are high (or both are low,) no current flows through the coil.


If one is high and the other is low, then current will flow in a particular direction.


If you swap the high and lows, it will flow in the opposite direction.


Now, if you hold one steady and pulse the other you will get a pulsed current through the coil. It will be smoothed (somewhat) by the coil to a steady magnetic field whose strength is propotional to the duty cycle of the pulses.


Switching the polarity of the current also changes the polarity of the magnetic field.





That is very much a simplified description, but I think it contains enough key words that you should be able to locate more details on your own.


It is a common circuit with many uses - and plenty of tricks and traps that go into making, using, and controlling it.




A bit more on how it operates:


The key to the whole thing is how pnp and npn transistors function.


When the voltage on the base of an npn transistor is more than 0.7 volts above the voltage on the emitter, then current will flow through the collector to the emitter.


When the voltage on the base of a pnp transistor is more than 0.7 volts below the voltage on the collector, then current will flow through the collector to the emitter.


So, looking at the H-bridge, putting a high signal on one of the control signals will turn off the pnp and turn on the npn - that side of the bridge is connected to the positive supply voltage.


Now, if you put a low signal on the other control line the npn transistor will turn off and the pnp will turn on. That side of the bridge is connected to the ground.


Current can now flow from V+ on one side of the bridge, through the coils, to ground on the other side of the bridge.



So, which control signal is high and which is low dictates the direction of the current flow through the load in the middle of the bridge.




You also asked it is possible for both transistors on one side to turn on and cause a short circuit.


It can happen, and is called shoot through. Part of the design and operation of an H-bridge goes into making sure that it doesn't happen.


In the design you've posted, I don't think it can happen.


It looks to me like the transistors on each side can never be on at the same time. But, I'm not an engineer and may well have overseen something (though Tony is an engineer and doesn't think it can happen with this circuit.)


terminology - What is the name of the sensor that most inkjet printers use to keep track of the print head's position?


I've been trying to build a cheap X-Y-Z table using mainly bits of old CD drives and printers I've got lying around. Since the printers already have a good single axis I would like to be able to, rather than having to buy a stepper motor and rebuild it, just repurpose the optical tabe the printer uses to keep track of the print head's position and keep the same DC motor. I've been able to extract the sensor the printer uses without damaging it or any part of the track, but I've been unable to find what the proper name of this sensor is, let alone documentation describing how to use it.


The sensor in question is in a black, plastic housing with a slit that the tape fits into. There are six pins on its underside that solder to the board, two of which come from something on top of the slit and four from something underneath. The black housing is labeled '6536' on top and '15' and 'DSO' underneath. My first guess is that the top is an LED while the bottom is a light sensor of some kind, but beyond basic checks (applying a weak current through the possible LED in either direction did not cause it to noticeably light up) I'm not sure how to get any more information out of it safely.



Answer



It sounds to me like an optical encoder, which looks something like this:


enter image description here



One side is an infrared emitter (which is why you can't see it--Infrared light is not visible to the naked eye) and the other side is the infrared receiver. The tape has very small stripes on it, through which light cannot pass. When this stripe blocks the IR light from the emitter, the receiver does not see it. When the tape continues to move, the clear portion of the tape eventually passes through. The light is then seen by the IR receiver, and the circuit can tell that the tape has moved.


I would expect the two-lead part to be the emitter and the 4-lead part to be the receiver.


Wednesday 22 May 2019

led - Not understanding Forward Voltage and Voltage Drop



I have a simple circuit:


+12V -- R1 -- LED1 -- LED2 -- LED3 -- ground


Falstad simulation link


If the Forward Voltage of an LED is 3V, and the Forward Current is 20mA, I can (I believe) calculate the required resistance of the resistor as (12V - (3 * 3V)) / 0.02A = 150Ω.


From what I understand, that should give me a Voltage Drop of 3V over the resistor and each LED respectively, and a current of 20mA through the circuit - perfect.


In the simulation of this circuit, I get a Voltage Drop of 4.01V, 2.66V, 2.66V, 2.66V respectively, and a current of 26.74mA through the circuit, which is too high for the LEDs.


This makes me think that I don't understand the relationship between Forward Voltage and Voltage Drop, and therefore, how am I supposed to calculate a correct resistor value that won't burn out the LEDs?


Apologies if this is asked a lot or is really simple, but I've been searching for ages and haven't come up with anything.



Answer



For your simulation, you specify the led's forward voltage as "3V at 1A". This means the forward voltage of the leds at about 20mA will be much lower.



Everything is right there, you just need to read the leds datasheet to find the forward voltage at arount 20mA.


digital logic - Construct an 8k X 32 ROM using 2k X 8 ROM chips


Construct an 8k X 32 ROM using 2k X 8 ROM chips and any additional required components. Show how the address and data lines of the constructed 8k X 32 ROM are connected to the 2k X 8 chips.


I tried to solve it but I am not sure if I got the correct answer. Could anyone check my drawing and correct me?



enter image description here




Tuesday 21 May 2019

pcb design - Warming PCB in a low temperature environment


I have to develop a microcontroller circuit that will run at low temperatures (as low as -60C). I want to heat the FR4 PCB board until it reaches the commercial temperature range above -40C. I found some flexi heaters to heat the PCB. What other options do I have? Is it possible to use a PCB layer as heater? I couldn't find any information about using a layer as a heater.



Answer



I would be inclined to use traces on or in the PCB as a direct heater, as you suggest. Obviously, you'd start by insulating the board as much as possible to minimize the energy required to maintain temperature. Pay particular attention to external electrical connections, which can also be good conductors of heat. Extra lengths of wire buried in the insulation will help quite a bit.


I would put the trace(s) mostly around the edge of the board, generally keeping them away from other heat-producing components in order to keep temperature gradients across the board to a minimum. I would design a current source that has temperature feedback to drive the trace, with a "maximum" setting that's guaranteed not to burn it out.


The flexi heaters you found are essentially doing the same thing, but they probably consider the applications data somewhat proprietary. You'll have to work out the details yourself; things like trace widths and thicknesses, current levels and temperature rise, based on the basic resistivity of copper, which is 1.68×10-8 Ω-m @ 20°C.


msp430 - Is it possible to drive 4 seven segment display with MSP430G2231?



I'm trying to teach myself electronics and my goal is to create a digital clock with 4 digits.


I have an MSP430G2231 which has only 8 available ports as far as I can tell.


I saw some methods for driving multiple seven segment displays, like using a multiplexer or transistors. But it doesn't seem possible with MSP430G2231 because of it's lack of ports.


Am I wrong? Or could it be done? If yes, how?



Answer



Like Leon says you can use an I/O expander, or even better a LED display driver. In the past I've used the MAX7219, but this is a 5V device, for 3.3V you have to go to MAX6950. This can drive up to five 7-segment digits (the 6951 can do 8), so that may be suitable for your clock. It's controlled via SPI, so you only need 3 I/O pin of your controller. The driver does the multiplexing for you, has a BCD to 7-segment decoder and you can control brightness via software. One minor issue may be the package. The 7219 was available in DIL, but the 6950 only comes in a 0.635 mm pitch TSOP.


enter image description here


You say you don't want a crystal (why not?). For a clock you normally would use a crystal to get the required accuracy. But you can also work with the mains frequency, which over long term like months is even more accurate.


edit
Leon rightly remarks on the high price for the MAX6950. The MAX7219 is more affordable, but like I said it's a 5V device. Since you only need 3 lines to drive it you could easily add a few level shifters. A transistor will suffice, at least if you don't mind bit-banging the SPI (because it inverts the signal). If you want to use the on-chip SPI you need a non-inverting level shifter, like the FXL4T245 (difficult package though).



Alternatively, just buy an MSP430 with more I/O pins :-)


digital logic - Square wave generator has nigh-useless output


I have a system that was designed for testing digital components. I have a device in the system which is used for generation and acquisition of digital signals. Now, I will happily admit to not fully understanding everything I'm about to say, but:




  • The outputs of the device have a 50Ω nominal impedance,

  • The cable carrying these signals is a 50Ω cable designed for the device,

  • The PCB the cable is plugged into is supposed to use 50Ω characteristic impedance on the lines with length matching to 0.5" and signals routed on the same layer.


For clarity: the output of the device is sent through a cable, which is attached to a PCB, where the signals are routed a short distance to a high pin-count connector. I am trying to see how high of a frequency I can reasonably generate with this device, so I started with the default for the software I have: 50MHz. And the signal looked like this:


50MHz digital signal


When I slowed down the signal to 1MHz to get a closer look at the transition, I got this:


1MHz digital signal


I believe that I'm following the instructions in the device's specification sheet correctly...50Ω cable (designed for the device), 50Ω traces on the PCB (if the company who designed the PCB did what they said they did), into a high-impedance load (my scope).


I suppose my question is this: am I measuring the signal wrong, or was the system designed wrong? Is there anything that I am grossly misunderstanding? If the system was designed wrong, are these graphs sufficient to show that or is there another measurement that would be more illustrative?



Edit: I was asked to show what the signal looks like when "properly" terminated, aka not just floating non-terminated out of the connector of my system. The process through which this signal arrives is kind of a mess (see my comments) but here's what I've got:


Terminated


Edit#2: I stuck a 50Ω resistor between the digital output I'm observing and the ground that the signal is referenced to and I got the following output. From my understanding of this conversation, this seems to not be what I would have expected.


Terminated 50Ω to ground


Edit#3: See The Photon's accepted answer, but here's what the signal looked like after I removed a long, unterminated cable that was essentially dangling in the wind and also terminated the point I was measuring with a 50Ω resistor.


Removed cable, terminated 50Ω to ground



Answer



The plot you showed in edit #2 should only happen if there's a long "stub" somewhere hanging off your signal path. Just a wrong termination shouldn't cause this. It looks like either there's a second arm coming off the source that isn't terminated, or your probe location is in the middle of the line and the line continues quite a ways (and isn't terminated correctly) after going past the scope probe.


The step duration is about about 10 ns, indicating a stub 2.5 to 5 feet long.


After we discussed this in chat, you let me know,




So I learned two things: one, there is a pretty good digital ground plane where everything is connected so that shouldn't be much of an issue if i'm probing the connector two, there actually might be long stubs hanging off of my signal path. The [NI] digital IO card I'm using has two large sets of outputs which are brought to the PCB separately basically one connector is DATA and one connector is SENSE so on the PCB, those are two separate connectors, and they get wired together across a pretty large expanse of pcb like, 2.32 inches straight, not taking the few bends in the run into account, from the digital IO I've been measuring to the sense line it is connected to



and then later



OK, that was totally the problem. Long story short- there was totally a Y [stub].


More detail: Like I said, there was a cable for DATA, and a cable for SENSE with the lines being tied together on the PCb but since I don't really know how to use sense, or if I'll ever even really need it it was just a meter of cable running off in the opposite direction i've got 1ns rise times across a 50Ω load now and the signal even looks pretty good unterminated (or rather into high impedance)



arduino - Can I use TI'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...