Advertisement

Blog

PIC (& Software) 1, Op-Amps 0

I have a current project that requires sensing an analog voltage, and turning on an LED when each of three thresholds is reached. The analog voltage relates to a detected RF power level (in the 50 to 100 watt range, at HF), and the whole circuit is powered by scavenging a little bit of the RF power and making some dc from it. I need about 100 of these boxes. Cost is an issue.

I found a circuit as prior art that used a quad op-amp to make the comparators, and bunch of resistive dividers to set the thresholds. Simple enough, and cheap. I'm kind of busy at the moment and had another engineer take a look at it and whip something up based on the original circuit. This engineer is pretty good, but does more digital and software than analog. He has a small sideline business selling a PIC microcontroller-based product that he designed to hobbyists.

The cost of a couple of quad op-amps, regulator, reference, and 20 or so resistors is within the budget; parts cost is not much over a dollar.

A few things changed from the prior art. The old circuit had one active channel; the new version needs two. There was concern about whether the circuit would power up fast enough to settle to reasonable accuracy soon enough without latching up if the input was ready before the supply voltage. A layout bug got the hysteresis backwards on the comparators. And the designer was having trouble getting the accuracy he wanted once he worst-cased the tolerances on the resistors, reference, etc.

So he eased into his comfort zone and threw a PIC at it.

One chip for each channel. One resistive divider to get the dc representing the RF power down to a manageable level (the coupler delivers around 10V for 100W). The PIC he used has an on-chip reference, enough outputs to drive the LEDs, and (of course) programmable threshold points (with hysteresis easily added in software). It also has a brown-out feature to allow well-behaved startup and power-down.

I was nervous about going this way, since anything with software in it is just too easy to keep revising and revising and never get finished. And I was not sure of the cost impact. But in this case it looks like the right choice. The software came up on the first try and does what we need. The designer is a lot less stressed. The PIC-based design was done faster than the revision to the analog-based design. And the cost? (Drum roll.) Still not much over a dollar, and well within the budget.

This was a lesson for me on several levels. I am still wrestling with the idea that it can make sense to replace a simple analog circuit with a microprocessor and software. It's not always the right solution, but in the overall discussion of analog integration, perhaps there are a lot of low- to moderate-accuracy and low- to moderate-bandwidth problems that are well solved this way. This is especially true when the design staff is more comfortable with the digital approach. “Impedance matching” the staff to the job is important.

The rest of the story is that the enclosures and connectors make up much more of the total cost than the electronics. Some of us can still recall when boxes and connectors were cheap and electronics was expensive. But that's another story for another day.

