Temperature

spinnaker

Joined Oct 29, 2009
7,830
I had no such problem with that site.

What you are trying to do is really complicated. For starters what you are going to have to do is figure a way to reserve flash memory with linker commands. That is not easy.


Why not just buy another pic with an eeprom and this time get plenty of memory.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
stdby on the flash read write for a while.
Have got another problem i am working on.

Have this code for reading / showing the temperature.
Rich (BB code):
void vis_temp (void) //Show temp..
 {
  signed int l, max,min,grader ;
     unsigned int rem;
     char mintemp[6],maxtemp[6];
            ADON=1;    // Turn on A/D Reading
  GO_nDONE=1;             // initiate conversion on the channel 0   
       while(GO_nDONE) continue;
     ADC.bytes[0]=ADRESL;
                 ADC.bytes[1]=ADRESH;
                utoa(ADC_num, ADC.res, 10);
                temprature=(float)ADC.res*478.1/1024;
                temprature=temprature-50;          
      l = (signed int)temprature;
      temprature -= (float)l;
         rem = (unsigned int)(temprature* 1e1);
      sprintf(&ADC_num, "%i.%u", l, rem);
       lcd_clear();
   lcd_goto(0x00);       
        lcd_puts("Ude temp : "); // writing temp.
        lcd_puts(ADC_num);   // writing the degrees.
        
        grader=atoi(ADC_num);  // try to get it to numbers again so i can set MAX and MIN Temp...
                    
if (grader>max)max=grader;
if (grader<min)min=grader;
lcd_goto(0x40);
lcd_puts("Min : ");
itoa(mintemp, min, 3); 
lcd_puts(mintemp);
lcd_goto(0x4a);
lcd_puts("Max : ");
itoa(maxtemp, max, 6); 
lcd_puts(maxtemp);
  
  
 }  // END VIS TEMP.
But this procedure to show "max & min" temp is not working right.
The current temperature is shown correct.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Not forget the debugger.
Have testing a lot.
But now i seem to get an error when building hex file.
Rich (BB code):
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error   [1347] ; 0. can't find 0x1A words (0x1a withtotal) for psect "text1561" in class "CODE" (largest unused contiguous range 0x18)
Error   [1347] ; 0. can't find 0x15 words (0x15 withtotal) for psect "text1565" in class "CODE" (largest unused contiguous range 0xE)
Error   [1347] ; 0. can't find 0x10 words (0x10 withtotal) for psect "text1527" in class "CODE" (largest unused contiguous range 0xE)
Error   [1347] ; 0. can't find 0x10 words (0x10 withtotal) for psect "text1537" in class "CODE" (largest unused contiguous range 0xE)
Error   [1347] ; 0. can't find 0xE words (0xe withtotal) for psect "text1568" in class "CODE" (largest unused contiguous range 0x8)
Error   [1347] ; 0. can't find 0xC words (0xc withtotal) for psect "text1552" in class "CODE" (largest unused contiguous range 0x8)
Error   [1347] ; 0. can't find 0xA words (0xa withtotal) for psect "text1567" in class "CODE" (largest unused contiguous range 0x8)
Error   [1347] ; 0. can't find 0x9 words (0x9 withtotal) for psect "text1534" in class "CODE" (largest unused contiguous range 0x8)
Error   [1347] ; 0. can't find 0x6 words (0x6 withtotal) for psect "clrtext" in class "CODE" (largest unused contiguous range 0x5)
********** Build failed! **********
This code is the fail part.
Rich (BB code):
 void vis_temp (void) //Show temp..
 {
  signed int l;//,max,min,grader,grader2;
     unsigned int rem;
     float max,min,grader;
     char mintemp[6],maxtemp[6];
            ADON=1;    // Turn on A/D Reading
  GO_nDONE=1;             // initiate conversion on the channel 0   
       while(GO_nDONE) continue;
     ADC.bytes[0]=ADRESL;
                 ADC.bytes[1]=ADRESH;
                utoa(ADC_num, ADC.res, 10);
                temprature=(float)ADC.res*478.1/1024;
                temprature=temprature-50;          
      l = (signed int)temprature;
      temprature -= (float)l;
         rem = (unsigned int)(temprature* 1e1);
      sprintf(&ADC_num, "%i.%u", l, rem);
       lcd_clear();
   lcd_goto(0x00);       
        lcd_puts("Ude temp : "); // writing temp.
        lcd_puts(ADC_num);   // writing the degrees.
 
        grader=atof(ADC_num);  // try to get it to numbers again
 
if (grader<=min)min=grader;
if (grader>=max)max=grader;
sprintf(mintemp,"%.1f",min);
sprintf(maxtemp,"%.1f",max);
lcd_goto(0x40);
lcd_puts("Min : ");
lcd_puts(mintemp);
lcd_goto(0x4a);
lcd_puts("Max : ");
lcd_puts(maxtemp);
 
 
 
 }  // SLUT VIS TEMP.
