Sunday 30 June 2019

power - What wattage should a headphone amp be?


I was at a local surplus store today and I got two LM386N ICs. I thought I could make a really simple headphone amp out of these. But I have no idea what the wattage of a normal headphone amp is.



These LM386 are rated 325 mW at 8 Ohm, which should be about 81.25 mW at 32 Ohm load.


Is 81.25 mW a reasonable power for a headphone amp? How does that compare to, say, a Laptop's 3.5 mm jack's power; how about an iPhone's?



Answer



Alfred already explained that for a voltage source (which an amplifier is) you'll have less power at higher impedance, because the current decreases. If your amplifier would be a current amplifier you would get a higher power, because the same current in a higher impedance will increase voltage.


Citing from this document, because I can't explain it better myself:



Headphone manufacturers specify a “sensitivity” rating for their products that is very similar to loudspeaker sensitivity ratings. For loudspeakers, the standard is to apply 1 watt and then measure the sound pressure level (SPL) at a distance of 1 meter. For headphones, the standard is to apply 1 milliwatt (1 mW = 1/1000 of a watt) and then measure the sound pressure level at the earpiece (using a dummy head with built-in microphones). Sensitivity is then stated as the number of dB of actual sound level (SPL) produced by the headphones with 1 mW of input; headphone specifications commonly refer to this by the misleading term “dB/mW.” What they really mean is dB SPL for 1 mW input.


Think about these sensitivity definitions a moment: headphone sensitivity is rated using 1/1000 of a watt; loudspeaker sensitivity is rated using 1 watt. So a quick rule-of-thumb is that you are going to need about 1/1000 as much power to drive your headphones as to drive your loudspeakers since both of their sensitivity ratings are similar (around 90- 110 dB SPL). For example, if your hi-fi amp is rated at 65 watts, then you would need only 65 mW to drive comparable headphones. (Actually you need less than 65 mW since most people don’t listen to their loudspeakers at 1 meter.) And this is exactly what you find in hi-fi receivers—their headphone jacks typically provide only 10-20 mW of output power.


Take another moment and think about all those portable tape players. They sound great, and loud. Why, you can even hear them ten feet away as the teenage skateboarder that ran over your foot escapes.


Power output? About 12 mW.




(emphasis by me)