25 comments on “PIC (& Software) 1, Op-Amps 0

  1. Dirceu
    May 24, 2013

        I needed to redesign an extruder for residues of roasted coffee beans at the request of a customer. There was a three-phase motor (60 Hz fixed) responsible for turning the endless screw, being necessary to measure its instantaneous power. The original machine used a 68HC11 and three-phase power was obtained by multiplying current and voltage (two wattmeter method) using a couple of AD633 (analog multiplier). The resulting signal entered on the processor ADC.

       As the required bandwidth is low and were available several fast and low cost processors and DSPs, I decided to make an upgrade using a Microchip DSPIC with all analog stuff inside (including ADC with two simultaneous Sample an Hold). The multiplications and sums would be performed by software. In my case was a positive result, because some processor peripherals were leveraged to implement other system functions (with reduction in BOM and cost).

  2. DEREK.KOONCE
    May 24, 2013

    With the MicroChip PIC controller line becoming more mature and manufacturing costs being reduced due to scale, the move from analog to digital-analog is gaining momentum. TI has jumpped in as well as several other analog companies. They see the need to move to the digital realm… so long as the overall response time is not critical. As speed of the digital products increase, these products are finding more uses.

    I am now refreshing my programming skills in preparation for starting to use these types of devices.

  3. Brad Albing
    May 24, 2013

    Altho' it pains me to admit it, sometimes it's better to use the more “digital-intensive” method to solve design problems. This 3-phase power measurement is just such an example.

  4. Brad Albing
    May 24, 2013

    As I mentioned in response to Dirceu's comment, there are times when you ought to use more digital + S/W. I also mentioned it here:

    Analog Engineers Write Code! Or Maybe Not

    I'll have to learn me some of the code writing stuff.

  5. Scott Elder
    May 24, 2013

    Doug's design problem is a great example of what is wrong in analog design.  Analog designers and analog design companies complain that there are not enough people pursuing analog.  Well, that's because it is hard and if there is an easier, acceptable way to solve a hard problem that is how it will be solved.  Analog be damned.

    When I was working on an FPAA design a while back I asked myself “Who is actually going to design with a complex analog part when it exists?”  The answer is no one. Or, not enough to make it worthwhile.  So what's the point?

    Does the existance of MATLAB turn non-mathematicians into mathematicians?  Still have to know mathematics regardless of working on paper or typing code.

    I'll bet if an analog designer sat down for a while with Doug's problem, they could find a way with using just logic on a microncontroller to solve the problem.  No need for $1+ microcontrollers with comparators or ADCs or etc.  For example, a DAC is nothing more than a digital clock divider signal sent into an RC filter.

     

     

  6. RedDerek
    May 24, 2013

    I will have to post about a design I was involve with some 20 years ago as an analog versus digital approach. Brad, it is being assembled as thoughts now, with finishing later.

  7. Brad Albing
    May 24, 2013

    I'm looking forward to that – and will also ponder Scott's thoughts on the topic to see what I can come up with.

  8. Scott Elder
    May 24, 2013

    Hey Brad — Here's a thought.

    Take an R-C divider from the 10-100W power signal source and tie it to a digital IO pin.  Take another R-C divider from the microcontroller VDD to another digital IO pin.  Now just drive the IOs low, let them float back high, and count time till the digital transition interrupts occur.  Compute the time difference and use that information to calculate the voltage.  Time domain ADC.  About 4 Rs (may need to divide the signal down) and 2 Cs and 2 digital IO pins on a 40 cent microcontroller.

    For a visual indication, 10ms delay is probably okay.

    That's the problem with these reconfigurable analog parts with low performing analog.  Once the performance is so low, you can just solve the problem without analog.

  9. Brad Albing
    May 24, 2013

    Instead of the quad op-amp, I would have used a quad comparator – LM339. That and five resitors for the divider chain and you're pretty much done.

  10. Brad Albing
    May 24, 2013

    I sort of had that idea in mind – but not completely formed. You clarified it for me. It's sort of like using a DAC as an ADC by putting some additional cktry around it.

  11. David Maciel Silva
    May 27, 2013

    Soon after the technological advancement in the question microcontrollers, there is integration between analog and digital peripherals.

    For many this is still a big dilemma, because when you choose a new technology there is a learning curve, which varies from person to person.

    The oldest are more analog and have greater confidence in the products, the younger defend the theory of microcontrollers and peripherals that integrate. Who is right?

    Due to market competitiveness and are arranged so that new technologies, a microcontroller can be the best option considering in costs, on the other hand if a new technology, development time can become great.

  12. Brad Albing
    May 28, 2013

    Or perhaps I should have said putting the DAC around some additional cktry – i.e., in a feedback loop of an op-amp.

  13. Brad Albing
    May 28, 2013

    Still, if you screw up the divider chain, you will need to recalculate and warm up the soldering iron. So that part would be easier to fix in software/firmware.

  14. Brad Albing
    May 28, 2013

    >>…when you choose a new technology there is a learning curve …. That's always the case – so you need to take the attitude that the learning curve is part of the NRE associated with the project. Just part of the f ixedcost of doing a new design.

  15. JeffL_#2
    May 29, 2013

    1. In some ways nowadays it's really a three-way choice because you also have the option of an FPGA and writing some VHDL. Now I haven't seen many gate arrays with so much as an internal comparator for internal analog so it's perhaps a weak option for that reason, but these chips have so many gates available you can craft more than one DSP inside them, on that scale you can imagine how tiny a simple MCU would be, the level of integration you could get is pretty awesome (assuming you need that of course). If we all had access to libraries of reliable open-source VHDL that included pre-tested MCUs, that option could be a serious game-changer.

    2. I've always found that it's when you really need time- or frequency-based selection that the MCU option really takes over versus analog. Even the supposed “trash” +/-1% internal oscillator options are so much more precise than you can get with “precision” analog, especially when you do at least 16-bit math (Timer 1 for PIC, use capture mode and that can be extended as far as you like using the overflow interrupt). If you're working with moderate frequency RF you might need a simple external prescaler but you still get a “bargain” in terms of accuracy versus parts cost. 

    3. The use of LEDs can be an issue in itself especially when you're “scavenging” power, you need both a minimum voltage AND a certain amount of current available. It could be handy if there were something available more like LCD teechnology (ultra-low current) without the drive complexity and both cost- and space-effective for simple go/no-go indications but I haven't seen much out there.

  16. Brad Albing
    May 29, 2013

    @JeffL_2 – just a partial response to your point #1: The use of an FPGA could be made to functionally solve this design problem (probably), but I'm guessing even the cheapest FPGA would wreak the budget of this particular product's design.

  17. JeffL_#2
    May 29, 2013

    Really? A Xilinx Spartan-3A with 100 pins and 50K gates is $6.12 quantity 1 at Digikey. I'm not familiar enough with the technology to know EXACTLY how much “stuff” that translates to but it was kind of my specific intent to raise the premise that the “bottom fell out” (sort of) of the price structure while most folks who weren't thinking about it weren't looking. In many ways most of us aren't particularly well prepared to address incorporating parts like this because of the rather steep learning curve of  the tools and so forth, but be honest, THAT'S not the fault of the wizards who come up with these parts, is it now? Time to learn new ways to do things maybe? Just wondering out loud…

  18. jkvasan
    May 30, 2013

    Doug,

    It is a thorough account you have given, about the whole case. I guess there is nothing blasphemous(?) about deploying a mcu in place of an analog circuit. However, the same techniques may not apply to , say, amplifying a signal in the order of micro or nano volt without a proper instrumentation amplifier. Analog is closer to the real world, agreed yet on some occasions, it is street smartness which wins the title rather than skills.

  19. Hughston
    May 30, 2013

    Some ADCs let you set an interrupt when an input gets to a certain threshold. Is there a PIC that lets you do that? If so, then you could maybe just use on PIC and not two. If you are a good analog designer you could do an LTSpice simulation very quickly and check your analog design in less than an hour. You could use a tri-color LED to indicate multiple thresholds and that might also simplify the design but use more power.

    Analog approach: With single colored LEDs, the LED can be turned on by the voltage difference between the an op amp output and the op amp output above it in the chain. So as an op amp switches low, the LED gets powered by the output of the op amp above it in the chain. But when the next op amp in the chain switches, then the first LED turns off then the next one gets turned on. The last LED is powered from the positive supply rail. You need a cheap reference or a regulator. The regulator might have a power good signal out to enable the whole thing.

  20. Brad Albing
    May 30, 2013

    @JeffL_2 – Certainly for any number of designs, that FPGA would be good to use and would simplify the design and lower the BOM cost. I just meant in this case (Doug's design), it would not be cost effective – and by extension, in other fairly simple designs, an FPGA would not be cost effective. Altho' certainly one of the low-end PIC parts would be.

  21. Brad Albing
    May 30, 2013

    That stacked op-amp approach could work. I'm not sure if it's really any better than the approach that Doug ended up with. The PIC part does provide a quick and easy way to get the design that he wanted. And I say this even tho' I'm an analog guy from way back.

    Of course, my quad comparator (LM339) + single long resistor chain is good too. Especially with the clever way that I calculate the resistor values with respect the the required tap voltages.

  22. JeffL_#2
    May 30, 2013

    Right you are about the specific design, I was taking the opportunity to make the larger point.

    There's a bit more interesting discussion to have over my second point, whether or not it's relevant to this specific design would depend on how accurately the “limits” have to be measured and implemented. This relates to an assignment I had where I was working for an engineer who prided himself on his “out of the box” thinking. He was determined to do data conversion in whatever manner got him the best accuracy for the smallest dollar, high conversion speed was not particularly relevant. At the time A/Ds over 12 bits in resolution were horribly expensive, so in order to get the most accurate measurements he fed the voltage to be measured into a highly linear V/F converter, then measured the resulting frequency more or less as I outlined in my second point. Nowadays external 16-bit converters (assume SPI interface for simplicity) are fairly inexpensive (again assume single quantity), the AD7171 is running around $1.72, whereas a V/F with .01% linearity like the KA331 is still only $0.71, true it needs a one-point calibration, it may not be a runaway winner but it's pretty interesting that the approach is still at least competitive, isn't it?

  23. sonic012
    June 2, 2013

    Seriously guys, I've never seen so much discussion over a simple RF power threshold detector.

    Regards,

    Alex GB

  24. Brad Albing
    June 4, 2013

    If it's worth talking about, it's worth talking about a lot. Sometimes, even if it's not worth talking about, it's still worth talking about a lot. E.g.: Fox News; MSNBC.

    Too much is not enough.

  25. Chuck Sampson
    September 27, 2013

    I think, in my humble opinion, whether or not the analog solution is difficult or easy depends on the designer's experience. If you give what is basically a digital problem to a software guru, you're going to get a software solution. 

    As an analog designer, I would never think of using an op amp for a comparator. I like the lm339. It's pretty cheap and fast. The lm4030 has a 0.05% initial accuracy with 75 ppm temp drift. 0.1% resistor are pretty cheap nowadays. 

    I know one thing for sure, using mcu comparators for responding to fault thresholds like over-voltage and over-current is bad idea. The power fets are blown way before the mcu has figured out the voltage is too high.

    I find it somewhat weird that the software guys would want to even bother with coding up such a simple circuit. The guys I work with are always asking me to stick some “glue logic” on the design so they don't have to mess with it. 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.