CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Need logical help for Seven segment display
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hemnath



Joined: 03 Oct 2012
Posts: 228
Location: chennai

View user's profile Send private message

PostPosted: Thu Nov 21, 2013 1:52 am     Reply with quote

Hi Ttelmah,
Yes you are right. It is very easy to display SSD. But it would consume more power when all leds are ON.

In my case, i want to reduce the power consumption. At one time, only one led should be ON. So i tried to use the method of charlieplexing.

As you suggested, i tried to display the 7 segment in the isr itself. But still led's are blinking.
Ttelmah



Joined: 11 Mar 2010
Posts: 19255

View user's profile Send private message

PostPosted: Thu Nov 21, 2013 2:13 am     Reply with quote

The single LED drive approach, shouldn't really make any difference.
I've done matrix displays (32rows, by 32 columns), with similar requirements (so you light just one line at a time), and provided the individual row update is faster than perhaps 60 or 70Hz, the blinking is not noticeable (some people see it out the corner of their eyes at this sort of rate). I'd wonder if you actually have a more basic problem somewhere.
Reasons for blinking:
LED being held on longer or shorter than the others.
Update not at a steady rate (hence the comment about doing it in the interrupt).
Update rate is not as fast as you think (have you tested.s the chip is running at the clock rate you think, and that the waveforms do change at the interval expected)?.
If you are doing something like a count, then keep the update of this synchronous to the display update.

Is the blinking on the whole display, or just part?.
Any pattern to 'when' it happens (relative to what else the chip is doing)?.

As a comment, look at timings. For instance, you use the approach of rotating a value from the array, and repeatedly accessing it from the array. It is very much faster to read values like this once, and do all accesses to this local variable, rather than the array.
Then look at your clock rate. 1MHz, is only 250Kips. Just a single array access, takes typically a dozen instructions. Calling an interrupt handler, and returning about 60 instructions. Even a single 8bit integer addition, takes a handful of instructions. With 7 display lines to drive, you need individual lines to update at perhaps 500* per second, which gives only around 500 instructions between updates. I'd suspect you should look to running the CPU noticeably faster. The extra power needed will be tiny (uA).

As some more comments:
Code:

            value = temp_value | 0b00000000;

What do you think this does?.
Sit down, and 'OR' a few values with zero, and see what this does.
Then:
Code:


         value1 = (0b00000001 << INCREMENT); 

Just generate a mask at the start of the loop, set it to one, and rotate it _once_ each time round. '<<increment', (rotating by a variable), gets increasingly slow as increment increases, so your high bit time will be very much longer than your low bit time... Not good.

Best Wishes
hemnath



Joined: 03 Oct 2012
Posts: 228
Location: chennai

View user's profile Send private message

PostPosted: Mon Nov 25, 2013 3:13 am     Reply with quote

Hi Ttelmah,
Below is the modified code
Code:
#include "18F2520.h"
#fuses INTRC_IO
#use delay(clock=1000000)

#use fixed_io(b_outputs=PIN_B4,PIN_B5,PIN_B6,PIN_B7)
 
const char DIGIT_ZERO[] =    {
                     //     gfedcba

                        0b11111110,       //   a
                        0b11111101,         //   b
                        0b11111011,         //   c
                        0b11110111,         //   d
                        0b11101111,         //   e
                        0b11011111,         //   f
                        0b11111111         //   g
                     };     

const char DIGIT_ONE[] =    {
                     //     gfedcba

                        0b11111111,       //   a
                        0b11111101,         //   b
                        0b11111011,         //   c
                        0b11111111,         //   d
                        0b11111111,         //   e
                        0b11111111,         //   f
                        0b11111111         //   g
                     };                           

const char DIGIT_TWO[] =    {
                     //     gfedcba

                        0b11111110,       //   a
                        0b11111101,         //   b
                        0b11111111,         //   c
                        0b11110111,         //   d
                        0b11101111         //   e
                        0b11111111,         //   f
                        0b10111111         //   g
                     };   

const char DIGIT_THREE[] =    {
                     //     gfedcba

                        0b11111110,       //   a
                        0b11111101,         //   b
                        0b11111011,         //   c
                        0b11110111,         //   d
                        0b11111111,         //   e
                        0b11111111,         //   f
                        0b10111111         //   g
                     };

const char DIGIT_FOUR[] =    {
                     //     gfedcba

                        0b11111111,       //   a
                        0b11111101,         //   b
                        0b11111011,         //   c
                        0b11111111,         //   d
                        0b11111111,         //   e
                        0b11011111,         //   f
                        0b10111111         //   g
                     };

const char DIGIT_FIVE[] =    {
                     //     gfedcba

                        0b11111110,       //   a
                        0b11111111,         //   b
                        0b11111011,         //   c
                        0b11110111,         //   d
                        0b11111110,         //   e
                        0b11011111,         //   f
                        0b10111111         //   g
                     };

const char DIGIT_SIX[] =    {
                     //     gfedcba

                        0b11111110,       //   a
                        0b11111111,         //   b
                        0b11111011,         //   c
                        0b11110111,         //   d
                        0b11101111,         //   e
                        0b11011111,         //   f
                        0b10111111         //   g
                     };