Thanks to marketing numbers of 100 W amplifiers most people don't realize this, but 1 W is a lot of power for a good speaker. It can give you more than 90 dB SPL at 1 m. At full power a 100 W amplifier just won't break the windows. Claiming to play 2000 W at full power in your living room is nothing to brag about: it just says that you have lousy speakers :-). 2000 W in 92 dB speakers delivers 125 dB SPL, which will turn you deaf in no time. (That may be OK, once you're deaf it also stops hurting your ears. :-)


Further reading
Understanding headphone power requirements


digital logic - What's the first step to learn Verilog coding to sort values?


I do not know how to start working on this problem. Should I first design the digital circuit of sorting? I am poor on both topic. Suppose I have four numbers R0, R1, R2, R3... What is the digital circuit for arranging these numbers in ascending order? I found a sorter circuit on the internet, but I'm not able to relate it to my problem.



enter image description here


Can anyone give me a hint regarding this?



Answer



The basic hardware sorting element is a module that has two inputs and two outputs. It contains a comparator and two multiplexers, and presents the smaller of the two inputs at one of its output ports, and the larger at the other output port.


There are many ways to use such a module to sort a list of items, with a wide range of space-vs.-time tradeoffs. At one extreme, you can build a completely combinatorial sorting network (with optional pipeline registers to increase throughput), but the resources required grows O(N2). I have implemented such a network to create a real-time median filter for high-definition video.


h bridge - 1N4007 comparable with 1N4001 diode?


I'm trying to make a bipolar H-Bridge motor driver. But instead of the mentioned diode(1N4001), I've got a 1N4007 diode. Can I use that instead?



Answer



Yes. The 1N4007 can withstand a higher reverse voltage(\$V_r\$), 1000V vs. 50V. The 1N4007 may even be a better choice, esp. if your motor is powered by a voltage near 35V. (The 1N4001 is rated for a \$V_{r(RMS)}\$ of 35V.)


While diodes like 1N400x may be well suited as freewheeling diodes in terms of voltage and current (rated at 1A), they're not exactly fast. To protect your transistors Schottky diodes would be a better choice, but they usually have limited \$V_r\$.


Here's the \$V_r\$ for the 1N400x series:



1N4001: 50V

1N4002: 100V
1N4003: 200V
1N4004: 400V
1N4005: 600V
1N4006: 800V
1N4007: 1000V



bootloader - Anyone knows how X86 platform set the PCIe bifurcation at boot up?



I got a question about the PCIe bifurcation setting when booting up in X86 system. Normally, we can set the PCIe controller to be X16, two X8, or four X4 in the UEFI shell menu. However, there is an auto detection way to do the same thing automatically. For example, if I put four X4 devices on the riser card, and put this riser card to the X16 PCIe slot, the system can automatically detect that the PCIe controller should be configured as a four X4 host controllers. Does anyone know the detail procedure to implement this function? I think it's not specified in the PCIe spec. Using PRSNT# pins hard wired to the PCH may be a way, but is there any other (or real case) way to achieve this goal? Thanks.



Answer



It depends on your processor family, but is auto configured by CFG 5/6 on i7.


This Intel video might help.


Measuring Current in Combination Circuit with a Shunt


I've done a fair bit of looking/asking around for help with this but I'm struggling to come up with an answer ....


I'd like to measure and record current in a circuit. There is a 12 VDC / 2 A power supply which provides power to two instruments. They draw 75 mA, and 640 mA at 12 V respectively. They're in parallel with the supply, like this:


enter image description here


Instrument 2 is a water pump which operates at a nominal rate of 3 L/min. However, if it gets clogged for some reason, it draws more current in order to try maintain that 3 L/min output.


SO, I would like to be able to measure and log the current supply to these devices. From my research, it appears as though a shunt is a possible option. I would place it just before the negative lead on the power supply, and record the voltage drop across it using an external DAQ device (which measures from -10 to 10 V), much like this:


enter image description here



I guess my questions are: 1) Is this the best way to solve this problem? If not, what would be a better alternative? 2) If it is a good option (or even if it isn't, maybe humour me a bit ....) what "type" of shunt should I get? Is this the right way to wire the shunt. Unfortunately, the instruments themselves cannot be re-configured.


I would be happy to provide more detail as required.




Saturday 29 June 2019

Oscilloscope probe measure squarewave


As I was trying to validate our pcb design, I measured the impedance matching on the digital transmission lines, and got stuck with the oscilloscope not showing what I expected. We are using the PicoScope 4227, but I suspect that the strange measurement is not directly related to the specific oscilloscope but more to general on how to measure digital signals.



My setup is as follow: I measure the output-pin of an FPGA with both oscilloscope input A and B.


Input A (blue) is measured using the oscilloscope probe set to x10.


Input B (red) is measured using a 50-ohm coxial cable terminated at the scope input with 50-ohm.


As you can see, Input B seems correct, no reflection ect.


But Input A (the probe) has some overshoot, and ringing.


The probe should be calibrated and valid to 250MHz, so I don't get was is wrong. ?


I suspect that the small probe-clip adds some inductance, and therefore we see the ringing. But I really don't know.


oscilloscope screenshot


EDIT After reading your answers, I walked got into our lab storage and started looking, and found a probe GND clip like the one showed in the answer below.


When I use that clip, I get the output below. Which is really a huge improvement.



enter image description here



Answer



Yep, this is typical when your ground connection is not suitable for the frequencies you're working with. You may want to use a ground spring to reduce both the inductance-related peak and the noise:


enter image description here


switch mode power supply - Switching regulator output is unstable


I have a problem in buck regulator. I'm using L4970A to make a buck regulator with a variable output that can be adjusted using a potentiometer.


Output is becoming a ramp when I set the output voltage to be above 7 V; it goes up directly and slowly goes down to 7.5 V, and repeated again.


I'm using an inductor that is larger than it should be, my calculation is about 50 to 150 uH, but I use 11 mH. Is that the problem?


This is my design, the same I saw from this application note, pg.38


This is output voltage below 7 V enter image description here


This is output voltage above 7 V enter image description here


Could you know what my problem is??? Thanks a lot!!!


Edit 1



I've changed the inductor value to 200 uH, and I tried it to supply laptop with supply input 24 V. It charged the laptop when the laptop was turned on, although the voltage is not stable when I saw it in oscilloscope, but when I turned it off, it won't charge...


Anybody could tell me why it was happen???



Answer



The large inductor value does have some design implications:




  1. It's going to make the converter tend to operate in continuous conduction mode, which has loop stability ramifications (you generally need a type-3 compensator with low gain)




  2. It's going to affect the transient response of the converter by limiting the current slew rate.





  3. Is this inductor intended to carry DC current? Such high values are common for EMI inductors, not output chokes.




If you're experimenting with a reference design, it's always recommended to start with the exact BOM that the manufacturer suggests - at least you get some assurance that the circuit will work to some degree.


Edit #1


Your input is 24V, and when you try and adjust the output higher than 7V, the controller loses regulation. The output is essentially rising up to a voltage just below the input, most likely only limited by the maximum duty cycle supported by the part. This could be for several reasons.


Your voltage feedback should be via a resistor divider from the output to ground, with the midpoint going to pin 11. The converter will regulate the output so that pin 11 is at 5.1V.


Is your clock stable? You should be able to see a clean ramp on the timing capacitor (no jitter).



Is your reference stable? The 5.1V on pin 14 should be rock-solid.


What compensation components do you have from pin 10 to ground? I would suggest removing what's there and replacing it with a fairly large capacitor (1uF ceramic), and try your experiment again. The impedance from pin 10 to ground is your loop compensation, which determines the overall stability of the converter (along with operating frequency, output RC filter and load). Since you have a radically different inductor, you'll probably need to change the compensation for stability.


cables - Which is the best, clean way to join wire together


I am installing CCTV cameras and I'm using a 3A adapter to supply power to the cameras, but I have very messy results when trying to join together very small wires with electrical tape.



Is there any clean way of doing all this? For example, how can I join together the wires of 3 power supply cables? Also, how to join the Audio/Video lead to the normal wires? I find it very hard to first cut the A/V cable and then use electrical tape to join them.


I want to make something like this, but it's not as clean. It looks messy with electrical tape.




oscillator - TUSB2046B crystal not oscillating


Further to my previous question, I also noticed that the crystal there was a 12MHz where this should have been 6MHz (due to an inventory error - the wrong part was fitted). I've removed the 12MHz crystal and fitted a 6Mhz crystal using a hot air tool but now it doesn't oscillate. It kind of looks like it's trying - the scope shows a fair bit of noise and occasional flashes of what looks like about 6MHz waves but it doesn't oscillate stably.


This is the datasheet for the 12MHz crystal that produced a stable sine wave and this is the datasheet for the 6MHz crystal that doesn't.


As far as I can see, the major difference is that the 12Mhz crystal has 40 ohm ESR while the 6MHz crystal has 80 ohm ESR. As far as I can tell, my rework hasn't damaged anything - the load caps and series resistance are still doing the right things - but it's a bit hard to tell if I've damaged the crystal or the IC.



What is my most likely problem here? Is the higher ESR of the lower-frequency crystal likely to be a problem? Or is it more likely that I have damaged a component with my rework?


The crystal has a 1.5k resistor in series with it (cribbed from the TUSB2046B reference design). I'm tempted to short this out to try to reduce the losses in the oscillator and see if that improves things - is this a useful thing to try?



Answer



ESR of 80 Ohms might ask for too much of negative resistance from the circuit, and the oscillator won't start. You might need to reduce or remove the R78 resistor.


Also keep in mind that if the hub is not connected to active host and is not enumerated, it will fall into SUSPEND mode in 3 ms time frame, and the oscillator might stop. The oscillator is usually shut down to meet low-power requirement in USB SUSPEND mode.


To get out of the SUSPEND, a simple method is just to keep the upstream D+ shorted to ground, emulating the USB_RESET bus condition. When seeing the USB_RESET on the bus, every USB device must wake up, and the oscillator should start.


Friday 28 June 2019

documentation - GPS pinning parameters


I have a Venus634LPx GPS on a breakout board from SparkFun.


The documentation is very cryptic, so I did not manage to configure it manually through the UART (although I can read data from it). Luckily, the SkyTraq GPS Viewer & Configuration program works under wine (I'm on LinuxMint):


SkyTraq GPS Viewer


I still can't figure out what the pinning parameters mean. The closest thing to an explanation I found online is in a thread from 2009:




In many applications, the position and/or velocity is represented as point on a display. To make that point appear more visually stable and/or accurate to the end user, position pinning is implemented. In position pinning the reported position will not change unless some user-defined criteria are met.


The criteria can be set in pinning parameters.



Another website, where they use GPS to build a time server (similar to my own application), says:



This is what I did to configure my module:



  • Enabled position pinning

  • Disabled all NMEA strings except for GGA, GSA, GLL and ZDA

  • Set update rate to 1Hz and output sync to UTC


  • Set baud rate to 9600 (higher is not better!)



Application Note AN0003 from SkyTraq only gives the following relevant information:


Binary command to set pinning parameters


What do these parameters mean? Is any better documentation available?



Answer



I sent an email to SkyTraq, and they replied by sending me Application Note AN0025 v5 (Uploaded with permission).


There is a slight difference from the datasheet in how this note names the parameters:




  • Pinning speed PSPEED in km/h

  • Pinning threshold PTH in s (pinning cnt in datasheet)

  • Unpinning speed UPSPEED in km/h

  • Unpinning threshold UPTH in s (unpinning cnt in datasheet)

  • Unpinning distance UPDISTANCE in m


When the speed is below PSPEED for longer than duration PTH, it enters a "position pinned state", where the GPS module is considered stationary. The reported location will not move around at all, contrary to the normal behaviour where the location jumps around in a stochastic fashion.


If there is a 3D fix, it will return to the normal "unpinned" state when the speed exceeds UPSPEED for longer than UPTH. If the fix is only 2D or intermittent, it takes longer (see pp.4–5). In either case, if the position of the GPS module has drifted by more than UPDISTANCE, it will also "unpin".


The application note says nothing about the purpose of this feature. I have an unconfirmed suspicion that pinning the location might improve the GPS time estimate on stationary devices.


Why is the earth a viable return path for power distribution?


I'm having trouble understanding why the earth is a viable fault path for electricity brought into my home. Isn't there really high resistance? I mean, it's dirt?


Also, let's say I connect the hot wire coming into my house directly to the ground wire. What is the path that the electricity takes to get back and "complete the circuit?"




voltage - Are cutoff frequencies of bandpass and bandstop filters equal?


Consider the two filter in picture


schematic


simulate this circuit – Schematic created using CircuitLab



Are the cutoff frequencies (i.e. the two frequencies at which \$V_{out}=\frac{1}{\sqrt{2}} V_{in}\$) the same for the two filters? (And therefore also the bandwidth is the same for the two filters?)




I think they should be the same since in both cases the condition \$V_{out}=\frac{1}{\sqrt{2}} V_{in}\$ reduces to


$$R^2=(\omega L-\frac{1}{\omega C})^2$$


Nevetheless it is strange that there is a frequency for which both \$V_{out}\$s taken at resistor and at LC series have the same value \$\frac{1}{\sqrt{2}} V_{in}\$.


Doesn't this violates Kirckoff voltage law? (At any time it should be \$V_{in}=V_{R}+V_{LC\ series}\$ but if \$V_{R}=V_{LC\ series}=\frac{1}{\sqrt{2}} V_{in}\$ then this is not true).


enter image description here




power - Transformer Rating Calculation


enter image description here


I am confused with the above problem. If I connect all 3 windings additively, I will get 3V1/3V2. But, I don't think there will be any change in kVA rating. It should still remain Q. The answer given in my workbook is option A. Please help me with this problem.


EDIT: It is not a homework problem. I am preparing for an exam called GATE(Graduate Aptitude Test in Engg). It is a previously asked problem in the exam.



Answer



After trying for sometime, I have figured out that the only way it makes sense is when I consider the ratings are each winding and not for the 3 phase transformer.


Each winding is rated Q kVA and V1/V2



Now when you connect three windings additively, you get a single phase transformer with rating 3V1/3V2 and 3Q kVA


Correcting for non-linear brightness in LEDs when using PWM


When driving an LED with PWM, the brightness (as I perceive it) does not scale linearly with duty cycle. The brightness is slow to ramp up, then increases exponentially with duty cycle.


Can anyone suggest a rule of thumb to use as a correction factor, or other workaround?



Answer



For 16 levels it's easy to do a simple look-up table "by hand" and convert the 4 bit value in an 8 bit value to pass to PWM controller: this is the component i've used in my FPGA led array driver. For an 8 bit level controller, you'll need at least 11-12 bit output from the look-up table.


library IEEE;
use IEEE.Std_logic_1164.all;

entity Linearize is
port ( reqlev : in std_logic_vector (3 downto 0) ;

pwmdrive : out std_logic_vector (7 downto 0) );
end Linearize;

architecture LUT of Linearize is
begin
with reqlev select
pwmdrive <= "00000000" when "0000",
"00000010" when "0001",
"00000100" when "0010",
"00000111" when "0011",

"00001011" when "0100",
"00010010" when "0101",
"00011110" when "0110",
"00101000" when "0111",
"00110010" when "1000",
"01000001" when "1001",
"01010000" when "1010",
"01100100" when "1011",
"01111101" when "1100",
"10100000" when "1101",

"11001000" when "1110",
"11111111" when "1111",
"00000000" when others;
end LUT;

4N35 opto-isolator for MIDI input does not work?


I have the following circuit which I would like to use to connect a MIDI enabled device. I am not getting any signal on pin 5, could it be because the resistor from the base to ground in too small? I am not sure how to calculate it from the datasheet.


enter image description here


Update #1


I have replaced the opto-isolator, tested the input using an LED and could see the LED light up indicating current flows in the MIDI loop. I have placed a scope probe on the output of pin 5 of the device. pin 6 is now not connected to anything. Normally (idle) the signal is pulled high, when a signal comes in the signal goes low but only down to ~2.8V which is not enough to register as a logic low.


enter image description here


Update #2


I have replaced R17 with 360 Ohm. Now the signal goes as low as 1.6V.



Update #3 - Final one


I've swapped the 360 Ohm resistor for 1K. Now the signal looks much better and it reaches almost 0V when low. It is worth mentioning the scope claims rise time of 7us and fall time of 3us (probably on the low side). Considering the MIDI freq. with about 32us per bit this is short enough not to have false readings. The MIDI signal goes to an Atmel AVR and from testing I did right now it seems the messages are going through clearly. I agree that this is not the optimal device for this task though, and the circuit one would make for it (if he desires) looks very similar to what is contained by the PC900 optocoupler from Sharp.


enter image description here




Thursday 27 June 2019

coupling - Can people act like antennas?


I was watching my oscilloscope as I was holding a very short wire attached to the probe. It was showing about 0 voltage (small spikes) until I touched the metal. When I touched the metal, the scope immediately showed a 60.0Hz (peroid of 16.66ms), approximately sinusoidal (very noisy) waveform. Considering that the power in my area is a 60Hz AC, I think it most likely that it was picking up coupling from the power lines. This sine wave was immediately replaced with a flat, -200mV line when I touched an electrical ground, but resumed when I let go.


Was I acting as an antenna for electrical noise from the mains line? I was wearing rubber shoes on a concrete floor and touching nothing but the probe.



Answer




Antennas are usually thought of as converting a radio wave into an electrical signal. I say this because you wouldn't name the plates of a capacitor as antennas. Capacitive coupling (not EM antenna reception) is the phenomena you witnessed when you touched the o-scope probe.


You might have heard about fluorescent lamps lighting up when pointed at overhead wires: -


enter image description here


The alternating electric field produced by the overhead lines cause a small current to flow through the lamps and light them - this is the same principle involved when touching the scope probe. Picture taken from here. If there were an earthed shield above the tops of the tubes and below the overhead wires, those lamps would not illuminate.


Your body has a large surface area and this massively increased the capacitance between probe tip and the local conductors supplying over one hundred volts RMS around your building.


When you also touched earth, this galvanic electrical connection would dominate the capacitive "connection" to your AC power wiring and the "picked up" signal reduced significantly.


It's all about potential dividers formed by capacitors and resistors and not really about antennas (RF electromagnetic wave devices).


And the presence of the human body can reduce signals reaching (say) a sensor plate: -


enter image description here


Here, the hand (and its capacitance to ground) diverts the electric field from hitting the "receive" plate and less current flows into that plate.



atmega - SPI device prevents ISP programming


I have an ATmega8 with a Nokia LCD 5510 connected to it. Everything works great on a breadboard and my next step is to move it to a more permanent board. My problem is that I can't program the ATmega8 while the LCD is also connected. I assume it's because they use the same SPI pins and that the LCD somehow interferes with the programming. How can I do this different so that I can flash the ATmega via ISP without unplugging the LCD?



Answer



You have to prevent any other device from driving the SPI lines during programming.


To avoid driver contention, a series resistor should be placed on each of the three dedicated lines if there is a possibility that external circuitry could be driving these lines.


enter image description here


Take a look at Application note AVR910.




To avoid problems, the In-System Programmer should be able to keep the entire Target System Reset for the duration of the programming cycle. The target system should never attempt to drive the three SPI lines while Reset is active.



So it would be best if the reset lines of the ATMEGA and the display are functionally connected to prevent the display from doing anything while the programmer holds reset.


Arduino code compiles both on Eclipse and on AVR Studio 5, but only Eclipse version is functional


I'm trying to choose an IDE for arduino development. I installed both Eclipse and AVR Studio 5. And configured them using the instruction on the Arduino site (for Eclipse) and those two tutorials (AVR Freaks, EngBlaze) for the AVR Studio.


I've written a simple project in Eclipse. The code compiles and work as expected when uploaded to the Arduino (Atmega2560). I then used the same code and created an AVR Studio project.


On AVR Studio my code compiles just fine (so it seems) but when I upload it to the board (using the same avrdude configuration) the board only flashes the L led (pin 13) at a what seems like 1 second rate.


Ideas anyone?




Typically, what is the function between pulse width and angle in a servo motor?


I have a pair of Futaba S3001 servers that I am controlling with a Raspberry Pi, using the pigpio library.


To control the angles of the servos, I set the pulse width according to the formula:


pulse_width = centre + angle * multiplier

where centre is the pulse width required for 0 degrees, and the multiplier is a figure arrived at by trial and error to that represents the pulse width difference required for one degree change.


For one servo, I have arrived at:


multiplier_1 = 9.444444444444445

centre_1 = 1350

and the other:


multiplier_2 = 9.222222222222221
centre_2 = 1315

This seems to work reasonably well, at least within +/- 45 degrees.


At larger angles, I am not so sure it's still within bounds, but it's hard to tell.


My questions are:





  • Is the relationship between pulse width and angle wholly linear, as I am assuming?




  • Does the linearity break down more towards the ends of the servo's travel?




  • What sort of accuracy should I expect from a hobby servo such as this?





  • Is there a better way to arrive at the function I need?





Answer



A typical function is a polynomial with multiple terms. 3 or four terms are required to get a function that fits reasonably well.


I have established this empirically through testing multiple servos (and multiple different models).


In the graph below, the x-axis represents degrees and the y-axis represents pulse-widths. This particular example is from a Tower Pro SG90, a very cheap hobby servo, with the dots representing actual values.


However, it's fairly typical of all the devices I tested:



  • the actual results don't track the curve perfectly


  • the response of the motors becomes less sensitive towards the extremes.


There's more information about this, plus a link to the Jupyter Notebook I used to produce the graph.


pulse-widths to angles


Having said that. In most cases I tested I have found that a 10ms change in pulse-width will produce roughly one degree of movement, which provides a useful rule of thumb for many applications.


So to answer the specific questions:



  • The relationship between pulse-width and angle isn't wholly linear, though I guess it's supposed to be roughly so.

  • The linearity breaks down increasingly towards the ends of the servo's travel.

  • Micro-servos such as SG90s seem to have a resolution of (quite approximately) 1.25 degrees, but they also suffer from hysteresis (i.e. where they land can depend on which direction you're coming from). I had better results with some larger, more powerful servos (Futaba S3001) but not some others.


  • In order to arrive at the function I needed, I captured some pulse-width/angle values, as shown, and used Numpy to find the curve of best-fit.


Embedded C programming material



I am looking for some material (books/sites) related to embedded system programming in C language. Here in the lab we have available three plataforms: one Microchip PIC18f4550, one Freescale HC12 and one ARM (Beagleboard).


We are willing to teach embedded C with the PIC, assembler with Freescale and embedded operational systems with Beagleboard. Each class will be a six month course.


Open to all advices.


Thanks



Answer



For C programming - embedded or otherwise, you need The C Programming Language by Brian Kernighan and Dennis Ritchie, popularly known as K&R.



I have one book on PICs, I like it: The Quintessential PIC® Microcontroller by Sid Katzen.



For the BeagleBoard, some background in embedded Linux will be important. Here's a good book written by a good friend: Building Embedded Linux Systems by Karim Yaghmour, Jon Masters, Gilad Ben-Yossef and Philippe Gerum.




Wednesday 26 June 2019

schematics - What is this electronics symbol (four triangles?)



The below image is from a service manual for a mobile radio. Note the small symbols that appear to be four triangles, point to point. I've searched far and wide and cannot identify that symbol. I have a nagging feeling that I've seen something like it in hydraulics, but never in an electronics diagram. I know that my radio doesn't have a bunch of stars of David printed inside it, so what could this symbol be?


Some of them have a line through the middle, others don't. Compare for example the ones near the labels "mic int" and "mic ext". Does this represent something, or is it a typo?


circuit diagram



Answer



It looks like it is a transmission gate. Although typically a transmission gate is made up of 4 pins and looks like(made with CMOS):
Transmission Gate


power engineering - Electrical schematics component ID's


Is there a list of standard ID codes used for components on a schematic drawing that anyone can point to?


e.g.


K = Contactor
S = Switch
Y = Solenoid
X = Terminal strip


etc.



Any list would be good, although if there is anything relating to Australian Standards that would be great.



Answer



These are from AS 3702, Item Designation in Electrotechnology. This is equivalent to IEC 60750.


There is a three-page long table of "Item" vs. "Letter Code" including -


Contactor                        K
Relay K
Switching devices for control S
Switching devices for power Q
Solenoid Y
Terminal X




For countries following American practice, the Reference Designators come from IEEE 315-1975 and IEEE 200-1795. These are different to the AS / IEC letter codes.


How to join high current wiring?


I need to join 4 wires together: a 6 gauge wire, two 10 gauge wires and a 22 gauge wire. The 6 gauge wire is the current source, the two 10 gauge wires will draw a continuous current of up to 30A and the 22 gauge wire about 20 mA. I need to do that twice - one for each leg of a 208/240v circuit. This is for an electric vehicle charging application.


I have been using a large size wire nut for this, but twice now it has failed due to overheating.


Left to my own devices, my next attempt would be with a split bolt, but then I'm going to need to wrap it all in a mile of electrical tape.


This is all going to be inside of a sealed chassis. The chassis will be portable, but all of the wires will have strain relief at the chassis entrance.



Answer



Look for a "power distribution terminal block" or a "terminal bus bar." These are designed to land wires of various sizes and secure with a terminal screw, like the grounding terminals in your circuit breaker panel. Obviously you will need to ensure that the block or strip is insulated from other circuits as appropriate.


You may want to add crimp terminals/space lugs on the ends of your wires.


Terminal Bus Bar Example Spade Lug Example



Terminal bus bar, left; spade lug, right.


Building an Ultrasound Generator



I need to generate ultrasound with a frequency of 1.5 MHz. The ultrasound should be pulsed as shown here


enter image description here


An ultrasound pulse should be 200 µs long, a pause (no ultrasound) is 800 µs long. The desired intensity should be 30 mW/cm^2 and upwards.


The problem is, I have no idea where I would even start. I have basic to advanced theoretical knowledge of electronics and physics, I have soldered once, but that's about it.


So I need you for guidance :).


What device do I need to generate the ultrasound? I guess a normal speaker won't do.


What do I have to do to generate such a pulse form and the desired frequency?


What other items do I need?


I prefer pre-built components (like an ultrasound generator which can give me the above pulse form and frequency) over having to build everything myself; but if I have to build something myself, I'll take on the challenge and hopefully learn something from it.


Any thoughts or pointers are greatly appreciated.



(If my question is too broad, I'll be happy to provide more details.)




power supply - Can a CM choke be used to suppress common mode current in a DC circuit?


I have a setup with a DC/DC converter like in the figure below. I need to minimize common mode current on the supply input.



There are no other connections besides Vsupply + and - and Rload + and -.


setup


I'm in doubt whether a CM choke will help reducing the CM current. And how would it need to be connected to the grounds of the DC/DC and the load. I've drawn to ways to connect it, but I'm not happy with either one.


schematic


simulate this circuit – Schematic created using CircuitLab In this circuit the Supply is separated from the buck and the load with a CM choke. But because the CM choke is in the supply GND - load GND path, this increases the transfer impedance. (The choke is depicted by L1 and L2)


schematic


simulate this circuit With this connection, the transfer impedance issue is solved, but now the CM choke is partly in the feedback loop.


Can I use a CM choke to reduce CM currents to the supply? How? Should I use a different filter?




identification - Is there some logic in IC name prefixes?


There are hundreds of prefixes in IC names, this page lists a number of them. For some it's easy to see that they refer to the manufacturer's name, like AD for Analog Devices or LT for Linear Technology. Others can be found with several manufacturers, often three letter prefixes: SAA, SAF, SDA, TCA and TDA, to name a few. I wonder if there's some logic in this, like T** being a specific group with subgroup TD*, etc. Is there a logical structure?



Answer



Manufacturers often do use their own prefix for original products, or may continue to use a prefix of a company or product line that was acquired.


As the number of IC available has continuously grown the complexity of the naming schemes have become less obvious, and more exceptions exist.


For example MAX- prefix typically refers to a Maxim IC, including the well-known MAX232 except MAX232 is also made by TI.


The NE5532 available from JRC, TI and On Semi, was originally designed by Signetics and continue to use the NE- prefix.



Other than business unit / company (original or acquired), the next most popular prefix convention would be series or technology based. Here I'm thinking of Op-Amps such as TL-, which are JFET or BiFET based op-amp technology AFAIK.


Of course there are nearly as many exceptions to the rule as the rule covers, so like life, it's messy.


Tuesday 25 June 2019

pcb design - Why route air gaps for voltage isolation on PCBs?


Learning about PCB design for power supplies, I frequently see boards with routed gaps to separate low and high voltage sections of the layout.


Why go to the trouble of routing an air gap when etching the copper away should create the same level of isolation? Is the breakdown voltage of air much higher than FR4?


I assume that such gaps are used to avoid situations where copper may not be etched away perfectly.



Answer



High voltage PCB design


High Voltage PCB design for arc prevention


A few reasons why:




  1. When arc-over occurs, it could cause carbonization (a.k.a. "burning") on the PCB surface. This could result in a permanent short. This is also irreversible damage, where-as arc-over in air isn't (unless something else goes wrong). This would be especially bad if a single high-voltage spike created a permanent short, then any "low-level" voltage source would still have a low impedance path available.

  2. You have the option of installing a high-dielectric strength shield (something much better than FR4/soldermask, and better than air).

  3. Dust/dirt can accumulate on a board surface, reducing dielectric strength. Not as much of a problem (though still could be a problem) if that surface just isn't there.

  4. In the second link, they did some experiments where humidity had a drastic effect on the breakdown voltage of the soldermask, and a smaller (though potentially still significant) effect on a slot. Their best result was from removing soldermask and cutting a slot (no significant performance hit).

  5. Any inadvertent creepage mistakes will be removed by the router, though really this should be caught in the design stage, especially with modern CAD. The PCB might not work right if tracks has unexpected open circuits, and making a high-current track smaller could cause other issues :P

  6. Required air clearance seems to be smaller than surface required surface creepage distance.


A quick look at some creepage/clearance tables :


clearance table III



creepage table IV


seems to confirm that creepage distance > clearance distance, especially with higher pollution degrees.


Pollution degree is a measure of how the environment could affect your PCB. See: Design for Dust.


Description of various polution degrees (table 1):



  1. No pollution or only dry, nonconductive pollution, which has no influence on safety. You can achieve pollution degree 1 through encapsulation or the use of hermetically sealed components or through conformal coating of PCBs.

  2. Nonconductive pollution where occasional temporary condensation can occur. This is the most common environment and generally is required for products used in homes, offices, and laboratories.

  3. Conductive pollution or dry nonconductive pollution, which could become conductive due to expected condensation. This generally applies to industrial environments. You can use ingress protection (IP) enclosures to achieve pollution degree 3.

  4. Pollution that generates persistent conductivity, such as by rain, snow, or conductive dust. This category applies to outdoor environments and is not applicable when the product standard specifies indoor use.



arduino - Change PWM frequency?



I am at the moment trying generate a PWM signal using timer1, but a failling misserably.


I am using this library available from arduino to interface the timer1.



http://playground.arduino.cc/Code/Timer1


The code i am running is this


#include "test.h"

volatile int step_count = 1;

test::test()
{
pinMode(10,OUTPUT);
Timer1.initialize(20);

Timer1.attachInterrupt(callback);
}


static void test::callback()
{

}



void test::test_pwm()
{

Serial.print("period: ");
Serial.println(period_used);
Serial.print('\n');
Serial.print("value: ");
Serial.print(value);
Serial.print('\n');


Timer1.pwm(10, (50.0 / 100) * 1023);

}

The constructor initializes the timer.


void TimerOne::initialize(long microseconds)
{
TCCR1A = 0; // clear control register A
TCCR1B = _BV(WGM13); // set mode 8: phase and frequency correct pwm, stop the timer
setPeriod(microseconds);

}

SetPeriod() should be one that determines the frequency of the PWM


void TimerOne::setPeriod(long microseconds)     // AR modified for atomic access
{

long cycles = (F_CPU / 2000000) * microseconds; // the counter runs backwards after TOP, interrupt is at BOTTOM so divide microseconds by 2
if(cycles < RESOLUTION) clockSelectBits = _BV(CS10); // no prescale, full xtal
else if((cycles >>= 3) < RESOLUTION) clockSelectBits = _BV(CS11); // prescale by /8
else if((cycles >>= 3) < RESOLUTION) clockSelectBits = _BV(CS11) | _BV(CS10); // prescale by /64

else if((cycles >>= 2) < RESOLUTION) clockSelectBits = _BV(CS12); // prescale by /256
else if((cycles >>= 2) < RESOLUTION) clockSelectBits = _BV(CS12) | _BV(CS10); // prescale by /1024
else cycles = RESOLUTION - 1, clockSelectBits = _BV(CS12) | _BV(CS10); // request was out of bounds, set as maximum

oldSREG = SREG;
cli(); // Disable interrupts for 16 bit register access
ICR1 = pwmPeriod = cycles; // ICR1 is TOP in p & f correct pwm mode
SREG = oldSREG;

TCCR1B &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12));

TCCR1B |= clockSelectBits; // reset clock select register, and starts the clock
}

I don't see anything wrong with the way it implemented, but are pretty sure that something must be wrong here, but can't quite figure out where the error is.


And the pwm function is coded here:


void TimerOne::pwm(char pin, int duty, long microseconds)  // expects duty cycle to be 10 bit (1024)
{
if(microseconds > 0) setPeriod(microseconds);
if(pin == 1 || pin == 9) {
DDRB |= _BV(PORTB1); // sets data direction register for pwm output pin

TCCR1A |= _BV(COM1A1); // activates the output pin
}
else if(pin == 2 || pin == 10) {
DDRB |= _BV(PORTB2);
TCCR1A |= _BV(COM1B1);
}
setPwmDuty(pin, duty);
resume(); // Lex - make sure the clock is running. We don't want to restart the count, in case we are starting the second WGM
// and the first one is in the middle of a cycle
}


the problem here is that I can't create a PWM signal that doesn't have a frequency more or less than 490 hz. If try to change the value it initializes changes the duty cycle, rather than the frequency... What could be wrong here?


Becomming annoyed by the library i began setting things up manually


Here is the code. It should create an interrupt each 1 hz,in which the state of the pin gets toggled. The frequency of the pin toggling occurs at 490 hz.


#include "test.h"

test::test()
{
pinMode(10,OUTPUT);
//Timer1 setup1 Interrup at 1hz

cli(); // Stop interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 15624; // Compare register value = cpu_fre/(interrupt_freq*prescaler)-1 (must be <65536)
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS12) | (1 << CS10);
TIMSK1 |= (1 << OCIE1A);

sei(); //allow interrupts

}

