Friday, 18 May 2018

arduino - Sharp IR distance sensor outputting consistently high voltage


I am on a steep learning curve, and a bit bamboozled by my sharp distance sensor (data sheet). I am building a project with two distance sensors that signal an Arduino to operate a servo motor when an object comes into range. This currently works well, except that the sensors are outputting a relatively high voltage all the time, so I have to set a very high cutoff voltage in the Arduino code, or the motor is triggered all the time - eg both sensors are giving the Arduino numbers like 350-450 via the analog Read command (which should be about 1.7 - 2.1V as far as I understand it) all the time. This means that if I set a cutoff of 550 or 600, the setup works, but only if an object is within 12cm of the sensor (which should be able to detect objects as far away as 80cm). The sensors are not optically interfering with each other.


I am using an old computer ribbon cable to connect both sensors to the Arduino and I am suspicious that this is somehow causing noise in the output voltage, but the Arduino never seems to be read values less than about 300 (1.4V), and I would have expected noise to give some low readings sometimes. Any help would be greatly appreciated. I tried posting a circuit diagram, but as a guest user, the site won't let me. Also, I'd post the code, but it is embarrassingly messy. The Arduino and the servo have separate power sources with common ground, the sensors are powered from the regulated 5V Arduino supply, and connected to separate analog pins.


<code>circuit diagram</code>




vhdl - Convert C to FPGA


I'm new to programming for FPGAs so I was recommended to use some available C/C++ to VHDL translator.


Problem is, there are tons of information out there and almost all good programs need an expensive license.


I'm going to be given a Xilinx FPGA (probably a Virtex-6) and so I will have a valid license to use Vivado HLS and ISE. So now, my idea on how to convert a C algorithm to the FPGA is this:


1 - Convert the algorithm from C to VHDL and optimize with Vivado HLS (already understood from tutorials how to do this step)



2 - Use the newly generated VHDL files in ISE to generate a bitstream (no idea how to do this)


3 - Use the Xillybus to connect a C program with the FPGA (with the bitstream) and send/receive information to be able to see the outputs.


Am I on the right way and am I lacking some step? About step 2, it is straigh-forward to generate the bitstream in ISE or to I need a lot of knowledge about port-forwarding?



Answer



Answering your comment question here where I have more space. Let's say you have an application you've designed on a linux box, and it runs an algorithm you wrote for counting the number of cat pictures on the internet. Now it runs but it's slow because there is a lot of cat pictures to go through, so you want to accelerate it in hardware.


So you use this tool to write OpenCL code which is in C but with some restrictions on form because it's going to be "compiled" to run on an FPGA. The call this portion of the code kernels. Now these kernels are going to be synthesized and run on the FPGA, maybe you have 1 or maybe you have a 100 working parallel.


You're doing all this right in your application, inline, so when you get to the point of actually counting the cats you're using their APIs to do the processing on the FPGA.


I just saw your other comment that it's not out yet, I know Altera's stuff has been out for a while you can find a bunch of design examples here


All that said it depends what your goal here is, do you want to learn how to write verilog, test benches, and be an FPGA designer? Or are you looking to just accelerate algorithms or functions using hardware without doing all that?


Like any tool-set, which one to use depends on the job at hand.



Raspberry PI's SPI over RS485


I'm trying to understand how to connect a SPI device (a mifare RC522 RFID board) over long distance to my RPi via SPI.


