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

pic stop working during float division?

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



Joined: 16 Mar 2009
Posts: 29

View user's profile Send private message

pic stop working during float division?
PostPosted: Sat May 14, 2011 9:18 am     Reply with quote

Hi. I have got a pic16f876 (clock 20MHz). I need to count pulses on rb4 and rb5 and do some calculations.

When arrives too many pulses the pic stop working. why?

Thanks

Code:

#include <main.h>
#include "flex_lcd_16x2.c"

unsigned  int16 cicliA = 0;
float portataA = 0;
unsigned int16 cicliB = 0;
float portataB = 0;


#int_RB
void detect_rb_change()
{
   int current;
   static int last = 0;

   set_tris_b(0xF0);
   
   current = input_b();

   if((!bit_test(last,4))&&(bit_test(current,4)))
      cicliA++;
   else if((!bit_test(last,5))&&(bit_test(current,5)))
      cicliB++;

   last = current;
}

void main()

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
   
   lcd_init();
   delay_ms(600);
   
   printf(lcd_putc, "\f");
   
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);

   while(1)
   {
      delay_ms(1000);

      portataA = (float) cicliA / (7.5);
      portataB = (float) cicliB / (7.5);

      lcd_gotoxy(1,1);
      printf(lcd_putc, "A: l/min: %lf         ", portataA);
      lcd_gotoxy(1,2);
      printf(lcd_putc, "B: l/min: %lf         ", portataB);

      cicliA = cicliB = 0;
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 14, 2011 1:39 pm     Reply with quote

Quote:
When arrives too many pulses the pic stop working. why?

Describe the pulses. What is the repetition rate of the pulses ? What is
the pulse length ? Is it the same pulse length for all pulses ?
What are the voltage levels (high and low) of the pulses ?


Quote:
When arrives too many pulses the pic stop working. why?

What specifically does this mean ? Does it mean the display is not updated ?
adalucio



Joined: 16 Mar 2009
Posts: 29

View user's profile Send private message

PostPosted: Wed May 18, 2011 1:57 am     Reply with quote

Solved with this code. thanks

Code:

#include <main.h>
#include "flex_lcd_16x2.c"

unsigned  int16 cicliA = 0;
float portataA = 0;
unsigned int16 cicliB = 0;
float portataB = 0;


#int_RB
void detect_rb_change()
{
   int current;
   static int last = 0;

   set_tris_b(0xF0);
   
   current = input_b();

   if((!bit_test(last,4))&&(bit_test(current,4)))
      cicliA++;
   else if((!bit_test(last,5))&&(bit_test(current,5)))
      cicliB++;

   last = current;
}

void main()

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
   
   lcd_init();
   delay_ms(600);
   
   printf(lcd_putc, "\f");
   
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);

   while(1)
   {
      delay_ms(1000);

      disable_interrupts(INT_RB);
      disable_interrupts(GLOBAL); 

      portataA = (float) cicliA / (7.5);
      portataB = (float) cicliB / (7.5);

      lcd_gotoxy(1,1);
      printf(lcd_putc, "A: l/min: %lf         ", portataA);
      lcd_gotoxy(1,2);
      printf(lcd_putc, "B: l/min: %lf         ", portataB);

      cicliA = cicliB = 0;

      enable_interrupts(INT_RB);
      enable_interrupts(GLOBAL);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed May 18, 2011 2:58 am     Reply with quote

and the reason is, that the pulses are coming in faster than the arithmetic can be handled (hence PCM programmers questions about rate....).

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
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