ISR(TIMER1_COMPA_vect)
{
digitalWrite(10,!digitalRead(10));
}

Answer



Do not configure hardware in a global constructor. Your constructor will be called before main(), and main() will call init() for initializing the Arduino core library. And init() will reconfigure Timer 1 for PWM at 490 Hz.


That's why many Arduino libraries have classes that implement an begin() method: for delaying the hardware initialization until after init() is done.


automotive - Can I use this analog switch for CAN bus signals?


In the deutsch 9 pin obd interface for heavy trucks, some manufacturers use the pin F,G for J1939 protocol and some use it for J1708 protocol. I am trying to use a NLAS4684 analog switch with dual SPDT configuration to get the desired output based on the pins usage by manufacturers.


I am worried about connecting an Analog switch next to the vehicle BUS pin. Is it safe to connect this switch to the diagnostic port to route signals? The Rd_on for this switch is low and the current per channel is around 300mA.




safety - Why are typically fatal currents non-lethal when they pass through your body for a short time?


I've been reading up on electrical safety, and the commonly cited controversial quote "it's not the volts that kills you, it's the amps". What I have gotten out of these sources is that it is in fact the amperes that stop one's heart, but the voltage determines this current, and the body is a non-ohmic resistor. (I have read this which mentions a lot about the volts and amps).