Specially the
Rich (BB code):
sprintf(mintemp,"%.1f",min);
sprintf(maxtemp,"%.1f",max);
Works in sim, and show the right .
I think it is cause i ran out of space in chip ??

Rich (BB code):
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Memory Summary:
    Program space        used  1315h (  4885) of  2000h words   ( 59.6%)
    Data space           used    91h (   145) of   200h bytes   ( 28.3%)
    EEPROM space         None available
    Configuration bits   used     2h (     2) of     2h words   (100.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)
 
Running this compiler in PRO mode, with Omniscient Code Generation enabled,
produces code which is typically 40% smaller than in Lite mode.
The HI-TECH C PRO compiler output for this code could be 1859 words smaller.
See http://microchip.htsoft.com/portal/pic_pro for more information.
Loaded C:\****************\16F1509\Temp.cof.
********** Build successful! **********
Build ok, is when i left out these 2 lines.

Edit
Have tried to left out some other stuff in code, and now i have room for the 2 lines,
88 % used then.
So the chip is again to small, reason to buy the 1509 was that it could use the same pinouts ect.
Maybe there is another way to make it without sprintf commands,. ?
maybe do it without decimalpoint.(INT)
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
Here is something from a search on the other error

http://www.microchip.com/forums/m529903.aspx

From this post it looks like you might be running out of memory on a page not on the chip itself.

I have never used a 16F chip. I have only used 18F. The 18F is supposed to be "optimized" for C.

I am not sure if you need to manage page memory yourself or not on the 16F. You don't on the 18F.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
From this post it looks like you might be running out of memory on a page not on the chip itself.
Dont get it, what di u mean by running out on page ?
these errors do not happens when i "miss" som code in chip. like taking all out execp the part with "temprature"
then there is room in chip, but not much, just like 99% used.
there must be a way to "convert" the degrees to integers or or
 

spinnaker

Joined Oct 29, 2009
7,830
Dont get it, what di u mean by running out on page ?
these errors do not happens when i "miss" som code in chip. like taking all out execp the part with "temprature"
then there is room in chip, but not much, just like 99% used.
there must be a way to "convert" the degrees to integers or or
Like I said I do not know much about the 16F chips. But mcus have pages of memory. When you allocate space you may need to switch pages to get more memory. I do know that using C combined with the 18F pics will do this for you automatically. I do don't know if it does it for you on the 16F.

Perhaps after Christmas holiday someone more knowledgeable will be able to comment.


Read up on "integer math" there are a number of articles out there that will show how to divide with integers.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Finaly i got something working.
Rich (BB code):
void vis_temp (void) //Show temp..
 { 
  signed int l,grader;
     unsigned int rem;
    char min1[10],min2[10],max1[10],max2[10];
            ADON=1;    // Turn on A/D Reading
  GO_nDONE=1;             // initiate conversion on the channel 0   
       while(GO_nDONE) continue;
     ADC.bytes[0]=ADRESL;
                 ADC.bytes[1]=ADRESH;
                utoa(ADC_num, ADC.res, 10);
                temprature=(float)ADC.res*478.1/1024;
                temprature=temprature-50;          
      l = (signed int)temprature;
      temprature -= (float)l;
         rem = (unsigned int)(temprature* 1e1);
      sprintf(&ADC_num, "%i.%u", l, rem);
       lcd_clear();
   lcd_goto(0x00);       
        lcd_puts("Ude temp : "); // writing temp.
        lcd_puts(ADC_num);   // writing the degrees.
 
grader=(l*10)+rem;    // convert to degree*10
if (min==0)min=grader;  //just to get it to work
if (max==0)max=grader;  // after reset of max-min .
if (grader<=min)   // if degree is under last reading
{ 
 min=grader;    // set new "min" temp.
 lcd_goto(0x40);
 lcd_puts(ADC_num);  // write new degree
 utoa(min1,l,10);  // to string
 utoa(min2,rem,10);  // to string
 strcat(min1,".");  // put a comma
 strcat(min1,min2);  // add 2 string
 }
if (grader>min)    //if degree bigger than "min"
{
 lcd_goto(0x40);   //
lcd_puts(min1);     // writes the last know "min"value
}
lcd_goto(0x45);
lcd_puts(":Min-Max:");  // just text
if (grader>=max)   // if degree is bigger than "Max"
{ 
 max=grader;    // new "max" value
 lcd_goto(0x4F); 
 lcd_puts(ADC_num);  // writes the new value
 utoa(max1,l,10);  // to string
 utoa(max2,rem,10);  // to string
 strcat(max1,".");  // add dot
 strcat(max1,max2);  // add 2 string
 }
if (grader<max)    // if degree less than "max"
{
 lcd_goto(0x4F);
 lcd_puts(max1);    // write last known "max"
}
 
 }  // SLUT VIS TEMP.