I searched and find I could connect those via SPI over RS485 using a MAX490. (http://forum.arduino.cc/index.php/topic,93234.0.html)


Could anyone explain, maybe with a schematic, how to connect those devices? And do I need some software changes?



Answer




The single-ended SPI signals can be converted to differential pairs, which are more robust in presence of EMI and can go the distance. Then the differential pairs can be converted back to single-ended SPI signals, and connected directly to peripherals (ADC, I/O expanders, and such). That's what the original forum post is proposing.


MAX490 has 2 different sub-circuits.
One sub-circuits is a differential bus transmitter. It can convert a normal single-ended SPI signal to a differential signal.
The other sub-circuit is a differential bus receiver. It can convert a differential signal back to single-ended.


enter image description here (fig. 2 in the datasheet)
enter image description here


In order to connect the SPI bus this way, 3x MAX490 would be required on each side. Something like this.


enter image description here



The above approach has a clock delay problem. So it has limitation in bus length and bit rate. This is what @Andy was referring to in his comment.



Here's an application note that further explores clock delay and proposed a solution (and this one too). However, that solution requires 2 separate SPI peripherals on the microcontroller.


Here's another app note on clock delay in the context of high speed SPI.


Thursday, 17 May 2018

batteries - Is is safe to let my PWM charge my 12V battery at 14.8V?


I have a 12V battery linked to my solar panels.



In the middle I have a PWM charge controller, that is configured by default to charge the battery if Voltage if lower than 14.8.


At night, battery goes down to ~13.8V. (Which I think is the voltage of the full battery) - with no added voltage from solar panels.


Is it safe ? Does it reduce battery life ? (I have a deep cycle lead battery 80Ah.)


Should I change the PWM default configuration to put 13.8V instead ? Why isn't it 13.8V by default ? Is there some advantages I don't understand when set to 14.8V ?


EDIT : I have a battery Hankook DC24MF and a cheap 15$ PWM 20A.



Answer



Check the battery datasheet for proper voltages that are exactly correct for your battery. Otherwise use safe values.


I have a commercial solar battery charger that by default overcharges the battery once per month to 15 volts to equalize the cells. Otherwise it charges it to 14 volts. These voltages can be changed from the user interface.


If you use too high battery voltage, it will cause gas formation in the cells. Traditional wet batteries will dry, gel batteries not so much as they contain chemistry to minimize it. But they will suffer and the end result is diminished battery life.


The most important thing for me has been to learn that it's not a good idea to overcharge the batteries. While it "feels" like you have more charge in your batteries when they say 15.0 volts than 13.5 volts, the difference is quite small in reality, as the last couple of percents of charge raise the voltage very quickly compared to the normal operating conditions.



Help understanding ESD ratings



I keep running into ESD ratings in datasheets but I have no idea what they mean, for example in LM385 datasheet it says:


enter image description here


What does this mean for an electronic engineer or a hobbyist like me? can someone help me understand these points please:



  • What is the normal and maximum human body static voltages and what cause it to increase?

  • What does the value 500V mean? is it safe to touch it with hand for example?

  • How can I tell what's my ESD voltage at a given time?



Answer





What is the normal and maximum human body static voltages and what cause it to increase?



There really isn't a normal maximum, its dependent on the triboelectric charging between the materials your wearing (the source of the charge) and any discharge path (humidity in the air also makes a difference). See this article enter image description here



What does the value 500V mean? is it safe to touch it with hand for example?



That means it was tested to 500V, which mainly concerts input terminals of the device that would be connected to the 'outside' world by a cable or something the user of a device could touch. The human body model is: "this standard is intended to simulate a person becoming charged and discharging from a bare finger to ground through the circuit under test." it involves a set capacitance and resistance and a standardized test setup.


If you want electronics to survive then get a proper ESD setup. There are numerous articles on this site and the internet that describe what is acceptable for hobbyists. An ESD mat and a wriststrap would be a good start.



How can I tell what's my ESD voltage at a given time?




You could build or buy an electrometer and measure your potential between you and ground.


efficiency - How are LEDs considered efficient?


I've always found circuits containing LEDs hard to understand, please bear with me. I know most people find it easy, but I'm confused by them so some of my assumptions might not be correct, please correct me if that's the case.


So onto the question: Since LEDs are, after all, diodes, they essentially act as conductors with forward voltage, right? Which is why we need a pull-down resistor to regulate the current that flows through the circuit.


For example, let's say we have an LED with a Vf of 2 V and an operating current of 20 mA. (I think those numbers are reasonable right? Again, if not, please let me know.) And our power supply is a constant 4V. This means we need the resistor to draw 20 mA at 2 V, so it would be a 100 Ω resistor, with 40 mW going through it. That's a tiny power usage, but half of the power supplied is wasted through heat. So in this case, isn't the best case efficiency 50%? Which isn't really efficient in terms of DC power supplies, I would have thought.



So when people refer to LED's high efficiency, are they referring to the fact that the LEDs themselves convert the power they use into light efficiently, or is it considered efficient even after considering the 50% max wall plug efficiency?


Or is it just that I've given an example that happens to be a horrible circuit design that would never be found in production applications?



Answer



You seem to be getting confused between the efficiency of the LED and the efficiency of the circuit to drive the LED.


In terms of light output per unit of energy used by the LED they are an efficient way to generate light. In absolute terms they aren't great, they are around 10%[1] efficient in that respect however that is still far better than the ~1-2% of a conventional incandescent bulb.


But what of that power wasted in the resistor. A series resistor is the simplest way to drive an LED, it is far from the only way to do so.


Even sticking to a resistor what if we put 20 of your 2V LEDs in series and supply it with 45V? Now you are using 45*0.02 = 900mW of which 800mW is going into the LEDs and only 100mW (11%) is being used by the series resistor.


But we can make it even more efficient, the reason for the resistor is that the LEDs needs a constant current and most electronics are designed to supply a constant voltage. The easiest way to convert from one to the other (assuming a constant load) is to throw in a series resistor.


You can get constant current power supplies. If you use one of those to drive your LED then the resistor can be eliminated and you can get an efficiency of well over 90% of your total system power going into the LEDs.


For a home project or a simple indicator on a signal a resistor is a lot cheaper and simpler but if you are driving a lot of LEDs then the logical choice is to pay a bit more, have a slightly more complex circuit and use a dedicated constant current LED driver IC.




  1. As noted in comments, 10% is a good ballpark for current household lighting and probably also about correct for cheap commodity LEDs using older processes. Newer single colour parts can achieve significantly higher levels of efficiency.


ultrasound - Why sound wave is the best choice for many location detectors?


So I'm currently working on my high school final project, which is basically a Radar :) ...



I'm using the SRF05 detector to detect objects that are near the surface of the device. My current assignment is to learn and summarize all the different components that will be assembled at the end. (UART, MAX232 74HC244 etc, if you want to know :)


My teacher told me that the more I will know about these components, the better I will do at my work, and in the exams. So here is my question: Why sound waves are the best choice for the SRF05? Furthermore, why UltraSonic ones? What are the benefits of using sound waves, but not invisible light waves, heat or any other means that can do the job? Light, for example, travel much faster, thus creates a better result and will probably be more effective than sound.



Answer



Basically, sound is slow.


Using sound you can easily time how long a wave takes to travel to your object and reflect off it, thus giving you a fairly accurate distance. Light goes too fast for that, unless you are looking to measure the distance of the moon, say.


And why ultrasonic? So you can't year it. Imagine how annoying it would be if you were forced to hear it all the time? BeeeEEEeeeEEEEeeeEEEEEEEeeeeeeEEE....eeEEEeeEEEP


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