However, I am confused as to how much time a current must be passed through your body in order to be fatal. This video states that if you were to model the human body as a 100 picofarad capacitor with a 1500 ohm resistor in series, a high voltage static shock would pass a very high current through the body, but for an extremely short time (less than a microsecond). How long would a potentially dangerous (>5mA) AC/DC current have to be passed through the body in order to harmful? I understand that this is maybe too general a question, but is it possible to give a figure accurate to a few orders of magnitude?


Also, if it is in fact the amperes delivered over time that are detrimental, would a unit such as the Coulomb be more suitable for determining how fatal an electric shock might be?



EDIT: I am assuming that the electric shock is delivered hand to hand where it is most likely to pass through the heart and thus heart fibrillation is of most concern. If there are other significant causes of death from hand to hand shocks that I have overlooked, please tell me.



Answer



You need to bear in mind that there are many different modes of damage possible,



  • Large current passed though tissue may burn the tissue

  • Modest current passed through a vital muscle (like that of the heart) may cause that muscle to operate in a manner that it's not used to and strain it so that it is damaged from the strain.

  • Very tiny current may interfere with the normal nerve signals that drive the heart's operation, throwing off the heart rhythm leading to ineffective pumping for long enough to be fatal.


So it's not a matter of stating a particular voltage, current, charge, energy or power. It's a matter of stating a range of very particular and quite different circumstances that pertain to different body systems.


