Electronic Design

  
Reprints     Printer-Friendly    Email this Article    RSS        Font Size     What's This?


[Ideas For Design]
Code Improves Display Stability For DC Signals With Large Ripple

Jorge M. Briseno  |   ED Online ID #9285  |   December 16, 2004


Sometimes, dc signals from physical parameters (temperature, current, voltage, etc.) may show a little variation in time caused by electromagnetic interference, or even by its own nature. For example, in dc power plants, even high-frequency rectifiers deliver a 0.2-V ripple when managing large loads. This signal variation is observed when an MCU displays its own (or external) analog-to-digital converter's (ADC's) sample conversions taken at different times. The figure shows a dc signal that has variations in time. If the samples are taken at t0, t1, t2, t3, t4, etc., and every sample is displayed on an LCD, the user might not know the measured signal's real level.

This instability may look like a system failure and cause uncertainty of the real measured value. A low-pass filter can solve this problem in some cases. But for others, such as when hardware is limited by pc-board space or budget, the best choice is to average the signal. This is accomplished by taking many samples and dividing the sum by the number of samples. The average of N samples of a parameter X is:

where Xi is the i-th sample taken from the parameter X, and N is the total number of samples.

Adding 10-bit numbers is made easy because they can be divided in two registers. Whenever a carry occurs in the addition of the two least significant bytes, the most significant byte must be incremented.

In some 8-bit RISC-based MCUs, there's no instruction available for performing arithmetical divisions. In principle, any number can be divided by 2 just by rotating its binary representation to the right. For example, the number (14)10 = (1110)2, then (14/2)10 = (7)10 = (0111)2. Similarly, it's possible to divide any number by 4, 8, 16, 32, and so on. In this case, particularly for Microchip's PIC MCU family, a short subroutine can solve this obstacle (see the code listing).

The first nine lines are an example of a source code that uses the subroutine "Average" to calculate the average of 64 samples taken from a particular ADC's channel (channel 3 in this case). As shown, these nine lines can be used similarly to call the same subroutine to calculate the average of any other channel by just changing the value of the constant defined in line 5.

The subroutine "Average" first calls a delay used to adjust the time taken to convert the 64 samples. It's recommended to take the 64 samples in a time that equals a multiple of the ripple's period. If the ripple isn't so large, this subroutine can be omitted. The best results occur if TEMPO is calculated as follows:

TEMPO ~ 1/64 mTR

where m is an integer and TR is the period of the ripple in seconds.

From line 10 to 18, the sum of the samples is made. The whole subroutine might be as short as that, because the average final result will be contained in registers AddM (the 8 most significant bits) and AddL (the 2 least significant bits), when the condition in line 17 will make the PC counter skip to line 19. If the programmer has a subroutine to convert binary to BCD (typical format to display characters in LCD) that may work with the actual result, then the code in line 35 shall be written in line 19 to exit the subroutine.

From line 19 to 34, the subroutine just shifts the result of the average in such a way that the eight least significant bits are stored in register LSB, and the two most significant are stored in register MSB, which is more likely to convert to BCD. The final result will be a steady, fixed, and more reliable reading on the screen, LCD, or seven-segment display.


Reprints   Printer-Friendly  Email this Article  RSS    Font Size   What's This?


  • A New Design Inflection Point
  • Forecasting Industry Growth For 2009 And Beyond
  • EDA Retools To Exploit Multicore Architectures
  • Design And Verification Move Up In Abstraction
  • EDA Retools To Exploit Multicore Architectures
  • A New Design Inflection Point
  • Design And Verification Move Up In Abstraction
  • Challenges Lurk For 22-nm Physical Implementation
    1) Build A Smart Battery Charger Using A Single-Transistor Circuit
    (260 views today)
    2) 1-A Switching Regulators Operate With 96% Efficiency To Replace Linear Regulators
    (105 views today)
    3) 2008 BEST Electronic Design Winners
    (99 views today)
    4) Microcontroller-Based Sine-Wave Generator Has Crystal Accuracy
    (91 views today)
    5) What's All This Transimpedance Amplifier Stuff, Anyhow? (Part 1)
    (89 views today)
    ALL TOP 20



    Reader Comments

    it is very useful for basic embedded projects

    Anonymous -February 25, 2006   (Article Rating: )

    POST YOUR COMMENTS HERE
    Name:

    Email:
    Your Comments:

    Enter the text from the image below


    Please refresh the page if you have trouble reading this text.

    Search Electronic Design
         
      
     
    Email Newsletter
    Sponsored By:
    Electronic Design UPDATE provides readers with late-breaking news, opinions from industry experts, and timely technology stories. It's a unique opportunity to get your product message in front of engineers, engineering managers, and corporate managers while they're reading about critical information online.

    Enter Email to Subscribe
      

    Electronic Design Europe Electronic Design China EEPN Power Electronics Auto Electronics Microwaves & RF
    Mobile Dev & Design Schematics Find Power Products Military Electronics EE Events Related Resources