SSD flickers too much. How to fix the flickering?

Status
Not open for further replies.
Yes. I did that but it did not work. I used a 1 ms Timer interrupt and then placed all the SSD code inside interrupt routine but it did not work.

Please show how to use the timer, i.e., what timer interrupt should I use? There are delays in SSD code. Is it ok if I place SSD code with delays inside interrupt routine?

I did like this but it is still flickering. See attached file.
 

Attachments

  • Clock_a.rar
    206.9 KB · Views: 80
Last edited:

Is it ok if I place SSD code with delays inside interrupt routine?
Delays in interrupt routines are a no no. You'll want to advance the scan position one digit on each timer tick and don't linger around in the interrupt code.

This is a really basic embedded programming concept, used in all microcontroller powered devices with multiplexed displays since decades. I presume you can figure it out by thinking a bit about the problem.
 

Yes, but how much should be the timer interrupt value? 500 us?
Not really critical, I think. For faster scan rates, you probably want to modify the control sequence: disable the segments, switch the digit driver, enable the new digit code, to avoid crosstalk on undriven segments.
 
@FvM

Here is my interrupt code but it is not working. Still have the flickering. I tried, 1ms, 1.5ms, 2ms, 3ms for timer interrupt, but still it flickers.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Timer1
//Prescaler 1:2; TMR1 Preload = 30533; Actual Interrupt Time : 3.5 ms
 
//Place/Copy this part in declaration section
void InitTimer1(){
  T1CON  = 0x11;
  TMR1IF_bit     = 0;
  TMR1H  = 0x77;
  TMR1L  = 0x45;
  TMR1IE_bit     = 1;
  INTCON     = 0xC0;
}
 
void Interrupt(){
  if (TMR1IF_bit){
    TMR1IF_bit = 0;
     scanval++;
     if(scanval == 7)scanval = 1;
 
            switch(scanval){
         case 1:
     PORTB = 0x01;
     PORTD = CA[sec%10];
     break;
 
       case 2:
     PORTB = 0x02;
     PORTD = CA[sec/10];
        break;
        case 3:
     PORTB = 0x04;
     PORTD = CA[min1%10];
        break;
        case 4:
     PORTB = 0x08;
     PORTD = CA[min1/10];
        break;
        case 5:
     PORTB = 0x10;
     PORTD = CA[hr%10];
        break;
        case 6:
     PORTB = 0x20;
     PORTD = CA[hr/10];
        break;
  }
  }
  TMR1H  = 0x77;
  TMR1L  = 0x45;
  TMR1IE_bit     = 1;
}

 

Attachments

  • Clock_b.rar
    207.8 KB · Views: 88

I didn't understand. Explain clearly. Here is new simulation. If Time/Temperature button is pressed it shows either Time or Temperature.
 

Attachments

  • Clock Hex and Sim.rar
    29.1 KB · Views: 133

I didn't understand. Explain clearly.
Explain what? I guess you fixed the problem by blanking the segment outputs before switching the digit, as already suggested in post #6.

It would be better to have complete simulations with *.cof and source code that can be debugged at source level, as in your previous posts.
 

To clarify, here's a segment of your code:

case 2:
PORTD = 0; // I added FvM's first suggestion here, which I assume you've already done...
PORTB = 0x02;
// ...because without it, the previous digit #1 will be output to #2 and cause flicker for as long as it takes to perform...
PORTD = CA[sec/10]; // ...this, of which the division in particular may be relatively slow
break;

Each digit needs to be lit at least 100x per second, or more, to appear constant to the human viewing it.

However, the actual digits displayed don't change 100x per second. Thus FvM's 2nd suggestion to move the math, like divisions, outside the ISR; and compute them at a slower rate, or only as frequently as needed. Let's say you defined a second array CB, and did this in your main code loop, or perhaps using a timer:

CB[2]=CA[sec/10]; // precompute digit #2

Now the ISR can set that digit by doing only a simple lookup:

PORTD = CB[2]; // instead of CA[sec/10]

And since each digit is now handled the same from the ISR's point of view, the switch structure can also be eliminated, saving even more time.

Now while you may not actually need to minimize time spent in your ISR for this particular project, in others you will - so doing stuff like this is good practice.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…