|
|
View previous topic :: View next topic |
Author |
Message |
hundil Guest
|
flashing on LCD when used float variables |
Posted: Mon Jun 21, 2004 9:04 am |
|
|
I use PCM ver 3.048 and 16F877. I can not add float variables cummulatively in the routine below, on the line it is stated.
It is compiling good but, the readings are flashing and some values are incorrectly printed on LCD.
LCD display is Hitachi HD44780 compatible with 16x2 characters.
Note: U may see some unused variables which are defined.
They are for other parts of the program.
thanks much in advance.
hundil
#include<16f877.h>
#include<stdio.h>
#device PIC16F877 *=16 ADC=10
#fuses XT,NOWDT,NOPROTECT, NOBROWNOUT,NOVLP
#use delay(clock= 4000000)
#include"_lcd.c"
float value_o= 0, akim_s ,value_i ,value,swtch, ort;
int
_i,s_swtch,_swtch=1,kk=0,hh=0,bb,SA=1,tx,TS=0,TA=0,OK=0,tmr1=0;
unsigned __swtch,SS_,_SA;
long int sayac=0,ii=0,counter=0;
static short print=false,sss=False;
static short rise_edge=TRUE;
int switch_fonk(void);
void stb_fonk(void);
#ZERO_RAM
#INT_TIMER1
void ornek_fonk()
{
if(rise_edge==FALSE){
++ort;
set_adc_channel(0);
delay_us(20);
value=Read_ADC();
value_i+=value; // the problem is here, cummulative addition is not possible! Is there any bug? (maybe)
value=0;
}
if(sss && rise_edge){
output_d(FALSE);
sss=false;
enable_interrupts(INT_RB);
disable_interrupts(INT_TIMER1);
}
}
#INT_EXT
void pass_fonk()
{
enable_interrupts(INT_TIMER1);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
if(rise_edge){
rise_edge=FALSE;
set_timer1(0xFC17);
value_i=0;
ort=0;
ext_int_edge(H_TO_L);
}
else
{
rise_edge=TRUE;
ext_int_edge(L_TO_H);
value_i=(value_i/ort) * 250.0/1023.0;
_i++;
if(_i==50){
if(TS==1 && TA ==1) printf(lcd_putc, "\f***SISTEM OK***");
printf(lcd_putc, "VI:%3ld " ,(long)value_i);
_i=0;
if(bb==1){
stb_fonk();
switch_fonk(); }
}
if(sayac<300) sayac++;
}
enable_interrupts(INT_TIMER1);
if(input(PIN_B0))
rise_edge=FALSE;
enable_interrupts(INT_EXT);
}
void main(void)
{
bb=0;
#asm
bcf 0x03, 6 // RP1
bsf 0x03, 5 // RP0
bcf 0x89, 4 // trise -> 0
#endasm
set_tris_b(0xFF);
//set_tris_c(0x80);
set_tris_d(0x00);
setup_adc(0xC1);
setup_port_a(0x82);
ext_int_edge(L_TO_H);
enable_interrupts(INT_EXT);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
disable_interrupts(INT_TIMER1);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
enable_interrupts(INT_RTCC);
enable_interrupts(global);
output_d(FALSE);
output_c(FALSE);
lcd_init();
delay_us(1000);
delay_us(1000);
do{
if(!sss ) ++counter;
delay_us(10);
}while(counter != 500 );
} |
|
|
hundil Guest
|
Re: flashing on LCD when used float variables |
Posted: Mon Jun 21, 2004 1:43 pm |
|
|
hundil wrote: | I use PCM ver 3.048 and 16F877. I can not add float variables cummulatively in the routine below, on the line it is stated.
It is compiling good but, the readings are flashing and some values are incorrectly printed on LCD.
If I use long or integer values, everything is OK on LCD
Please Help , Iam in trouble.
LCD display is Hitachi HD44780 compatible with 16x2 characters
Note: U may see some unused variables which are defined.
They are for other parts of the program.
thanks much in advance.
hundil
#include<16f877.h>
#include<stdio.h>
#device PIC16F877 *=16 ADC=10
#fuses XT,NOWDT,NOPROTECT, NOBROWNOUT,NOVLP
#use delay(clock= 4000000)
#include"_lcd.c"
float value_o= 0, akim_s ,value_i ,value,swtch, ort;
int
_i,s_swtch,_swtch=1,kk=0,hh=0,bb,SA=1,tx,TS=0,TA=0,OK=0,tmr1=0;
unsigned __swtch,SS_,_SA;
long int sayac=0,ii=0,counter=0;
static short print=false,sss=False;
static short rise_edge=TRUE;
int switch_fonk(void);
void stb_fonk(void);
#ZERO_RAM
#INT_TIMER1
void ornek_fonk()
{
if(rise_edge==FALSE){
++ort;
set_adc_channel(0);
delay_us(20);
value=Read_ADC();
value_i+=value; // the problem is here, cummulative addition is not possible! Is there any bug? (maybe)
value=0;
}
if(sss && rise_edge){
output_d(FALSE);
sss=false;
enable_interrupts(INT_RB);
disable_interrupts(INT_TIMER1);
}
}
#INT_EXT
void pass_fonk()
{
enable_interrupts(INT_TIMER1);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
if(rise_edge){
rise_edge=FALSE;
set_timer1(0xFC17);
value_i=0;
ort=0;
ext_int_edge(H_TO_L);
}
else
{
rise_edge=TRUE;
ext_int_edge(L_TO_H);
value_i=(value_i/ort) * 250.0/1023.0;
_i++;
if(_i==50){
if(TS==1 && TA ==1) printf(lcd_putc, "\f***SISTEM OK***");
printf(lcd_putc, "VI:%3ld " ,(long)value_i);
_i=0;
if(bb==1){
stb_fonk();
switch_fonk(); }
}
if(sayac<300) sayac++;
}
enable_interrupts(INT_TIMER1);
if(input(PIN_B0))
rise_edge=FALSE;
enable_interrupts(INT_EXT);
}
void main(void)
{
bb=0;
#asm
bcf 0x03, 6 // RP1
bsf 0x03, 5 // RP0
bcf 0x89, 4 // trise -> 0
#endasm
set_tris_b(0xFF);
//set_tris_c(0x80);
set_tris_d(0x00);
setup_adc(0xC1);
setup_port_a(0x82);
ext_int_edge(L_TO_H);
enable_interrupts(INT_EXT);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
disable_interrupts(INT_TIMER1);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
enable_interrupts(INT_RTCC);
enable_interrupts(global);
output_d(FALSE);
output_c(FALSE);
lcd_init();
delay_us(1000);
delay_us(1000);
do{
if(!sss ) ++counter;
delay_us(10);
}while(counter != 500 );
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 21, 2004 1:56 pm |
|
|
Are you trying to get people to notice your post ?
The reason I didn't respond (and probably others, too)
is because your variable declarations are a total mess.
Things you are doing wrong:
1. You have 10+ variables on one line.
2. You have tacked underscore characters onto your
variable names all over the place.
3. There are tons of variables with cryptic 2-character names.
I'm not trying to be mean-spirited, but your coding style
is so error-prone, that most people would just take a glance
at it, and immediately give up on trying to help you.
They were being polite, and so they didn't tell you this. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Mon Jun 21, 2004 5:00 pm |
|
|
The first thing I am wondering is how you get this to compile. There are two device definitions and that would keep it from compiling for me. That is in addition to the other things PCM pointed out |
|
|
hundil Guest
|
flashing on LCD with different readings |
Posted: Tue Jun 22, 2004 6:35 am |
|
|
dyeatman wrote: | The first thing I am wondering is how you get this to compile. There are two device definitions and that would keep it from compiling for me. That is in addition to the other things PCM pointed out |
DEAR DYEATMAN
Thank you very much for your polite reply.
As I wrote before my code, It was a part of the whole code.
The problem is that : When I use float variables (for 'value_i' AND 'value' variables) in the line of
value_i+=value;
this command is not adding correctly.
But in case of long OR integer definition , There is no problem with the above command. Every thing is OK in my program.
(I think )The other probability is :
There is something wrong with my printf command.
And I am sure that there is no two device definition in my code.
So you don't need to compile my partial code.
I am new at CCS programming and trying to write a long code unfortunately.
Please Help
sincerely
hundil |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Jun 22, 2004 6:49 am |
|
|
Try paring your code down to the smallest example that still exhibits the problem. It will then be easier for you and others to see what is going wrong. Often I look at the generated assembly code in the .lst file. The shorter the program the easier it is to understand the .lst file. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Jun 22, 2004 9:31 am |
|
|
PCM programmer is very experienced and most appreciate the opportunity to learn from him. I have learned much from him I am very grateful.
As to the issue you have to be aware that the PIC lives on CPU cycles.
Certain things Printf and float calculations especially float division consume large numbers of these cycles. All effort must be made to avoid consuming large numbers of cycles in an interrupt routine.
Float produces accurate answers within its 23 bit precision however when these numbers are converted to a different representation such as the decimal notation of everyday use some get surprised when a number like 0.1 displays as 0.099999. It is not an error it is an intrinsic property of number systems. even the decimal system notation has this issue EX 1/3 can't be written with total accuracy as 0.3333333.
As to coding style it is like handwriting if you want others to read your handwriting you have to try and make it neat and readable.
It is not much different when it comes to code. |
|
|
|
|
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
|