Now it's just the flash_read write part i miss.
Still here is the info.
Rich (BB code):
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Memory Summary:
    Program space        used   FACh (  4012) of  2000h words   ( 49.0%)
    Data space           used    9Eh (   158) of   200h bytes   ( 30.9%)
    EEPROM space         None available
    Configuration bits   used     2h (     2) of     2h words   (100.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)
 
Running this compiler in PRO mode, with Omniscient Code Generation enabled,
produces code which is typically 40% smaller than in Lite mode.
The HI-TECH C PRO compiler output for this code could be 1512 words smaller.
See http://microchip.htsoft.com/portal/pic_pro for more information.
Loaded C:\***************************\Temp.cof.
********** Build successful! **********
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
Well good for you and bad for you.

For I do not no how many times I have asked. But I will ask again. Post in complete thoughts! No one can read your mind. What does

"Now it's just the flash_read write part i miss.
Still here is the info."

mean????
 

nerdegutta

Joined Dec 15, 2009
2,689
I agree with the complete thoughts and complete code. It would be nice with complete code. Maybe not complete code in brackets but as an attachment as *.txt.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Here is the complete code.

Rich (BB code):
Attached as file.
Hope it give meaning.

Things to do now.
1. Read_write from and to FLASH Memory.
2. Final cleanup. Maybe an extra temprature unit, but misses input pin.

Edit
Will RA1 ( AN1 ) could be used as a second input analog, i mean , it's used for Vref , will it work ok anyway ?
 

Attachments

Last edited:

t06afre

Joined May 11, 2009
5,934
Here is the complete code. Will RA1 ( AN1 ) could be used as a second input analog, i mean , it's used for Vref , will it work ok anyway ?
Yes AN1 as far as I can see. Can both be analog input or Vref just get the configuration correct. And you can use it as a ADC input
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Yes AN1 as far as I can see. Can both be analog input or Vref just get the configuration correct. And you can use it as a ADC input
Waiting with that anyway.

I got an other little problem.
Sometimes under readout of temprature, i get a reading of
65480 and til 65533, arround max unsigned integer number
Have tried to make a workarround but do not seems to work.
Here is the temprature code, again.
Rich (BB code):
 void vis_temp (void) //Show temp..
 { 
  signed int l,grader;
     unsigned int rem;
    char min1[10],min2[10],max1[10],max2[10];
            ADON=1;    // Turn on A/D Reading
  GO_nDONE=1;             // initiate conversion on the channel 0   
       while(GO_nDONE) continue;
     ADC.bytes[0]=ADRESL;
                 ADC.bytes[1]=ADRESH;
                utoa(ADC_num, ADC.res, 10);
                temprature=(float)ADC.res*478.1/1024;
                temprature=temprature-50;          
      l = (signed int)temprature;
      temprature -= (float)l;
         rem = (unsigned int)(temprature* 1e1);
      sprintf(&ADC_num, "%i.%u", l, rem);
       lcd_clear();
   lcd_goto(0x00);       
        lcd_puts("Ude temp : "); // writing temp.
        lcd_puts(ADC_num);   // writing the degrees.
      
 if(rem>9 || rem<0)rem=0;   //try to prevent big numbers.
 if(l>99 || l<-49)l=0;  
grader=(l*10)+rem;    // convert to degree*10 + decimal
if (grader>900)grader=0; // if total off.
if (grader<-499)grader=0; // under -49 grader
if (min==0)min=grader;  //just to get it to work
if (max==0)max=grader;  // after reset of max-min .
if (max<min)min=0;
if (max<min)max=0;
if (grader<=min)   // if degree is under last reading
{ 
 min=grader;    // set new "min" temp.
 lcd_goto(0x40);
 lcd_puts(ADC_num);  // write new degree
 utoa(min1,l,10);  // to string
 utoa(min2,rem,10);  // to string
 strcat(min1,".");  // put a comma
 strcat(min1,min2);  // add 2 string
 }
if (grader>min)    //if degree bigger than "min"
{
 lcd_goto(0x40);   //
lcd_puts(min1);     // writes the last know "min"value
}
lcd_goto(0x45);
lcd_puts(":Min-Max:");  // just text
if (grader>=max)   // if degree is bigger than "Max"
{ 
 max=grader;    // new "max" value
 lcd_goto(0x4F); 
 lcd_puts(ADC_num);  // writes the new value
 utoa(max1,l,10);  // to string
 utoa(max2,rem,10);  // to string
 strcat(max1,".");  // add dot
 strcat(max1,max2);  // add 2 string
 }
if (grader<max)    // if degree less than "max"
{
 lcd_goto(0x4F);
 lcd_puts(max1);    // write last known "max"
}
  
 }  // SLUT VIS TEMP.