Monday 24 June 2019

Purpose of 2 serial resistors on voltage divider


In the schematic/picture below, what is the purpose of 2 serial resistors for voltage divider? Temperature, thermal runaway, stocks, prices, or something else?


Thank you.


schematic


simulate this circuit – Schematic created using CircuitLab



Answer



It's typically done to meet reliability requirements for safety.



When operating from a hazardous high voltage, a circuit needs to have Single Point Of Failure (SPOF) protection to meet safety approvals such as CE. Specifically, a hazardous voltage is usually that above 50 Vac or 120 VDC, but the requirement is stated in the standards that the equipment must be approved to. It certainly applies to your 400 VDC here.


Designing for SPOF means that the effect of a failure of a single component will have on the circuit needs to be considered, for every component. For SPOF, 'failure' means that the component fails short-circuit or open-circuit. Components don't all fail this way in real life but this is how it is considered in SPOF. The circuit must not cause further hazards, such as fire, harm to people or over-rating of other components, when a single component has failed in this way.


Considering SPOF here, a single series resistor from 400 V could fail short-circuit and deliver 400 V across the 1 K resistor and the output. So two series resistors are used instead, for SPOF-level protection. If one fails short-circuit, the other must still be working since we are considering a single point of failure.


Each surviving resistor must be rated to the handle the full voltage and power it would then have to deal with. So here, you would need 1 M resistors rated for 400 V plus the tolerance of your supply plus a safety margin (500 V or higher?). And the power rating needs to be for the highest 400 V supply voltage across a single 1 M resistor and the 1 K, with derating. So lets look at 160 mW dissipation and use at least a 320 mW resistor e.g. 1/2 W.


