Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Best way to designa a real-time LED driver

Status
Not open for further replies.

shsn

Junior Member level 3
Joined
Nov 28, 2012
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,523
Hello,

I have been working on a design that drives 8 individual LEDs driven by a PIC16F716. The design works by converting an incoming voltage that varies from 0 to 5V using ADC and depending on this analogue voltage input I have programmed it to turn on X LED(s). For instance, at 4.5V 6 out of 8 LEDs are turned on. Although it works well the response is not so good considering it will be used in time-critical environment (measuring engine RPM speed) -- I did more reading and came up with two alternative ways to re-design the current design.

1. Use Interrupts.

The current design's program uses 'Polling' method with a bunch of IF statements that has following routine:
- Check the converted ADC value
- Go through IF statement for matching ADC value
- Turn LED(s) on

So if I am not mistaken I can take 'turn LED(s) on' part outside the main routine to interrupt, this way it will not 'turn on LED(s)' unless it detects changes in ADC value.

2. Use MAX7221 driver using Serial interface

I am not too sure about this but the ability to drive 64 individual LEDs might come in handy. But the question I want to ask with this method is, will the LEDs have more faster response time than simply using 16F877A with interrupts?

Thank you.
 

the response is not so good considering it will be used in time-critical environment
I'm not so sure using interrupts will make any difference, if your current code is just doing the tasks that you mention.
The 'if' statements, and the turning on of LEDs is extremely fast. And if anything, using a MAX.. driver will merely
slow things down further.
I suspect your ADC routine may have delays which are unrealistic (this is just a guess). You could try to reduce the delay
to a more realistic value according to your microcontroller datasheet.
Otherwise, you could implement in an interrupt routine which gets executed by the 'ADC conversion complete' interrupt
(assuming such a thing exists in your microcontroller that you're using).
 

Hi sky_123,

I too was wondering the same thing regarding to using MAX7221 driver, as that IC will need to process the incoming serial data which will add 'time' to process the instructions. Currently this is the code loaded on to the PIC16F716; I'm not too sure about "ADC routine delay", but if you could point out any better way of programming the instructions please feel free point out.

Code:
unsigned int adc_val;
 
void main() {
    TRISA = 0;
    TRISB = 0;
    PORTB = 0;
 
    do {
        if (adc_val >= 0 && adc_val <= 18) {
            PORTB = 0b00000000;
        }
        else if (adc_val > 18 && adc_val <= 36) {
            PORTB = 0b00000100;
        }
        else if (adc_val > 36 && adc_val <= 67) {
            PORTB = 0b00001100;
        }
        else if (adc_val > 67 && adc_val <= 87) {
            PORTB = 0b00101100;
        }
        else if (adc_val > 87 && adc_val <= 118) {
            PORTB = 0b00111100;
        }
        else if (adc_val > 118 && adc_val <= 138) {
            PORTB = 0b01111100;
        }
        else if (adc_val > 138 && adc_val <= 169) {
            PORTB = 0b01111110;
        }
        else if (adc_val > 169 && adc_val <= 189) {
            PORTB = 0b11111110;
        }
        else if (adc_val > 189 && adc_val <= 220) {
            PORTB = 0b11111111;
        }
        else {
            PORTB = 0;
            delay_ms(120);
            PORTB = 0b11111111;
            delay_ms(120);
        }
    }
    while(1);
}

Thank you :)
 

The if..else instructions take no time at all. It's the delay_ms function that is causing it. You're delaying by 240msec, which is a quarter of a second.
You need to reduce that, or check the ADC conversion register (I'm not familiar with PIC, but the user manual will contain this info) or rely on an ADC conversion complete interrupt.
 
  • Like
Reactions: shsn

    shsn

    Points: 2
    Helpful Answer Positive Rating
Yes, I looked into SPI and it seems it'd rather increase the response time so I decided to stick with IF statements.
Thank you :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top