if i reset the min-max temprature, it works again a little while, but just out of nowhere it just show the big number again.
Why ?
 

spinnaker

Joined Oct 29, 2009
7,830
You need to learn to troubleshoot problems. You are the one with the circuit and the code. We can help but it is not the same as being there. It is a lot easier if you can narrow the problem down and tell us where you think the problem is.

Create a new test program that does nothing but output an integer. See if the number stays as expected. This will determine if it is code or hardware.


If that works then add your code to the test program to convert the integer to the actual temperature that you want to display.

If you find the issue there then step through with the debugger till you see the error.


This is basic troubleshooting procedures that all of us go through.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
The error is not all of the time, that makes it hard to find.
But have found that when reading AN0 i could sometimes result i bad reading, or bad input.
I have just made a simpel eay to work around it, maybe not the right way, but i works.

Rich (BB code):
 void vis_temp (void) //Show temp..
 { 
  signed int l,grader,length;
     unsigned int rem;
    char min1[10],min2[10],max1[10],max2[10];
            ADON=1;    // Turn on A/D Reading
  GO_nDONE=1;             // initiate conversion on the channel 0   
       while(GO_nDONE) continue;
     ADC.bytes[0]=ADRESL;
                 ADC.bytes[1]=ADRESH;
                utoa(ADC_num, ADC.res, 10);
                temprature=(float)ADC.res*478.1/1024;
                temprature=temprature-50;          
      l = (signed int)temprature;
      temprature -= (float)l;
         rem = (unsigned int)(temprature* 1e1);
      sprintf(&ADC_num, "%i.%u", l, rem);
    lcd_clear();
  length = strlen(ADC_num); // find length of the string
if (length<6)     // if string length is under 6 "-50.0" until "150.0"
{
lcd_goto(0x00);       
lcd_puts("Ude temp : "); // writing temp.
lcd_puts(ADC_num);   // writing the degrees.
lcd_puts("ß C");
grader=(l*10)+rem;   // convert to degree*10 + decimal
if (min==0)min=grader;  // just to get it to work
if (max==0)max=grader;  // after reset of max-min .
if (grader<=min)   // if degree is under last reading
{ 
 min=grader;    // set new "min" temp.
 lcd_goto(0x40);
 lcd_puts(ADC_num);  // write new degree
 lcd_puts("ß");
 utoa(min1,l,10);  // to string
 utoa(min2,rem,10);  // to string
 strcat(min1,".");  // put a comma
 strcat(min1,min2);  // add 2 string
 }
if (grader>min)    //if degree bigger than "min"
{
 lcd_goto(0x40);   
 lcd_puts(min1);   // writes the last know "min"value
 lcd_puts("ß");
} 
 lcd_goto(0x46);
 lcd_puts(":MinMax:"); // just text
 
if (grader>=max)   // if degree is bigger than "Max"
{ 
 max=grader;    // new "max" value
 lcd_goto(0x4F); 
 lcd_puts(ADC_num);  // writes the new value
 lcd_puts("ß");
 utoa(max1,l,10);  // to string
 utoa(max2,rem,10);  // to string
 strcat(max1,".");  // add dot
 strcat(max1,max2);  // add 2 string
 }
if (grader<max)    // if degree less than "max"
{
 lcd_goto(0x4F);
 lcd_puts(max1);    // write last known "max"
 lcd_puts("ß");
}
 } 
else      // if string length is over 5, 
{ lcd_puts("    Out of range");
 lcd_goto(0x40);
 lcd_puts("  Tjek forbindelser");
}
 }  // SLUT VIS TEMP.
Now i could need some help to get Flash_read and Flash_write working,
And yes, i have read a lot on the net, but i get more and more confused how to do it.
 

t06afre

Joined May 11, 2009
5,934
FroceMaster said:
Hi.
HAve u any idea how to read and write from internal flash ?
HAve tried a lot, but can not fint anything i can get to function.
LAst part i miss..
Yes I have. Reading is quite easy. Writing is more awkward as before you write to a row in the flash. It has to be erased first. But everything is quite clear in the datasheet. So I can pitch in and help on the code writing. To be sure what did you write to the EEPROM in the 16f690 and how often did you update the data
 
Top