Next, if the 1 K fails open-circuit, the 400 V through 2 M source impedance will be delivered to your output. So that needs to be considered also. You could use a second parallel resistor and make both 2 K. A failure of any of the four resistors you've now got will affect the potential divider output voltage, so that must be allowed for. If it's just detecting the presence of 400 V, suitable resistor values would let the output drive an NPN transistor or voltage comparator that'd work from any of the three output voltages caused by the three possible dividers (2M:1K normally, 1M:1K, 2M:2K). If you're trying to measure the 400 V, you could add a second and third identical divider circuit and put them through a majority voting circuit to identify the correct voltage (two of the three voltages nearly the same). There are different ways of doing these things but they all affect cost, peformance, space etc., so they need careful consideration.


This may not be the original reason that your circuit here has two series resistors, I don't know the application or its requirements. But its a reason why it should.


Designing for reliability, safety and EMC are often forgotten in circuit designs over pure function. It is a very good design approach to consider these requirements in the very conception of a circuit, not try to add them later.


avr - Using diodes to limit current to LEDs


I'm setting up an attiny2313 to drive an array of LEDs and blink them in different patterns. Rather than putting a series resistor in line with each LED (they'll be controlled separately, so I can't do tricks like putting them in series with each other), I was wondering about just using a couple diodes to get the voltage down to the right range.


The system is running at 3.3V (with a regulator to keep it pretty constant), and two 1N4001 diodes will drop that down to 1.9V - right in line with the lower end of the 1.8 - 2.2V these LEDs are specced for. Since the diodes will always want to maintain the same voltage drop across themselves, I don't have to worry about that voltage changing as I turn the LEDs on or off. Overall I save 6 components.


Has anyone else tried something like this? Any gotchas I've overlooked? I realize the diodes will have to dissipate the full current from all the LEDs, but for this small amount of current that doesn't seem like it will be an issue.


(edit: I'm putting these diodes between the common cathode of the LEDs and ground)




Answer



I must confess I never tried this. But the series resistor has an important role: it is there to limit the current through the LED. If there's no resistor, the current may be limited in the end to a value which is too high for the LED or for the driver transistor. Theoretically you should graphically add the U-I characteristics of the diodes and the LED, and see on the the resulting characteristic what's the current for your Vcc value. But the main problem is that this current cannot be reliable predicted, since the U-I catalog characteristics of the diodes and LED give you an typical curve, and this curve will also shift with the temperature.


So while it may work, I wouldn't count on it working in every instance. But you may have some help from an unexpected place: the IC driving your LEDs. Sometimes the digital outputs have internal resistors or other ways to limit the output current, in order to avoid overloading them. So check the spec sheet for your attiny2313.


Single LED single transistor circuit not working


I was making a circuit with 1 LED and 1 transistor. pretty primarily i was trying to use the transistor as a normal switch. Here is the diagram below.


enter image description here


So, this is an NPN transistor and i connected the -ve part of the D1 (transistor) with the -ve part of the LED and the other -ve leg of D1 to ground. I connected the +ve part of D1 with the positive end of 9V dc power supply. The LED should light up and if I disconnect the wire connecting the +ve part of D1 , the LED should turn off. But the problem that I am facing is that the LED isn't lighting up when I connect all the points and follow the schematic.



Also another problem that I am facing is that when I connect a wire with the +ve leg of D1 and don't connect the other end of the wire with the battery and just hold the wire by my fingers, the LED turns on but emits very little light. Is there any mistake in my schematic?




receiver - Should a fuse with the correct amps, but is physically too small, still power my stereo unit?


I'm not sure if I'm asking the right kind of question for this site. But if someone could help me, I'd be grateful:


I blew a 125V 2.5A fuse in my home stereo head unit. I couldn't find that fuse at any stores nearby, but I was told 250V 2.5A would work just fine. I bought those but when I went to install it, I noticed I bought 3/4" size but need 1" size.


Even though it's too small to fit in the fuse clamp, I figured it would still work if I drop it in there and have the metal touching on both sides. My stereo powers up like it's working again, but now I get no sound; just humming from my speakers. I've checked all the speaker wires, they look fine.



Is this because the fuse is too small, or does it sound like i have another problem?




bandwidth - minimum readable rise/fall times in an oscilloscope


How can I calculate minimum readable rise/fall times of a signal in an oscilloscope (from practical point of view)? Does it depend just to bandwidth and sampling rate of oscilloscope? regards



Answer



Did you Google at all before asking? A simple search for "scope bandwidth vs rise time" brings up this document, which explains that the "rule of thumb" is that


$$\text{Rise Time} = \frac{0.35}{\text{Bandwidth}}$$


For example, a 350 MHz scope will have a rise time of about 1 ns.


For reasonably accurate readings, the scope rise time should be no more than about 20% of the signal rise time. Another way of putting it is that the scope bandwidth should be 5× the highest frequency of interest.


Note that we're talking about the analog bandwidth here. The sample rate really has nothing to do with it, as long as it meets the Nyquist criterion for the bandwidth.


Sunday 23 June 2019

batteries - Modifying a Simple Transformer Circuit


I have a heavy 14.4V 1.5A heavy battery charger I would like to use to charge my car battery (over time, monitored for heat in a well ventilated area).



When I plug the battery to the charger as is, I believe it turns off as the led doesn't turn on and the Voltage I read is 10.8 which is what the battery is at. When I measure the charger on it's own I get 13V.


Can someone help me modify it to make it work? I'm comfertable soldering and researching if you don't feel like giving a specific answer :). Images of the transformer and circuit:


Transformer


Circuit


Details


Thanks in advance for any efforts :)


Edit - I sketched a diagram of the circuit on tinyCad, here it is: circuit


I noticed that there is an earth connection for the battery, but only 2 connections to the wall socket. I don't get how it would be earthed, but perhaps the third connection is needed to turn it on? It is directly connected to one of the switch's 4 'legs'.



Answer



It looks like you're trying to repurpose a charger that was originally intended for some sort of tool battery, judging from the socket built into the case.



It also appears that said battery leaked at some point into the charger, given all of the crud all over the case, contacts and PCB.


You really need to clean the corrosion off of everything, and verify that all of the connections on the PCB and the rest of the wiring are still good.


The relay is probably there to switch between "fast" and "trickle" charging modes, as indicated by the labels on the LEDs. It would be worth your while to trace out the circuit and draw a schematic diagram, so that we all have a reference for further discussion.


pic - USB transmissions crash my software GUI


I'm transmitting a buffer array from inbuilt USB of PIC 18F controllers and sending this to a GUI. I am able to detect the device properly (enumeration). But the GUI crashes some times, without any reason.


I assume it is a transmission/interrupt problem as whenever I'm sending a constant number it does not crash. But whenever I'm doing an ADC operation and sending the corresponding value via USB, it crashes.


This made up my assumption that USB transmission or interrupt handling needs to be handled properly.



I'm new to the USB protocol and tried with this working code.


I have no problem regarding enumeration, but when transmits the crashing occurs.


The format of the code is:


 main()
{ usbinit(); // usb initialization

while(1)

{
x=do_adc();

UsbTasks(); // does usb works
yourtasks();//sends the buffer

}

}

I would like to understand what might be the cause behind this anomalous behavior.


As noted below in the comments the USB stack is set for polled configuration. How should I manage the ADC read?


If I do:



while(1)

{

UsbTasks(); // does usb works
x=do_adc();
yourtasks();//sends the buffer

}


Will it make any change? Or is this not the best way to send ADC values?



Answer



According to the USB CDC Class on an Embedded Device application note by Microchip which would mostly apply to other device classes as well:



The USBTasks routine may be used in a polled, cooperative manner as demonstrated. If so, nothing in the main loop should block for more than a few microseconds or events may be lost.



So the main two solutions that come to mind are:




  • Rather than wait for the ADC conversion to finish start the conversion and then use a conversion complete interrupt so that the main processing loop can continue while the ADC is taking a sample.





  • Set the USB stack to use the interrupt-driven mode to remove the requirements to call UsbTasks so often.




