Saturday, 10 September 2016

power supply - Shutdown Controller for Raspberry Pi in a car


Following on from my previous question I'm trying to create a shutdown controller for my Raspberry Pi. The Raspberry Pi needs to be powered from the battery, but should power-down after the Pi detects that the ignition has been turned off.


The Pi will take a 3.3V feed from the ACC line (I have other components that will take 5V from the ACC line via a 7805, so I will step down to 3.3V using a voltage divider unless anyone has a better suggestion - I'll also be driving a uPD6708 which takes 5V CMOS I/O, so will have to step-down from 5V to 3.3V on another 2 lines).


Software running in the RPi will set one of the GPIO pins high, presumably when the RPi shuts down the GPIO pins will all go low. So Q1 should turn the relay on, keeping the RPi's power on as long as the ignition is on, or the GPIO pin is high.


I have 3 fuse kits with a 1000uF cap and some kind of transformer/inductor, so I may as well use one of them on each the 12V battery and 12V accessory line.



This shut down controller claims to draw only 50uA in standby - if I used a CMOS 4071 OR gate that would be a start, but from what I've read, you'd need more current from the OR gate to saturate the transistor - is that right?


Bearing in mind that I need to level-shift 5 lines from 3.3V to 5V and 2 from 5V to 3.3V in addition to the requirements of this sub-circuit, can anyone recommend components/alternatives for OR1, Q1, RLY1 and/or any modifications?


schematic


simulate this circuit – Schematic created using CircuitLab


Here's my attempt at following @Connor Wolf's suggestion.



  • R1 and C3 need to be be chosen to allow the RPi to shut down properly

  • I've added C1 because I image that it will take a brief moment before the relay switches after the ignition is turned off - I've got no idea how long that is, but I suppose the RPi is going to be drawing about 700mA from the capacitor, in addition to the 555 and relay


schematic



simulate this circuit


@Nick suggests it could be simpler - like this perhaps? I tried to remove the diodes so that I could just use an off-the-shelf 12V-5V 1A USB power supply (or a pair of them). The 555 datasheet says that it outputs 3.3V (max source 100mA? This page says 200mA). The RPi will take read the ACC line at 3.3V to determine when to shut down.


schematic


simulate this circuit



Answer



While using a one-shot timer circuit will work, I think an easier solution can be used. Take a look at this circuit.


enter image description here


For clarification, "VBAT" is a 12V source that is always on as long as the battery is connected. However, "ACC" is a 12V source that is only on when the ignition is on or the key is set to "accessory." Rather than using a 5V relay just to control the power to the RPi, why not use a standard 12V auto relay as shown. This way, there is no wasted power (except for the coil current while the power is on) because everything will be disconnected from the battery.


One side of the coil is always connected to 12V. The opposite side is connected to ground (chassis) through an N-Channel FET (Q1). While a MOSFET is used in the diagram, any FET capable of sinking the coil current can be used. When "ACC" is powered ON, Q1 will switch ON, connecting the coil to ground and actuating the switch. This will in turn power whatever 5V regulation circuit you plan to use (a simple 7805 regulator with heat sink, a switching DC-DC converter, the USB supplies mentioned, etc).


The diode D2 is there to ensure the capacitor can only discharge into Q1 and can be regular or Shottky. Other methods should probably be used for over voltage and current protection from the battery.



The "ACC" voltage can be put through a voltage divider to create a 3.3V signal for the RPi. Be careful with this voltage level, considering a 12V auto battery can really be more like 14V DC. As long as this signal is HI, the RPi knows that the power is on. Obviously, this GPIO pin should be set as an input with any internal pullups disabled. When "ACC" is turned off, the RPi should see the LO signal on the pin and begin its shutdown.


When the "ACC" voltage is turned off, the capacitor C1 will retain the charge for so long, discharging through the resistor R1. Once the capacitor voltage drops below the gate threshold of Q1, it will switch OFF, disconnecting the relay coil from ground and removing power from the peripheral circuit. If a "logic level MOSFET" is used for Q1, it will remain switched ON until C1 voltage is fairly low. I tested this circuit using an NTD4960 (Datasheet), and it remained on for around 15 seconds - until C1 was around 2V. To increase the time, increase the capacitance value.


arduino - What is the voltage range of a standard headphone jack from a phone?


I want to connect the output from the audio jack of an iPhone to an Arduino.


What voltage range can I expect to see on the audio lines from the iPhone? I assume that turning the volume up on the phone will produce a large AC voltage, but how large does it go up to?


I want to make sure that it wont exceed the voltage level that an Arduino can read on its input pins. Will I need to provide any circuitry between the iPhone and the Arduino?



Answer



Commercial line out specification is to be able to drive 1 milliwatt to a 600 ohm load. For a sine wave, this means a voltage of 0.77 volts RMS (2.2 volts peak-to-peak) and a current of 1.3 milliamperes RMS (3.6 milliamperes peak-to-peak).


varying load from electric motor



How does the discharge rate of the battery pack in an electric vehicle vary from 1C to 4C for example when the vehicle accelerates? It's the same electric motor and the same battery. How does the electric motor vary it's load on the battery?




hdmi - How to create an FPGA based Ambilight clone?


Some quick background:
Ambilight is a system on some Philips TVs that analyzes the color information on the screen and then sets some LEDs on the back of the display to project the screen's color onto the wall. It is a pretty nifty effect. There are clones of this system out there now that use a PC to process the video and control the LEDs. I find this to be a bit overkill - using an entire machine to dance some LEDs...

I'd like to modify bunnie's NeTV to process an unencrypted HDMI video feed and drive some LEDs. I know the NeTV has been designed for other purposes, but I feel that it can be modified to achieve my goal. I don't care for the underlying Linux subsystem, I2C spoofing, video overlay, etc. At this point, I am not concerned with working with HDCP encrypted streams.


NeTV schematics


NeTV source code


FPGA Block Diagram NeTV Block Diagram
This is a block diagram from one of bunnie's presentation slides.
The rest of the slide set is here.



Slide showing HSYNC,VSYNC, PIXCLK
This slide seems to imply that video pixels are, in fact, decoded (not necessarily decrypted).


Finally...some of my thoughts and questions:




  1. Can this be done on my desired hardware? If "yes", continue on! If "no", tell me what more I need!




  2. Will I be able to process video information without any external memory? There is no memory that the FPGA can access directly, as far as I can tell. This probably depends on what algorithm I use to process the video data - to use as little FPGA Block RAM as possible, I am guessing I would want to use some kind of 'iterative summing' of the pixels coming in, rather than storing a whole frame of picture data and then averaging the colors. Any hints with regard to implementing this algorithm? How to get started with this is my greatest hurdle.





  3. I have investigated the source code as to where I should 'tap into' the video data.
    This looks like the appropriate spot:
    Block Diagram of DVI Decoder
    I know, this image is long - it is the best I could do while making it clear to read. Blame Xilinx's tool for that!
    This seems to take in the TMDS data and output 8-bit for each color.




  4. I should have some kind of state machine for the LED driver - every clock cycle, it gets the pixel info from whatever module I create to process the video data.





Sorry if this is wordy or long - I'm trying to be thorough...I just need some help getting off the ground with this. This is my first attempt at an FPGA project - some may say its too difficult for a beginner but I say ... gotta start somewhere :) Thanks for reading.



Answer



I'm basing my answer completely on the code and documentation of the dvi_decoder module, and assuming it actually works as advertised. This file seems to be a (modified?) copy of the IP in the app notes Video Connectivity Using TMDS I/O in Spartan-3A FPGAs and/or Implementing a TMDS Video Interface in the Spartan-6 FPGA. These app notes are chock-full of important details, and I suggest you read them carefully.


As you indicated in the question, I will assume you are treating unencrypted streams, that is non-HDCP streams. I'm fairly certain that the information in the NeTV project can be adapted to decrypt HDCP, but it would involve a non-trivial amount of additional work and be on questionable legal grounds depending om your jurisdiction.


It looks like you will be able to obtain the data you need from the outputs of the dvi_decoder block. The block outputs 24-bit color information using the wires red, green and blue, synced to the pixel clock pclk. The outputs hsync and vsync alert the user to the end of a line/screen respectively. In general, you should be able to do on the fly averaging using these outputs.


You will need some basic logic to translate hsync, vsync and the pixel clock into an (X,Y) location. Just instantiate two counters, one for X and one for Y. Increment X at every pixel clock. Reset X to zero at hsync. Increment Y at every hsync. Reset Y to zero at every vsync.


Using red, green, blue, X and Y, you can do on the fly averaging. By comparing with X and Y, you can determine what box each individual pixel should contribute to, if any. Sum the color values into an accumulation register. To obtain the average value, you need to divide the value in the register by the number of pixels. If you are smart, you will make sure the number of pixels is a power of two. Then you can just wire the MSBs of the register to whatever you want to drive.


Because we want to drive displays while doing the accumulation, we will need to do double buffering. So we will need two registers per box per component. If you are using a 25-led string, this means you will need 25*3*2=150 registers. That's quite a bit, so you might want to use block ram instead of registers. It all depends on your exact requirements, experiment!


I assume you will be driving a led string like the one used in the original adafruit project kit. You should be able to figure out how to drive it from the values in the registers quite easily using SPI.


The dvi_decoder module is a fairly complex piece of kit. I suggest you study the app notes in detail.



As an aside, if you have not yet purchased an NeTV for use in this project, I recommend you also have a look at Digilent's Atlys board. With two HDMI inputs and two HDMI outputs, it appears to be tailor made for projects of this kind.


communication - Implementing a CAN protocol layer in software



I'm developing a project which will require the modest microcontroller specs of:



  • 8 12-bit, 10kHz ADCs


  • 1kB of RAM

  • 48-QFN or smaller footprint

  • 20kbps daisy-chainable noise-resistant and error-correcting communication protocol


Signal processing requirements are fairly low, and most can be exported to the master processor in the system. The first three specs are easy to meet, and can be done for less than $2 in quantity. However, communication will be happening in a very electrically noisy environment, so noise-vulnerable networks like LIN and I2C are out. An additional argument against LIN is that I'd like to run the whole thing at 5V or 3.3V, and LIN transceivers require 12V, and so would require an extra regulator or wire per sensor board. I initially chose CAN for this task. However, CAN controllers add considerable cost, and I'm curious if this can be done in software.



The CAN specification defines the Data Link and Physical layers of the OSI network reference model. Many inexpensive 8-pin ICs, such as the NXP TJA1040/50, Maxim MAX3058/59, Microchip MCP2551, and TI SN65HVD1050 exist to implement the physical layer. Implementing the physical layer with D/A converters or op-amps would be difficult, if not impossible, so these ICs are well worth the $1 or so that they cost.



For the Data Link layer, some microcontrollers add CAN protocol modules onto the basic UART, I2C, and SPI communications layers. However, these are significantly more expensive than the basic chips.


Investigation of cost of CAN protocol modules



To substantiate this claim, here are a few popular micros in CAN and non-CAN versions, from the :



  • ATmega16 - ATMEGA16M1 (with CAN): $3.87, ATMEGA168A (no CAN): $3.23

  • dsPIC - DSPIC33FJ64MC802 (with CAN): $6.14, DSPIC33FJ64GP202 (no CAN): $5.48

  • PIC18 - PIC18F2480 (with CAN): $6.80, PIC18F24J10 (no CAN): $2.10

  • Cortex-M3 - STM32F103C4T6A (with CAN): $6.50, STM32F100C4T6B (no CAN): $2.73


To be fair, I only compared microcontrollers with equivalent memory sizes, however, many of the non-CAN versions are available with smaller memory sizes for less. External CAN controllers, like the Microchip MCP2515, are almost $2, so it's obviously more cost-effective to have the CAN integrated into the microcontroller if you have the option.


Interestingly, the ATmega part is by far the cheapest CAN-equipped part in Digikey's inventory.


Function of CAN protocol layer



The CAN module found in the dsPIC microcontrollers does the following:



The CAN bus module consists of a protocol engine and message buffering/control. The CAN protocol engine handles all functions for receiving and transmitting messages on the CAN bus. Messages are transmitted by first loading the appropriate data registers. Status and errors can be checked by reading the appropriate registers. Any message detected on the CAN bus is checked for errors and then matched against filters to see if it should be received and stored in one of the receive registers.



This seems fairly doable in software.



Can a software protocol layer be used implement the CAN specification with only an inexpensive UART-equipped microcontroller and a CAN transceiver? If so, do any open-source implementations exist?


Alternatively, can CAN transceivers be used with UARTs to implement a custom protocol? I'm OK with a single-master topology; I understand that arbitration can be hard to get right in a custom protocol.



Answer



I think implementing the CAN protocol in firmware only will be difficult and will take a while to get right. It is not a good idea.



However, your prices are high. I just checked, and a dsPIC 33FJ64GP802 in QFN package sells for 3.68 USD on microchipdirect for 1000 pieces. The price will be lower for real production volumes.


The hardware CAN peripheral does some real things for you, and the price increment for it is nowhere near what you are claiming.


Added:


Since you seem to be determined to try the firmware route, here are some of the obvious problems that pop to mind. There will most likely be other problems that haven't occured to me yet.


You want to do CAN at 20 kbit/s. That's a very slow rate for CAN, which go up to 1Mbit/s for at least 10s of meters. To give you one datapoint, the NMEA 2000 shipboard signalling standard is layerd on CAN at 200 kbits/s, and that's meant to go from one end of a large ship to the other.


You may think that all you need is one interrupt per bit and you can do everything you need in that interrupt. That won't work because there are several things going on in each CAN bit time. Two things in particular need to be done at the sub-bit level. The first is detecting a collision, and the second is adjusting the bit rate on the fly.


There are two signalling states on a CAN bus, recessive and dominant. Recessive is what happens when nothing is driving the bus. Both lines are pulled together by a total of 60 Ω. A normal CAN bus as implemented by common chips like the MCP2551, should have 120 Ω terminators at both ends, hence a total of 60 Ω pulling the two differential lines together passively. The dominant state is when both lines are actively pulled apart, somewhere around 900mV from the recessive state if I remember right. Basically, this is like a open collector bus, except that it's implemented with a differential pair. The bus is in recessive state if CANH-CANL < 900mV and dominant when CANH-CANL > 900mV. The dominant state signals 0, and the recessive 1.


Whenever a node "writes" a 1 to the bus (lets it go), it checks to see if some other node is writing a 0. When you find the bus in dominant state (0) when you think you're sending and the current bit you're sending is a 1, then that means someone else is sending too. Collisions only matter when the two senders disagree, and the rule is that the one sending the recessive state backs off and aborts its message. The node sending the dominant state doesn't even know this happened. This is how arbitration works on a CAN bus.


The CAN bus arbitration rules mean you have to be watching the bus partway thru every bit you are sending as a 1 to make sure someone else isn't sending a 0. This check is usually done about 2/3 of the way into the bit, and is the fundamental limitation on CAN bus length. The slower the bits rate, the more time there is for the worst case propagation from one end of the bus to the other, and therefore the longer the bus can be. This check must be done every bit where you think you own the bus and are sending a 1 bit.


Another problem is bit rate adjustment. All nodes on a bus must agree on the bit rate, more closely than with RS-232. To prevent small clock differences from accumulating into significant errors, each node must be able to do a bit that is a little longer or shorter than its nominal. In hardware, this is implemented by running a clock somewhere around 9x to 20x faster than the bit rate. The cycles of this fast clock are called time quanta. There are ways to detect that the start of new bits is wandering with respect to where you think they should be. Hardware implementations then add or skip one time quanta in a bit to re-sync. There are other ways you could implement this as long as you can adjust to small diferences in phase between your expected bit times and actual measured bit times.



Either way, these mechanisms require various things be done at various times within a bit. This sort of timing will get very tricky in firmware, or will require the bus to be run very slowly. Let's say you implement a time quanta system in firmware at 20 kbits/s. At the minimum of 9 time quanta per bit, that would require 180 kHz interrupt. That's certainly possible with something like a dsPIC 33F, but will eat up a significant fraction of the processor. At the max instruction rate of 40 MHz, you get 222 instruction cycles per interrupt. It shouldn't take that long to do all the checking, but probably 50-100 cycles, meaning 25-50% of the processor will be used for CAN and that it will need to preempt everything else that is running. That prevents many applications these processors often run, like pulse by pulse control of a switching power supply or motor driver. The 50-100 cycle latency on every other interrupt would be a complete show stopper for many of the things I've done with chips like this.


So you're going to spend the money to do CAN somehow. If not in the dedicated hardware peripheral intended for that purpose, then in getting a larger processor to handle the significant firmware overhead and then deal with the unpredictable and possible large interrupt latency for everything else.


Then there is the up front engineering. The CAN peripheral just works. From your comment, it seems like the incremental cost of this peripheral is $.56. That seems like a bargain to me. Unless you've got a very high volume product, there is no way you're going to get back the considerable time and expense it will take to implement CAN in firmware only. If your volumes are that high, the prices we've been mentioning aren't realistic anyway, and the differential to add the CAN hardware will be lower.


I really don't see this making sense.


Friday, 9 September 2016

soldering - What does "no clean" solder actually mean?


I bought some solder that says it doesn't require cleaning. The description specifically says "Eliminates the need and expense of cleaning". But there's still a lot of some substance left on my board that I can't easily clean off. What is this substance? Is it a problem? Is there some way to clean it off besides soap and water?



Answer



Soldering requires flux to dissolve oxides and to promote wetting. Rosin (made from tree sap) is one flux material that has long been popular, and comes in various strengths- RMA (Rosin Mildly Activated) or RA (Rosin Activated). Kester says you can leave the flux on the board under fairly benign conditions and experience bears that out (it only becomes active = corrosive) at elevated temperatures, however most manufacturers will clean the board for cosmetic reasons and to allow inspection. Cleaning often involves the use of petroleum solvents- for example by vapor degreasing or just scrubbing.


Aqueous clean fluxes have been developed that can be cleaned without solvents- using just hot water and detergent.


No clean fluxes allegedly don't need to be cleaned and can be left on the board, however many of us have had problems with no-clean processes having relatively conductive residue. The residue is ironically extremely hard to remove, much more difficult than the two above-mentioned processes, more like 'can't clean'. Think twice about this kind of flux if you're thinking of sensitive analog boards that have high impedances. Even circuits you may not think of as being analog such as RTCC chips with an external crystal may be affected.


Safest for sensitive boards is rosin flux followed by a thorough cleaning process.


Corner Cases to Verify Synchronous FIFO


I'm trying to figure out the corner cases for verifying a synchronous FIFO during hardware verification.


My setup is a very simple two ports synchronous FIFO (write/read) and the write clk frequency is same as read clk frequency.


In order to test whether the FIFO overflow occurs or not, can somebody help me identify those corner cases so that we can completely verify this simple synchronous FIFO?


synchronous FIFO Spec




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