Led display multiplexing - MicroC

Discussion in 'Programmer's Corner' started by LauraB, Aug 16, 2013.

  1. LauraB

    Thread Starter Member

    Dec 15, 2011
    43
    0
    Hey

    I wonder if it's better to use Timer or just a delay? And why?
    I use Pic16f.
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    Use a timer driven interrupt to refresh the display. Using delays will prove problematic when you try to interleave processing tasks with display updates. Once you get the interrupts working, generate the segment pattern for each digit in its own char and let the interrupt refresh the display when its time. A 10ms refresh rate is a good place to start.
     
  3. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    Compiler manufacturers do offer that delay routine, but it's a trap for lazy programmers. If you always add a fast (several KHz) repeated clock interrupt to your code, you can do all kinds of things with it, and very often avoid using any other kind of interrupt completely.

    Anyway, "a 10ms refresh rate" is fine, but that means re-writing your entire display in that time. If you're using multiplexing for 8 digits, then you'd want an interrupt rate at 8 times that 100Hz frequency. So every 1/800 of a second, the processor would interrupt, load the data for one digit to the output pins, and turn on the appropriate digit. After another interval, repeat for the next digit. And so on.
     
  4. LauraB

    Thread Starter Member

    Dec 15, 2011
    43
    0
    Thank you for the answers. But then, is it better to use external driver for display, instead of refreshing all the time. And If the code is more complex, then I need to use priorities?
     
  5. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    Manufacturers of microcontrollers try to pack features into them, with the aim of making the chip capable of doing as much as possible without external hardware. So you wouldn't want to use an external driver if the processor could do the same job. On the other hand, a processor can't do everything--and handling significant amounts of electrical power is one thing they're never capable of. If this display is beyond what the chip can deliver, then of course you need additional hardware. You just have to do a design that maximizes what your processor does, and minimizes the parts you need to add. Or if you must have additional components, you want to match them to the chip in the most economical way.

    Complexity and priorities, those are what the game is all about!
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    You should not need an ext driver or priority interrupts for a basic muxed display. Start by sketching out the circuit. Rough out the code flow to output seg patterns while selecting the appropriate digit. Do one digit per interrupt. Even at moderate clock rates you'll have plenty of time to refresh the display and still get other processing done.

    It's not hard.

    Have fun.
     
Loading...