|
|
View previous topic :: View next topic |
Author |
Message |
adalucio
Joined: 16 Mar 2009 Posts: 29
|
pic stop working during float division? |
Posted: Sat May 14, 2011 9:18 am |
|
|
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
|
|
Posted: Sat May 14, 2011 1:39 pm |
|
|
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
|
|
Posted: Wed May 18, 2011 1:57 am |
|
|
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: 19515
|
|
Posted: Wed May 18, 2011 2:58 am |
|
|
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 |
|
|
|
|
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
|