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 CCS Technical Support

7 segment display off while executing modbus

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
td



Joined: 16 Apr 2015
Posts: 21
Location: India

View user's profile Send private message

7 segment display off while executing modbus
PostPosted: Tue May 19, 2015 6:41 am     Reply with quote

hi,
In our project we are using 18f4620 controller, ccs compiler 4.119, 3 common cathode 7segment displays, modbus(rs 485).
If we are not using modbus, the 7segment is working properly. If we add code for modbus and read the holding registers, the display is blinking. ie, if modbus code is executed, then the display will be off for approx 1 sec. We directly use modbus driver file.
Code for reading hold register is

Code:
 if(modbus_kbhit())
         {
         
            delay_us(10);
         
         //check address against our address, 0 is broadcast
         if((modbus_rx.address == MODBUS_ADDRESS) || modbus_rx.address == 0)
         {
         
                 
            switch(modbus_rx.func)
            {
             
             case FUNC_READ_HOLDING_REGISTERS:
             case FUNC_READ_INPUT_REGISTERS:
               if(modbus_rx.data[0] || modbus_rx.data[2] ||
                  modbus_rx.data[1] >= 15 || modbus_rx.data[3]+modbus_rx.data[1] > 15)
                  modbus_exception_rsp(MODBUS_ADDRESS,modbus_rx.func,ILLEGAL_DATA_ADDRESS);
               else
               {
                  if(modbus_rx.func == FUNC_READ_HOLDING_REGISTERS)
                     modbus_read_holding_registers_rsp(MODBUS_ADDRESS,(modbus_rx.data[3]*2),hold_regs+modbus_rx.data[1]);
                  else
                     modbus_read_input_registers_rsp(MODBUS_ADDRESS,(modbus_rx.data[3]*2),input_regs+modbus_rx.data[1]);
                     
                 
                  event_count++;
               }
               break;

default:    //We don't support the function, so return exception
                  modbus_exception_rsp(MODBUS_ADDRESS,modbus_rx.func,ILLEGAL_FUNCTION);
            }
            }
         


How can we over come the blinking (display off) problem?
please help
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue May 19, 2015 9:40 am     Reply with quote

I don't know for sure, but here area few ideas:

MODBUS receive is done using interrupts. So should cause few problems.

MODBUS send, in other words responses, are blocking. That means the routine only returns when the whole message has been sent. but message sending should not normally take anywhere near as long as a second.

Sending may take much longer if there's a problem on the bus and it has to do many retries. That can happen if the bus bias is wrong. It can happen with a bus without biasing resistors, or with them connected to the wrong lines.

The MODBUS code uses timer two. If your also uses timer two then there will be clashes. If you use clock ticks from timer two, and my code often does, then it will not work with MODBUS code.
Do NOT use timer two in code that includes MODBUS. Also the MODBUS driver can not set up timer two to the required time if the processor is greater than 20MHz. It is possible to modify the driver to work up to 64MHz, but not higher than that. 24s and dspics, that have faster processors, have a different MODBUS driver.

My best guess would be that you are driving the display by a routine linked to timer two, and that is getting messed up - completely altering the timing - by the MODBUS code. That is a guess, as you haven't shown your display driving code.

I also don't see any need for the 10us delay after checking modbus_kbhit. When a message arrives, you need to process it as soon as possible.

Even if everything's working correctly, the time taken to in blocking calls to MODBUS response routine will probably cause some flicker or un-even brightness.
td



Joined: 16 Apr 2015
Posts: 21
Location: India

View user's profile Send private message

PostPosted: Tue May 19, 2015 10:42 pm     Reply with quote

thanks for reply

but in our program we are not using timer.

Quote:

Even if everything's working correctly, the time taken to in blocking calls to MODBUS response routine will probably cause some flicker or un-even brightness.


is there any way to avoid the flicker in 7seg display due to modbus (delay)?
Ttelmah



Joined: 11 Mar 2010
Posts: 19480

View user's profile Send private message

PostPosted: Wed May 20, 2015 12:54 am     Reply with quote

Simple question. _How_ are you doing the display timing?.

If you are not using a timer, and a timer interrupt, then what is happening, is basically 'inevitable'.
td



Joined: 16 Apr 2015
Posts: 21
Location: India

View user's profile Send private message

PostPosted: Wed May 20, 2015 2:54 am     Reply with quote

We are using the display function in program.
Code:
                         
void displayOn7Seg(int8 d1,int8 d2,int8 d3)
{
   int8 number=0;
   while(number<25)
   {
      //restart_wdt();
     
     
      delay_us(10);
      output_d(d3);
      delay_us(500);
      output_high(PIN_E0); 
      delay_us(100);
      output_low(PIN_E0);

      output_d(char_blank);

      delay_us(100);
      output_d(d2);
      delay_us(100);
      output_high(PIN_E2); 
      delay_us(100);
      output_low(PIN_E2);

output_d(char_blank);
 
delay_us(100);
      output_d(d1);
      delay_us(100);
      output_high(PIN_E1); 
      delay_us(100);
      output_low(PIN_E1); 

 
     
     
     
      delay_us(100);
      output_d(char_blank);
       delay_us(100);
      number++;
   }
   output_d(char_blank);
}


This is the function for 7 segment display.

If we are not using modbus, no flicker in display. If modbus code included, flickering starts.

How the timer can be used to drive the segment?


Last edited by td on Wed May 20, 2015 3:30 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19480

View user's profile Send private message

PostPosted: Wed May 20, 2015 3:29 am     Reply with quote

This approach does not allow your machine to do _anything else_ while displaying.....

Even something like performing maths _is_ going to have the display flickering.

You need to re-think.

You need a display 'tick' interrupt, otherwise _every_ other operation _will_ interfere with the display.
Look at Mike's code in this thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=47508&highlight=segment+interrupt>

There are many other similar threads that may give you an idea of how to do this.
td



Joined: 16 Apr 2015
Posts: 21
Location: India

View user's profile Send private message

PostPosted: Thu May 21, 2015 6:35 am     Reply with quote

i have used timer for display .then also display is blinking while connecting to modbus.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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