const char DIGIT_SEVEN[] =    {
                     //     gfedcba

                        0b11111110,       //   a
                        0b11111101,         //   b
                        0b11111011,         //   c
                        0b11111111,         //   d
                        0b11111111,         //   e
                        0b11111111,         //   f
                        0b11111111         //   g
                     };

const char DIGIT_EIGHT[] =    {
                     //     gfedcba
                        0b11111110,       //   a
                        0b11111101,         //   b
                        0b11111011,         //   c
                        0b11110111,         //   d
                        0b11101111,         //   e
                        0b11011111,         //   f
                        0b10111111         //   g
                     };

const char DIGIT_NINE[] =    {
                     //     gfedcba

                        0b11111110,       //   a
                        0b11111101,         //   b
                        0b11111011,         //   c
                        0b11111111,         //   d
                        0b11111111,         //   e
                        0b11011111         //   f
                        0b10111111         //   g
                     };

unsigned int16 value = 0, temp_value = 0, value1 = 0, count = 0;
unsigned int16 increment = 0, DIGIT_VALUE = 0;
int1 DIGIT_FLAG = 1;
int1 UP_FLAG = 1;
unsigned int disp_value1, disp_value2, disp_value3, disp_value4;
unsigned int16 DIGIT_VAL;

void display_value();
void digit(int16 DIGIT_VALUE);
void segment(int16 digit);

#INT_TIMER1
void timer1_isr()
{
   if(interrupt_active(INT_TIMER1))
   {
      count++;

      if(count > 6)
      {
         INCREMENT++;
         count = 0;
      }

      if(INCREMENT == 0)
      {
         output_b(0b00010000);      // 1st digit
         DIGIT(disp_value4);             //
      }   
         
      if(INCREMENT == 1)
      {
            output_b(0b00100000);
           DIGIT(disp_value3);   
      }
      
      if(INCREMENT == 2)
      {
            output_b(0b01000000);
           DIGIT(disp_value2);   
      }
      
      if(INCREMENT == 3)
      {
            output_b(0b10000000);
            DIGIT(disp_value1);   
      }

      if(INCREMENT > 3)
      {
         INCREMENT = 0;
      }

      set_timer1(0xFF05);         // 1ms for 1Mhz
      clear_interrupt(INT_TIMER1);
   }
}   

#INT_EXT
void ext_interrupt_isr()
{
   DIGIT_FLAG = 0;
}

#INT_EXT1
void ext_interrupt_isr1()
{
   UP_FLAG = 0;
}

void main()
{
   set_tris_a(0xFF);
   set_tris_b(0x00);
   setup_comparator(NC_NC_NC_NC);

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   set_timer1(0xFF05);       // 1ms for 1Mhz
   ext_int_edge(H_TO_L);
   enable_interrupts(INT_EXT);

   ext_int_edge(H_TO_L);
   enable_interrupts(INT_EXT1);

   #priority TIMER1, EXT, EXT1

   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   
   count=0;

   INCREMENT = 0;
   DIGIT_VALUE = 0;

      DIGIT_VAL = 1234;
      
      disp_value1 = (DIGIT_VAL%10);
      disp_value2 = ((DIGIT_VAL/10)%10);
      disp_value3 = ((DIGIT_VAL/100)%10);
      disp_value4 = ((DIGIT_VAL/1000)%10);

   while(1)
   {
   }
}


void DIGIT(int16 DIGIT_VALUE)
{
   
   switch (DIGIT_VALUE)
   {   
      case 0:   output_a(DIGIT_ZERO[count]);
            break;

      case 1: output_a(DIGIT_ONE[count]);
            break;

      case 2: output_a(DIGIT_TWO[count]);   
            break;

      case 3: output_a(DIGIT_THREE[count]); 
            break;

      case 4: output_a(DIGIT_FOUR[count]);
            break;      

      case 5: output_a(DIGIT_FIVE[count]);
            break;

      case 6: output_a(DIGIT_SIX[count]);
            break;

      case 7: output_a(DIGIT_SEVEN[count]); 
            break;

      case 8: output_a(DIGIT_EIGHT[count]);
            break;

      case 9: output_a(DIGIT_NINE[count]);
            break;      
   }
}


Whole display is blinking at very fast rate.
Seven segment display is of type Common Anode. So in the array, 0 means LED will be ON. 1 - OFF.

How can be done without using array?? Can you please help me.
thanks in advance Smile
hemnath



Joined: 03 Oct 2012
Posts: 228
Location: chennai

View user's profile Send private message

PostPosted: Mon Nov 25, 2013 11:08 pm     Reply with quote

I have changed the frequency to 2Mhz from 1Mhz. and isr to happen 250us. Everything is working great with PIC18F2520.

To reduce current consumption i have used PIC18LF2520. The same program is used in this device. segment b is not glowing at all. Why it is ? Please help .
Ttelmah



Joined: 11 Mar 2010
Posts: 19255

View user's profile Send private message

PostPosted: Tue Nov 26, 2013 1:37 am     Reply with quote

Possibly Cvref?.

You'd have to work out what pin is involved in driving this segment, but if Cvref is 'on', this overrides output on the pin. Most peripherals only override input, but this one overrides I/O.
I'd have thought it'd be segment c, not b, but you'd need to check, and make sure this peripheral is off.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group