For most applications I'd say the latter is probably the easier solution so you don't have to worry so much if your main loop stalls a little while.


How is a VHDL variable synthesized by synthesis tools


I know two ways in which a VHDL variable is synthesized by synthesis tool:



  • Variable synthesized as Combinational logic

  • Variable synthesized as a Latch unintentionally (when an uninitialized variable is assigned to a signal or another variable)


What are the other ways in which a VHDL variable can be synthesized ? (Example: can it be interpreted as a FF ? )



Answer



I would distinguish three possibilities:





  1. A VHDL variable has no hardware representation at all. Assume the following example


    signal a,b,c : integer;  
    ...
    process ( clk ) is
    variable var : integer := 0;
    begin
    if ( rising_edge(clk) ) then
    var := a + b;

    c <= var;
    end if;
    end process;

    The variable var is not really synthesized as combinatorial logic at all (assuming this is what was meant in the question). It's rather the right hand side of the assignment a + b that is synthesized into hardware. Strictly speaking a variable never is synthesized into combinatorial logic.




  2. A variable merely holds an intermediate result, which is either evaluated in the same clock cycle -> no hardware synthesized ( this is 1) again ), or is evaluated in the following clock cycle -> a flipflop is synthezised.





  3. One of those dreaded latches is inferred in such cases where conditional branches exist in which the variable is assigned neither a new value (depending on some signals) nor a default value. Usually this case happens unintended :-)




AVR and STM32 ARM GPIOs state when IC is unpowered


I'd like to make a device combined two controllers: ATMega64 I already familiar with and ARM Cortex-M0 STM32F051 I'd like to be familiar with.


I'd like to directly connect GPIOs of two controllers. I hope that I will be able to choose which controller is now operating just providing the power to the one I need.



So the question is: if one of the controllers is unpowered will it's GPIOs interfere with GPIOs of powered one? Can I assume that all GPIOs are in Z-state while controller has no power?



Answer



No, in general you can not assume anything about GPIO pins of an unpowered chip, unless this is explicitly stated in the datasheet.


What will likely happen is that the protection diodes in the chip will try to power the 'unpowered' chip from any pin that is high.


ferrite bead - Magnetic core transfer loops (logic)


I have an interest in "alternative" logic gates, as in not silicon transistors. I have built RAM in a little game called "Powder Game", constructed "one-off" logic gates out of exploding lattices of popsicle sticks, and used electromechanical devices such as motors and relays. Right now, I'm intensely interested in magnetic cores. I would like to somehow experiment with these myself, but short of purchasing the equipment to do so, I haven't found a way. I am hoping that there is, perhaps, a free piece of software that would let me experiment with trying to make logic with magnetic cores. Can anybody help me find one?


Here is a PDF to describe what I am talking about: http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=04051986



Answer




You can buy vintage bare 45,000 cores here for $US49.00, with free international shipping from Bulgaria. Find 9 other friends interested in sharing and you have 4,500 each for $5.


One bit core memory project - liable to be of high interest. Use a suitable ferrite bead if needs be. Drive levels etc need looking at.


This vintage core memory board costs $400 on ebay BUT I have bought similar here for about nothing and while they are rarer than way back then they are probably still available for looking as electronic junk.


Almost any small ferrites with a hole in them will do - including RF decoupling beads. Or you could wrap a coil around a stick core etc. You can also just use iron or steel with due attention to characteristics. A steel nail with a suitable amp-turns pulse will be magnetised. Not the most efficint core memory but doable.


How to drive one


Very useful


Useful


Old discussion -2010 - may be some use


multiplexer - On-the-fly routing of digital and analog signals using unbuffered analog crosspoint arrays?


The issue I have is strongly related to a question which was asked over here. Unfortunately I did not find the answer I was looking for. Digging a bit more I've came across a class of IC's named unbuffered analog crosspoint arrays.


What I would like to know is if an unbuffered analog crosspoint array IC would allow for:



  • bidirectional data flow Xn to Yn

  • analog signal passthrough with virtually no noise injection up to, let's say, 12-bit resolution

  • digital signal passthrough compatible with I2C & SPI & UART


The one IC that I came across is ADG2128 but I'm not sure if it fits the criterias listed above.



I'm well aware that the problem might be solvable via a PLD (be it FPGA or CPLD), but I have no experience whatsoever hardware or firmware (VHDL) wise when it comes to such devices. Implementing an I2C slave altogether with a biderectional crosspoint array is no easy task for a beginner. Thus, a ready-to-go, already made IC would be a good kick-start.



Answer




bidirectional data flow Xn to Yn



It looks "configurably bidirectional": so you can route Xn to Yn, or Yn to Xn, but you have to pick which direction you want in advance.



analog signal passthrough with virtually no noise injection up to, let's say, 12-bit resolution



Bits aren't the most appropriate measure for noise levels in analog signals. You need to use signal-to-noise ratio (SNR) in decibels. 12 bits corresponds to a SNR of at least 72db. This device only guarantees up to 63db crosstalk between adjacent channels, so that may be a problem.




digital signal passthrough compatible with I2C & SPI & UART



Lack of true bidirectionality will be a problem here for I2C. The others ought to work for normal speeds.



I'm well aware that the problem might be solvable via a PLD (be it FPGA or CPLD), but I have no experience whatsoever hardware or firmware (VHDL) wise when it comes to such devices. Implementing an I2C slave altogether with a biderectional crosspoint array is no easy task for a beginner. Thus, a ready-to-go, already made IC would be a good kick-start.



The analog side of this cannot be done with a programmable digital logic device.


Saturday 22 June 2019

pic - What is slew rate for I2C?


I'm configuring I2C on a PIC18 using the built-in functions of the C18 compiler as described in section 2.4 of the documentation:


void OpenI2C2( unsigned char sync_mode,
unsigned char slew );

I'm not sure what I should do with slew. I can choose from two options, defined in i2c.h:



  • SLEW_OFF: Slew rate disabled for 100 kHz mode

  • SLEW_ON: Slew rate enabled for 400 kHz mode



In the datasheet in register 15-1, page 257, the two options are explained in a bit more detail:



  • 1 = Slew rate control disabled for standard speed mode (100 kHz and 1 MHz)

  • 0 = Slew rate control enabled for high speed mode (400 kHz)


I don't understand it though - I have a couple of questions:




  1. What is slew rate?





  2. For me, the two options don't make sense - what if I'd want to disable the slew rate for 400kHz and enable it for 100kHz? Why is this?




  3. When should I choose SLEW_OFF and when SLEW_ON?





Answer



Slew rate is how fast the signal changes from low to high, or vice versa. By limiting this abrupt transition, you can reduce ringing from signal reflections, and limit crosstalk between signal lines.


The way it works out, though, is that at 100kHz, the signal rates are so slow that the slew rate doesn't really matter; at 400kHz you may be able to fix an otherwise problematic circuit by limiting it; but then when you get to 1MHz you really need all the transition speed you can get, and so you just have to do good signal matching and route your lines more carefully.



The bit in question does nothing more than enable or disable the feature. The rest is simply advice. The speeds are in parentheses, as it is just a suggestion.


analog - dividing voltage of shunt Vref Lm4040


