Category: Uncategorized

  • A high(er) voltage DAC using PWM

    Sometimes you just need to do things the old way. A recent post on the Arduino forum was asking about a method to replace the manual speed control potentiometer with something that could be automated. The need was to just replace the pot without replacing the entire control. Since the potentiometer provides a variable voltage to the control circuit, you’d normally use a DAC (Digital to Analog Converter) for this application. We don’t know what voltages may exist internally, so it’s a good idea to isolate the controller from the rest of the circuit. I decided that this could be a good application of a PWM (Pulse-Width Modulated) DAC.

    By filtering a PWM signal, we can create a DC voltage. This has the advantage of being a very simple way to produce a variable DC output at low cost using the Arduino. We can use a basic optoisolator like a 4N26 to isolate the Arduino from the rest of the motor control circuit.

    Here’s the circuit

    This takes the PWM output from the Arduino at pin 11 and feeds it into an optoisolator through the resistor R1. This protects the Arduino from any high voltage in the motor controller. There approximately 1,000V of isolation between the input pins (1&2) and the output (4&5). R2 is a pullup resistor that gives us +15V at the output of the isolator. Next, we buffer the output of the isolator with a CMOS 4011 AND gate. This is to provide an even drive to the RC filter. By using a 4000-series CMOS gate, we can supply up to 18V output. This is a very old logic series, dating back to the 1970’s but the parts are cheap, easy to find and work pretty well in this kind of application. The main drawback to 4000 series CMOS is that it’s pretty slow, but that doesn’t affect us here.

    The output of the NAND gate drives an RC filter (R3, C1) that provides a smooth DC value from the input PWM. J1 provides our 15V power input.

    And the code to run it.

    const int DAC_PIN = 11;
    
    void setup() 
    {
      // put your setup code here, to run once:
      pinMode(DAC_PIN, OUTPUT);
    }
    
    void loop() 
    {
      // put your main code here, to run repeatedly:
      for (int i = 0; i < 256; i++)
      {
          analogWrite(DAC_PIN, i);
          delay(5);
      }
    }

    So you can see here a simple, but interesting method of creating a high voltage, isolated output from the standard Arduino pins.




    If you’d like to subscribe to this blog, please click here.

  • A bit about pumps

    Syringe pumps, valve pumps and peristaltic pumps are classified as positive-displacement pumps.

    When a solenoid valve opens or closes, there is usually a small amount of liquid moved. This effect can be deliberately used as a pump. There are solenoid valves that are also specified for use as precision pumps, but they have to be at least 2-way (3-port) valves since you need a source to aspirate from and a destination to dispense into. They are very precise but you can’t control the volume of the dispense except by making multiple dispenses.

    Syringe pumps as you know use the motion of a piston in a cylinder to aspirate or dispense a fluid. They can be extremely precise and accurate if built properly. I used to work with some that were accurate below 10 microliters and precise, IIRC to within about a microliter. However, they were also very expensive. Syringe pumps are generally slow moving as high speed can cause the pump to cavitate, which reduces precision and introduces air into the fluid path. Cavitation is a release of dissolved gas (air) into the pumped fluid when the fluid pressure drops below the vapor pressure of the gas. This causes the gas to be released as small bubbles.

    One common technique that I saw when I was involved in the medical device industry is to build a motorized fixture that a syringe can fit into and and use that to control the piston. It gives a high precision and also solves the problem of contamination: just throw the syringe away when you’re done.

    Peristaltic pumps are also an option for a positive-displacement pump, but they are typically an order of magnitude less accurate than syringe pumps. They have the advantage that material compatibility is mainly an issue of the what the tubing is made from.




    If you’d like to subscribe to this blog, please click here.

  • What is an Embedded System and what does Arduino have to do with it?

    An Embedded Computer System is a small computer that is “embedded” inside something else. Unlike a laptop computer, or a desktop, or a server, its primary purpose isn’t processing data, but it is meant to control some aspect(s) of the “thing” it’s embedded into. You probably don’t think of your clothes washing machine as a computer, but if it was built in the last 10 years, it almost certainly has an embedded computer controlling it. Likewise, the car or bus that takes you to work has dozens of embedded computers doing tasks as complex as sequencing the operation of the engine, or as basic as raising and lowering the windows.

    How big are they?

    A typical mainstream CPU (Central Processing Unit: the heart of the computer) such as an AMD Ryzen runs at a clock speed of almost 4GHz, requires more than 65W of power and has over 900 pins for external connections.

    By contrast, the majority of embedded systems are based on microcontrollers. A microcontroller is a single package that houses a CPU, perhaps a basic clock source, some RAM memory to hold data and Flash storage for the program that it will execute, and peripherals that can read inputs like switches and pushbuttons, measure temperatures and voltages, and control output devices.

    A basic AVR Mega microcontroller that might be found controlling the functions in your washer will run on substantially less than 1W of power, has a nominal clock speed of 8Mhz (but can run much slower to save power) and might require fewer than 20 pins to control such things as water flow, agitator cycling or spinning at the end of cycle. The microcontroller in your toothbrush might only have 6 pins and could run for years on a single AAA cell if necessary.

    At the other end of the spectrum, more modern 32-bit microcontrollers have 1M+ of Flash memory and 256kb of RAM. Some microcontrollers can access external memory , further expanding their usefulness.

    Why use them?

    The benefit that an embedded system has over using logic “chip” to do their operations as was more popular in the past is primarily that a single low-cost chip can replace potentially dozens of external chips, thereby saving space, power and, of course, money. Additionally, a manufacturer may base a number of their products on a single microcontroller type, thereby saving on inventory costs and training. Since microcontrollers are computers at their heart, they can be reprogrammed to perform functions specific to the product they are embedded into.

    Where does Arduino come in?

    The Arduino is a basic microcontroller platform that was initially intended to offer artists and hobbyists a simple way to get involved in embedded systems. It has expanded from its basic roots to become a huge Open Source ecosystem of programming tools, libraries that make it easy to program unique functionality and add-on hardware that offers motion control, temperature and humidity measurement, multicolor LED displays, sophisticated graphics and so on.

    Arduino continues to be a great way to get your feet wet in programming embedded systems.




    If you’d like to subscribe to this blog, please click here.

  • First KiCAD boards

    All these years I’ve used Eagle to design PCBs. Finally decide to try KiCAD and I’m loving it. The part editor is so much easier to use and you know that’s one of the major tasks of making a new board.

    This particular design is a custom Bluetooth audio interface based on an ESP32.




    If you’d like to subscribe to this blog, please click here.

  • Why am I still doing this?

    I get asked sometimes why I do this. I’ve been an engineer for 30 years and programming embedded systems for most of that time. Sure, I’ve taken occasional side-treks into building a mobile app here and there. I’ve built a couple of web applications, including a pretty complex one for managing gym workouts, but I keep coming back to Embedded.

    Why?

    It’s FUN, that’s why. I love writing code that makes things move, or turning little (or huge) blinky lights on and off. I like to regale people with the stories of the times something caught fire, or the weird bug where the machine would “fix” itself, or how we almost had a massive recall due to some obscure failure that only raised its head years after a machine was in the field.

    Embedded systems are fun to write (yeah, I’m deliberately ignoring the nights of frustration searching for some apparently random failure) and the end results are usually something you can actually put your hands on.

    Try that with your React frontend!




    If you’d like to subscribe to this blog, please click here.

  • Basic wire crimping for arduino users

    I keep posting information on crimpers and crimping, so I’m just going to put this here so I can refer to it without having to type it all in again 🙂

    Crimping is a far more specialized and precise operation than it appears at first glance.

    First, you need good quality tooling. Crimp dies have to be made specifically for the terminal to work ideally and wire length and wire insulation thickness are critical. That said, I have had fairly good luck with some cheap crimpers, but it’s hit and miss.

    If you find that you’re having to “pre-crimp” anything before you can get the terminal into the die, then that’s a problem. That suggests that the die you have is not made for that terminal. Likewise, if the wires are slipping out. A good crimp cold welds the wire to the terminal and should require pounds of force (at least a firm pull) before the wire pulls out.

    The basic technique is to put the terminal into the die and squeeze the crimper just enough to hold it in place. Next, put the stripped wire into the terminal, making sure it’s at the right depth and that the insulation ends at the right spot.

    Then squeeze until the crimper completely closes and the ratchet releases so you can open it again. Inspect the crimp (the book I link below shows what various crimps should look like), and pull gently on the wire, holding the terminal in your other hand. A crimp for wire around 26-22gage should withstand at least a 5-lb pull, ideally a lot more, before it separates.

    This book has everything you need to know about crimping and more.
    Molex/TE Connectivity actually has a shorter book with good tips about crimping, but I can’t find it online at the moment.




    If you’d like to subscribe to this blog, please click here.

  • Fixing PCB in enclosure

    Step 2:




    If you’d like to subscribe to this blog, please click here.

  • Single Slope Integration ADC for Arduino

    Occasionally you might end up in a situation where your Arduino project need to measure an analog voltage such as a thermistor or a resistance change, but all your analog inputs are in use.

    Now, in this situation I would pretty much always suggest you purchase an external Analog to Digital (A/D) breakout board because they are so cheap and precise these days. But what if for some reason you can’t? Maybe you have to get this project done before one can arrive or you hit your budget limit, or, or… whatever.

    There’s a very simple technique to read some analog values that you can use when all you have available are digital inputs. I won’t go into the general theory behind analog to digital conversion since there are many good ones online already. However, I will briefly talk about Single Slope Integration.

    Single slope integration is a method of measuring a voltage by timing how long it takes that voltage to charge a capacitor in an R-C circuit. An R-C circuit is basically a circuit consisting of a single resistor and a single capacitor. You might remember that the voltage across the terminals of a capacitor takes time to build up. That instantaneous voltage is a function of the incoming voltage, the amount of capacitance, the resistance of the circuit and how long it’s been since the incoming voltage was applied. This last part is the bit we most care about. If we know that the capacitor is fully discharged, and we apply a fixed voltage to the input of the circuit, then the amount of time it takes that voltage to get to a specific threshold at the circuit output is a measure of the resistance value. In other words, if we keep the applied voltage constant, the capacitor value constant and the threshold constant, then the only variables are Time and the Resistance. So by measuring Time, we know resistance.

    We’re going to look at an application of this technique as it was used years ago. For reference, this is how the joysticks on the original IBM PC (vintage early 80’s) worked. That should tell you how long it’s been around.

    Now, before I go any further, I want to emphasize that the way we’re approaching this is not a precision measurement by any means. There are methods to make this measurement very accurate, but they generally will incur more cost than, you know, just buying an A/D breakout!

    This is our circuit:

    R1 is the resistance we want to get a relative value for, R2 is there to prevent damage to the Arduino pin when it tries to either charge or discharge the capacitor (a discharged capacitor looks like a dead short, so we want to limit the current going out the pin), and C1 is our capacitor. With the values shown, we should get roughly 10-bit resolution measuring a 10k ohm variable resistor.

    // Simple program to illustrate reading a resistor by using a single-slope
    // integration method
    
    // Pin 2 is used as our "analog input"
    // Connect R2 here
    #define ANALOG_PIN 2
    
    void setup() 
    {
      Serial.begin(115200);
      Serial.println("Ready");
    }
    
    void loop() 
    {
        // Start a reading
        pinMode(ANALOG_PIN, OUTPUT);
    	// Discharge capacitor
        digitalWrite(ANALOG_PIN, LOW);
    	// Wait for it to discharge
        delay(500);
        
    	// Snapshot the start of charging
        unsigned long start = micros();
    
    	// Use 500,000us as our timeout so this 
    	// doesn't hang if the resistor is disconnected
        unsigned long timeout = start + 500000;
        unsigned convEnd = 0;
    	
    	// Switch the pin to input so we can look for the
    	// transition from LOW to HIGH
        pinMode(ANALOG_PIN, INPUT);
    	
        while (convEnd = micros() < timeout)
        {
          if (digitalRead(ANALOG_PIN) == HIGH)
          {
    		  // Threshold reached, exit
              break;
          }
        }
        
    	// Resistance value is a function of the time it took
    	Serial.print("Value read: ");
    	// Print value read or timeout
    	convEnd != timeout ? Serial.println(convEnd - start) : Serial.println("TIMED OUT");
    }
    

    So the way this works is first we discharge the capacitor through the 100 ohm resistor on pin 2. The resistor is there to limit the current and not damage the arduino. After giving it 500mS to discharge, which is plenty, now we switch the pin configuration to Input and monitor it waiting for it to transition from LOW to HIGH. At this time, we break out of the loop and report the time difference between start and conversion end. This is proportional to resistance.

    For better performance, you can calibrate the software by using two known-value resistors in place of R1 to measure a min and max conversion time. Once you have that, you can interpolate between those values to measure any unknown resistor value.




    If you’d like to subscribe to this blog, please click here.

  • connect NV9 bill acceptor to your pc

    Bill acceptors and coin acceptors are used to take cash payments. They work by detecting certain denominations of bills or coins and provide an output signal that can be read by a computer. This allows your software to take cash payments. We’ve had a few inquiries from owners of the popular NV9 bill acceptor and how it can be interfaces using our counter systems.

    This is a quick note for those using the NV9 bill acceptor. As we mentioned in an earlier post, our PRT232 or IOCTL counters can give your PC the ability to record the cash value of bills inserted into a bill validator. Recall that the IOCTL232 is the same as the PRT232 but without an enclosure and at a lower cost. With the NV9 bill validator specifically, pins 1 & 16 on the main interface connector are used for the connection to the PRT232 “sensor” connector. Pin 16 is ground and pin 1 is the open-collector pulse output.

    The pulses are delivered at a rate of about 10 per second, which is well within the counting speed we support. The dollar values are sent as 1 pulse per dollar, e.g., a $1 bill produces one pulse, a $50 produces 50 pulses and so on.




    If you’d like to subscribe to this blog, please click here.

  • High speed counter and Encoder reader

    We are getting ready to release a new high speed counter that greatly simplifies machine to PC connections. 

    Feature set:

    • Read quadrature encoder pulses at up to a 20MHz rate.
    • Single-ended or differential pulse inputs.
    • USB data output provides count to USB or encoder to USB output.
    • USB connection for configuration.

    The device implements USB counter that is significantly faster than our existing ones and it is still compatible with the existing software interface.
    This counter has a maximum input pulse rate of 20MHz and will accept either a “standard” or Gray-code mode used for interfacing with quadrature encoders. You can now get a high speed quadrature encoder input read from your PC’s USB port. This new high speed interface is available in a choice of DIN-rail mount or standard wall/desktop mounting enclosure.

    Click the link below to be notified when the interface is available for the introductory $125 pricing. This price is only available for pre-orders.




    If you’d like to subscribe to this blog, please click here.