| View previous topic :: View next topic |
| Author |
Message |
fiasgardone
Joined: 19 Jan 2010 Posts: 71
|
|
Posted: Wed Jan 20, 2010 6:49 pm |
|
|
PCM .. again tested the program down as you said, with the driver changed, and the LCD displays nothing!
slowly we get!
Code also changed.
| Code: |
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#include <flex_lcd.c>
// Tell the driver to use pins D0 and D1 for the i2c bus.
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
#include <DS1631.c>
//=================================
void main()
{
signed long result;
lcd_init();
init_temp();
while(1)
{
delay_ms(1000);
result = read_full_temp();
//printf(lcd_putc,"\f %ld", result);
}
}
|
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 20, 2010 7:34 pm |
|
|
It would be much easier to debug this program if you had rs232 output
from your board. Then you could put printf statements in the code to
follow the progress of the program, and to display diagnostic messages
on the terminal window.
It's not that easy with just an LCD display. |
|
 |
fiasgardone
Joined: 19 Jan 2010 Posts: 71
|
|
Posted: Thu Jan 21, 2010 7:24 am |
|
|
PCM .. My board does not have rs232 ! unfortunately!
I think that yesterday many tests, to the end, no longer runs it well.
So today I went to do further testing, and has an error that I do not understand!
In the program, if I compile as you said the compiler sends the following error message!
***Error14"testing DS1631.c" Line22(9,10): Missing #ENDIF
f I remove these two lines, the compiler compiles normal, but nothing shows on the LCD
| Code: |
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
|
I changed my DS1631 but the result is same. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 21, 2010 1:34 pm |
|
|
| Quote: |
if I compile as you said the compiler sends the following error message!
***Error14"testing DS1631.c" Line22(9,10): Missing #ENDIF
|
The ds1631.c driver in vs. 4.068 has a bug. It's missing the last #endif
statement. To fix it, edit the file and add the line shown in bold below:
| Quote: |
#ifndef DAL_SCL
#if defined(__PCD__)
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
#else
#define DAL_SCL PIN_B0
#define DAL_SDA PIN_B1
#endif
#endif
|
|
|
 |
fiasgardone
Joined: 19 Jan 2010 Posts: 71
|
|
Posted: Thu Jan 21, 2010 2:00 pm |
|
|
| PCM programmer wrote: | | Quote: |
if I compile as you said the compiler sends the following error message!
***Error14"testing DS1631.c" Line22(9,10): Missing #ENDIF
|
The ds1631.c driver in vs. 4.068 has a bug. It's missing the last #endif
statement. To fix it, edit the file and add the line shown in bold below:
| Quote: |
#ifndef DAL_SCL
#if defined(__PCD__)
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
#else
#define DAL_SCL PIN_B0
#define DAL_SDA PIN_B1
#endif
#endif
|
|
PCM .. I added the driver line you said, but the error continues?
I do not see ,why? |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 21, 2010 2:10 pm |
|
|
Maybe you have more than one ds1631.c file on your PC ?
Maybe you are editing one file, but MPLAB is using a different copy of it ?
Search your system for all copies of ds1631.c. |
|
 |
fiasgardone
Joined: 19 Jan 2010 Posts: 71
|
|
Posted: Thu Jan 21, 2010 2:36 pm |
|
|
Incredible! now sends the following message;
| Quote: | | ***Error 100"C:\Programme\PICC\drivers\DS1631.c"Line 34(5,41).USE parameter value ist out of range Not a mumber:PIN_D1 |
This line;
#use i2c(master,sda=DAL_SDA,scl=DAL_SCL) |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 21, 2010 2:45 pm |
|
|
| Re-install the compiler. Start fresh. |
|
 |
fiasgardone
Joined: 19 Jan 2010 Posts: 71
|
|
Posted: Thu Jan 21, 2010 2:46 pm |
|
|
PCM after restarting the compiler, the program complile without problems and now the LCD shows the following;
19 E0
19 F0
19 C0
19 BO
19 A0
19 90
The number 19 is constant, the other is variable, I checked 10 minutes and was observed that
Now is improving? |
|
 |
fiasgardone
Joined: 19 Jan 2010 Posts: 71
|
|
Posted: Fri Jan 22, 2010 6:38 am |
|
|
| Hi PCM, I noticed that the values shown in the LCD change depending on the temperature. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 22, 2010 9:10 pm |
|
|
It looks like it's probably working now. Remove the diagnostic code
and put the normal code back in. |
|
 |
fiasgardone
Joined: 19 Jan 2010 Posts: 71
|
|
Posted: Sat Jan 23, 2010 8:13 am |
|
|
Hi PCM...I removed the diagnostic code and tested it with the source code below, and the result shows that the LCD is for example "temp.22.3". If I can finger on the sensor values go up, if I remove the finger values fall, but the conversion is slow.
Not sure if the mathematical conversion is correct!
Please check for errors, or can improve the code!
Thanks!
| Code: |
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#include <flex_lcd.c>
// Tell the driver to use pins D0 and D1 for the i2c bus.
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
#include <DS1631.c>
//=================================
void main()
{
float value;
lcd_init();
delay_ms(100);
init_temp();
while(1)
{
delay_ms(1000);
value = read_full_temp();
value /= 100.0;
value=(value-32)/1.8;
lcd_gotoxy(15,2);
printf(lcd_putc,"temp.%04.1f", value);
}
}
|
|
|
 |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Jan 23, 2010 9:07 am |
|
|
| Quote: | | but the conversion is slow |
You may want to reduce delay_ms(1000);  |
|
 |
fiasgardone
Joined: 19 Jan 2010 Posts: 71
|
|
Posted: Sun Jan 24, 2010 2:41 pm |
|
|
| Code: |
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#include <flex_lcd.c>
// Tell the driver to use pins D0 and D1 for the i2c bus.
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
#include <DS1631.c>
//=================================
void main()
{
float value;
lcd_init();
delay_ms(100);
init_temp();
while(1)
{
delay_ms(100);
value = read_full_temp();
value /= 100.0;
value=(value-32)/1.8;
lcd_gotoxy(15,2);
printf(lcd_putc,"temp.%04.1f", value);
}
}
|
Hi,..What is wrong in the code above, I compared the temperature shows the DS1631 in the LCD, with a thermometer I bought, and DS1631 shows 2 °C above the thermometer bought!
Why this difference? |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 24, 2010 3:18 pm |
|
|
Read the DS1631 data sheet.
| Code: | Table 6. RESOLUTION CONFIGURATION
R1 R0 RESOLUTION CONVERSION TIME
(BITS) (MAX)
0 0 9 93.75 ms
0 1 10 187.5 ms
1 0 11 375 ms
1 1 12 750 ms
|
The ds1631 driver writes 0x0C to the Config register.
This sets bits R0 and R1 = 1. So it's using 12-bit resolution.
So, it takes at least 750 ms to get an accurate result.
Your current delay loop is a lot less than 750 ms.
There is a "trade off" between accuracy and conversion time. |
|
 |
|