the whole thing i'm trying to do for about 3 mounth's is measuring IR-level with high accuracy, i tried many newbie circuits with huge noises, unstable results etc..
then i focused on ADS1110, an ADC chip which has an internal 2.048V vref so i can't use any value bigger that Vref for measurement. in other side, i'm using a voltage divider to generating voltage changes in different IR levels. not matter how much photodiode is sensentive and what is maximum and minimum resistance of it, the importance is just steady results for ever... so an steady power supply is the key, and i just found LM4040CIZ-2.5 available for myself (and don't know any other steady supply) which can provide 15mA maximum current.
but that is 2.5 not 2 in voltage! then i decide to use this formula to calculate R1 : enter image description here
and this one for R2 & R3 (considering an absolute maximum current drawing or passing trough Lm4040) : enter image description here
also i moved photodiode before the divide line in serie with R2 (instead R3) here is the circuit :


schematic


simulate this circuit – Schematic created using CircuitLab



i cant validate this method, im not crowling for a negative answer (80% i guess my circuit not works) i just trying to find a way to get an steady result from photodiode and ADS1110


TLDR : i read some things about Op Amps with a few understanding, im not sure if they are undependent voltage stability? here is the reference





Answer to comments, my imagine of steady is something near to a Big 1.5v Battery which i used many times to measuring IR level but unfortunately the whole of the big batteries goes empty then and new batteries are different from each other in millivolts,


Friday 21 June 2019

Simple soft power latching circuit for a microcontroller


I'm building a simple device with a microcontroller and I'd like to be able to turn it on and off using the "hold a pushbutton for 2 seconds" trick that is found on so many consumer devices nowadays (bluetooth headset, USB powerbank, smartphone.. come to mind). This feature seems to be called "soft power latching" but all the schematics I can find to implement it have drawbacks that make them impractical for such application, such as :




  • overly complicated, too many components for a small PCB such as found in a bluetooth hand-free headset

  • sometimes erratic behaviour in some borderline use cases such as a peak of current draw

  • need two separate buttons for on and off, or act as immediate response and do not allow for a 2-second-ish delay

  • a non-negligeable amount of current is consumed either at the on or off state, or both.


I thought such feature would easily be found implemented in a small IC for such applications, for example one with a pulled-up input for the push button, an external resistor/capacitor to configure the delay, and an open-drain output to control a pass-transistor or an EN pin. A Clear input pin to allow a software shutdown, a way to be able to use the pushbutton by the microcontroller as a user input, and a way to detect an imminent shutdown to perform a cleanup routine, would also be necessary in my case. However I fail to find such chip (granted I might not be using the right keywords). The closest I've found is the MAX16054 but it is a bit expensive for such feature and doesn't allow for the 2-second-hold delay (adding a capacitor beside the button seems a bit hacky because it would rely on the activation voltage of the IN pin).


I've therefore imagined a simpler/smaller/cheaper circuit that looks like it would match all the requirements but I'd like an external opinion on it, because it doesn't feel right that I can't find anything similar documented anywhere for such a useful and widespread feature :



It works like this :




  • the LDO's EN is pulled low by R3 and Q1 is pulled in a blocking state by R2, ensuring the LDO is off by default

  • when the button is pressed Q1's grid is pulled low, making it conductive and pulling EN high, which powers on the microcontroller

  • the MCU waits for two seconds then ouputs a low state on its PIN0 to permanently enable the LDO even if the button is released, allowing the delayed-latching behaviour (if the button is released before the delay, there is no latching : the LDO is disabled immediately)

  • the voltage across the button is pulled high again by R1 and made independent from Q1's grid by D1, allowing it to be used by the MCU through PIN1

  • the software is responsible for implementing the turn-off behaviour as required by reading PIN1 and releasing PIN0 to shutdown itself after doing the required clean-up


My questions are therefore :



  • would this circuit work and are there drawbacks I'm not thinking of?

  • why this kind of simple and useful IC doesn't exist and how is it implemented in consumer devices? (or alternatively, am I bad at searching?)





Edit : the circuit above will not work because the ESD diodes in the microcontroller will pull the lines low when the LDO is disabled (thanks @ElliotAlderson for pointing it out). Here is an updated version which should address the issue :




Answer



I've implemented this circuit and it works perfectly on my devices :



When the button is pressed, the microcontroller is powered on. Its firmware is programmed so that it sleeps for about 2 seconds before doing anything. If the button is released during this time, the power is cut off and nothing happens. Otherwise, when the delay is reached, the microcontroller asserts the PW_EN line, forcing the gate of Q1 low to assert the EN pin of the regulator and keep the power on from now on. The button is decoupled from this by D4, so it can be used as an input for any purpose by the microcontroller on the BTN_PW line. The firmware is responsible for detecting a 2-second press on this button and when it does, it performs a clean power off by saving the current state to flash memory, disabling peripherals, and finally, setting PW_EN to low to cut the power off.


In the end, it checks all the requirements I had : configurable timings, no power consumed when OFF, ability to perform a clean power off, BOM reasonably small.


usb - USB3 with fewer wires



USB3 offer a much faster bandwidth than USB2 but, technically, at the price of more wires that results in a thicker cable. USB3 is build with 9 wires, 4 are standard USB2 and 5 are the USB3 serial (2 differential transmit, 2 differential receive and one GND).


In an effort to make a thin & flexible cable, would it be possible to make a 5 wire cable, just with the USB3 wires? Assuming that both sides of the cable are USB3?



Answer



I could not find any information regarding initial synchronization for USB3. The best idea I could come up with is insulating the UTP pair from the old USB and trying it out.


So I covered the two center data pins on my USB3 hard drive cable with some kapton tape and plugged it in. The computer negotiates with the drive fine. No longer initial sync than normal.


It is likely that a 6 wire USB3 cable would work. 4 for LVDS pairs and Power and Ground.


However, most cables have a separate ground for each LVDS pair. This is to give return current paths other than the pair. This is helpful for signal integrity, just like how return current actually flows in the ground plane under LVDS pairs, not in the other pair, on a PCB.


So you are actually loosing only 2 of 10 wires.


enter image description here


Splitting a power supply between two circuits


I have two separate circuit boards (clock & radio) that I'd like to place within the same enclosure. One takes 12V, and the other needs 3V. How can I utilize one AC adapter to power both boards appropriately?



Answer




Use a 12V DC output AC Adapter to power the 12V module directly. You will then need a voltage regulator or DC to DC converter to reduce the 12V down to the 3V required for your other module. If the current requirement for the 3V module is low you could build a linear regulator out of an LM317, two resistors, two capacitors and a heatsink.


If your current requirement is more than a small number of mA the LM317 style design will get very hot and so a switching type DC-DC converter module would be required. You can find these for sale on eBay. Building your own switching regulator requires a certain amount of experience with such designs. Here is a sample type thing from eBay that could suit your needs.


enter image description here


(image from above linked eBay auction page)


Here is a diagram of how the power lines from the 12V wall adapter would connect into your two modules.


enter image description here


Thursday 20 June 2019

power - N-Channel MOSFET as on-off switch between battery and load


I'd like to use 3v microcontroller to activate a small fan after the microcontroller wakes from sleep. I'm not quite clear on the placement of the load (i.e. fan) and the LiPo battery in a MOSEFT schematic. My understanding is that I can use an N-chanel MOSFET to create a closed circuit between the LiPo and fan by supplying voltage via GPIO to the gate. Am I correctly understanding this? Below is my circuit diagram. Thanks for any feedback.


N-Mosfet circuit with battery placement



Answer



Your general idea is correct. I would like to clarify a few points:




  • The FAN connector is the other way round (the top pin is connected to the "+" of the battery, thus should be labelled "+"), while the bottom pin will be brought to ground when the MOSFET closes.





  • By "3v microcontroller" I suppose you mean "3.3v". In any case, the MOSFET you choose must have a threshold voltage lower than 3v. For example, the FDN338P MOSFET has a 2.5v threshold voltage. EDIT: apart from the threshold voltage, you have to make sure that the MOSFET will be able to handle the current that goes through your fan (this one has 1.6A maximum continous drain current, which should be fine for a small fan), and should also have a low conducting resistance (Rds) while being driven from 3.3v. This one has 155mΩ at 2.5v, which is great. Thanks to Spehro Pefhany for pointing this out.




  • The idea that you're powering a fan from a separate power source (battery) is a bit strange: if your microcontroller is powered by another battery, but you're doing this because the fan requires another voltage, it would be a better idea to use a 3.3v LDO to bring stabilised power to the microcontroller from the same battery. This way, you will have exactly 3.3v powering the microcontroller, instead of the fluctuating voltage it gets by being powered directly from a battery.




EDIT: To expand on my second point, I would like to add that a MOSFET might not be necessary in your circuit, and could be replaced by a regular NPN bipolar transistor (BJT), since a MOSFET with such a low threshold voltage might be hard to find.


schematic



simulate this circuit – Schematic created using CircuitLab


Since the BJT, unlike the MOSFET, "opens" when there's a current between the base and the emitter, we use a resistor (R1) to limit the current.


EDIT: Another valid point (thanks to Icy) is that it would be a good idea to add a flyback diode across the fan - when the motor (or any inductive load) is turned off, it becomes a generator for a short time, because the magnetic field induces a current back into the coil, causing a huge momentary spike. The diode will suppress those spikes.


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...