Temperature

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
This sub takes care of the outside temperature

Rich (BB code):
void vis_temp (void)  // Viser temperaturen
{
 unsigned int degree,celcius;
  char grader[4];
   ADON=1;
lcd_clear();
 
    GO_DONE=1;              // initiate conversion on the channel 0   
     while(GO_DONE) continue;
    degree = ADRESL;           // Get the 8 bit LSB result
degree += (ADRESH << 8);   // Get the 2 bit MSB result
celcius=(((5000/1024)*degree)-500)/10;
lcd_goto(0x00);
lcd_puts(" Ude Temp : ");
utoa(grader, celcius, 10);
lcd_puts(grader);
 }
And then i would like another sub that takes care of the inside temperature.
Should that be possible ?
how should i ask it to use input 2, ex RA1 ?

Rich (BB code):
void vis_temp_in (void)  // Viser temperaturen
{
 unsigned int degree,celcius;
  char grader[4];
   ADON=1;
lcd_clear();
 
    GO_DONE=1;              // initiate conversion on the channel 0   
     while(GO_DONE) continue;
    degree = ADRESL;           // Get the 8 bit LSB result
degree += (ADRESH << 8);   // Get the 2 bit MSB result
celcius=(((5000/1024)*degree)-500)/10;
lcd_goto(0x00);
lcd_puts(" In Temp : ");
utoa(grader, celcius, 10);
lcd_puts(grader);
 }
 

t06afre

Joined May 11, 2009
5,934
I think you need to get a bigger PIC. Or a full licensed compiler. The 16f1509 is a drop in replacement and also contain a temprature sensor
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
I think you need to get a bigger PIC. Or a full licensed compiler. The 16f1509 is a drop in replacement and also contain a temprature sensor
if i change , will i then have to rewrite all the program, or ?
If i still have space enough ( used 2500 of 4096 )
could i not just make it read from channel2, and 1.
the powersupply i regulated 5.00 v.
I could use a vref , a value i put in the EEprom, and maybe make changeable in the program, like a 10 mv step up or down.
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
And then i would like another sub that takes care of the inside temperature.
Should that be possible ?
how should i ask it to use input 2, ex RA1 ?
[/quote]

You already have it working on RA0. It is not hat difficult to duplicate for RA1.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Next problem, :(
When temperature drops below 0,
it starts writing something bull----.
how can i calculate in negative numbers ?
int , double , or what ?

have tried with double, still wrong, and it takes up a lot of space.
 

spinnaker

Joined Oct 29, 2009
7,830
Next problem, :(
When temperature drops below 0,
it starts writing something bull----.
how can i calculate in negative numbers ?
int , double , or what ?

have tried with double, still wrong, and it takes up a lot of space.

No idea what "it starts writing something bull----."

means but both int and double have negative numbers.

The difference is that integers are whole numbers like 1,2,3, or -5 and doubles are fractional like 1.123,23456 and -3.456.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
No idea what "it starts writing something bull----."

means but both int and double have negative numbers.

The difference is that integers are whole numbers like 1,2,3, or -5 and doubles are fractional like 1.123,23456 and -3.456.
hmm, goes from 5 , 4 , 3 , 0 , and then 65535 , no negative numbers.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Then you have an unsigned integer and not just an integer.
Rich (BB code):
void vis_temp (void)  // Viser temperaturen
{
 signed double celcius,degree,vref;
  char grader[4];
  vref= eeprom_read(35);
   ADON=1;
lcd_clear();
 
    GO_DONE=1;              // initiate conversion on the channel 0   
     while(GO_DONE) continue;
    degree = ADRESL;           // Get the 8 bit LSB result
degree += (ADRESH << 8);   // Get the 2 bit MSB result
celcius=((((5000/1024)*degree)-500)+vref)/10;   
lcd_goto(0x00);
lcd_puts(" Ude Temp :  ");
utoa(grader,celcius,10);
lcd_puts(grader);
 }
seems to be a signed double, and it does not write decimal point.
allways in hole numbers,
 

spinnaker

Joined Oct 29, 2009
7,830
I have never heard of a signed double. All doubles are signed. This must be something unique to your compiler.

Have you checked your documentation?

What do you think utoa(grader,celcius,10); does? Take a guess what the u in utoa stands for.
 

spinnaker

Joined Oct 29, 2009
7,830
hmm, Unsigned integer to string,,,,,
How many times do I need to say it:

LEARN TO USE YOUR DEBUGGER!

LEARN HOW TO DEBUG!



If you would have debugged your code then you would be able to see the line causing the problem. You may not have known exactly why it was causing a problem but then that is when you check your documentation. When that fails, that is when you come here and ask questions. Then you could say "the problem is right here on this line, why is that"?


Have been searching a little, and found
sprintf( missing something , what ?????

I have no idea what this means. Please use complete sentences when posting.

Yes you can use sprintf but many people do not like to use it because it takes so much memory. There are other methods to writing floating point numbers to strings but I don't worry about it. I pick mcus with plenty of memory.

And if you want to be saving on memory then you should not be using floating point in the first place. There are ways to do what you want with using all integers.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
How many times do I need to say it:

LEARN TO USE YOUR DEBUGGER!

LEARN HOW TO DEBUG!


If you would have debugged your code then you would be able to see the line causing the problem. You may not have known exactly why it was causing a problem but then that is when you check your documentation. When that fails, that is when you come here and ask questions. Then you could say "the problem is right here on this line, why is that"?





I have no idea what this means. Please use complete sentences when posting.

Yes you can use sprintf but many people do not like to use it because it takes so much memory. There are other methods to writing floating point numbers to strings but I don't worry about it. I pick mcus with plenty of memory.

And if you want to be saving on memory then you should not be using floating point in the first place. There are ways to do what you want with using all integers.
Sorry, not that god to english, and understand it all.
when i started this project, i was told the 16f690 was very big.
fine, but now, when i will have to expand a little bit, there is no more space.
if i then by a new one, and later will expand a little again, the problem will proberly come back.

Still, if i chance will i still be able to use the same program, or do i have to start all over again, ????
how can i make it with intergers ?
still need to write from -40.0 to hopefully 35.0 ;)
with decimal point.
 

spinnaker

Joined Oct 29, 2009
7,830
Sorry, not that god to english, and understand it all.
when i started this project, i was told the 16f690 was very big.
fine, but now, when i will have to expand a little bit, there is no more space.
if i then by a new one, and later will expand a little again, the problem will proberly come back.

Still, if i chance will i still be able to use the same program, or do i have to start all over again, ????
how can i make it with intergers ?
still need to write from -40.0 to hopefully 35.0 ;)
with decimal point.
Your English is not a problem. What you wrote right here is not a problem at all. Poor English yes but you have a full and complete statement, that is easy to understand.

No you do not need to start over. But what I would do is to copy what you have and start making your modifications on the new version.

That way if you make mistakes in the new version you can always go back to what you had.

As I said before, I take the easy way out and do just what you did. I use floating point and the sprintf function. But my pic is plenty large and it is only things I will use for a hobby and not professional

You should read up on integer math and dividing by shifting.
Here is just one of many articles.
http://en.wikipedia.org/wiki/Arithmetic_shift

Integers can represent doubles to you know. For example an integer of 5,250 can actually represent 5.250.

There are also tricks for turning an integer into a string of ASCII characters. itoa is a common C function but there are other ways to do it too. If you use itoa to turn an integer into a string that represents a decimal number then you would need to insert the decimal point at the correct place.

I would first learn how to do all of your math with integers. Don't worry about the decimal point for now. Then I would post a new thread that says something like Convert integer to ASCII string. Then I would say something like "I have and integer number that represents a decimal number and I want to convert the integer into an ASCII string. For example: int x=5250 convert x to a string of "5.250".

Maybe someone one the forum has a nice function for that but I would get your integer math working first.
 

t06afre

Joined May 11, 2009
5,934
Hi.
Should i choose the 16F1509 ?
Will that be enough space ?
The 16f1509 should have enough space. And it also have a temperature sensor. You will have to do some minor changes to your program. But that will only be in the configuration part of the program. What you do is up to you to decide. What we also can look at. Is to convert volt (ADC reading) to temperature and then to ASCII. in some more clever way. And hence not using ROM guzzling functions
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,415
The sprintf() function is one huge piece of code. I think I once clocked it at over 4,000 assembly instructions. It's huge as it has to do so many things at different times.

Converting an integer to a string can be done by a small function you may already have: atoi. While it is not part of the C standard it is very often included as part of stdlib.h. The C8 compiler has it there, though the documentation is hidden you can find it inside ...\Program Files\Microchip\xc8\v1.10\docs\manual.pdf, which is the MPLAB® XC8 C Compiler User’s Guide.

One complication is it only works with integers, but that is not a horrible problem. Floating point arithmetic is very expensive in terms of time and code and really should be avoided if at all possible, and this is definitely a case where floating point arithmetic is an overkill.

I would approach this by looking at the range: -40.0 to +35.0. Instead of looking at that as a real number with an integer and fractional component I would instead "adjust" the units I'm working in from simple degrees to 10th of a degree, so my adjusted range is -400 to +350.

A (signed) int type can handle this range.

That eliminates the floating point arithmetic. It does give you a string in the incorrect form. 22.5° would come out as 225, just a tad too large.

So you'll also need to adjust the string before you display it, or transmit it or however you use it. You just need to see how long the string is to insert the decimal point character, and also optionally a zero for degrees like so:

given string of the form: abcd

length 1: a becomes 0.a
length 2: ab becomes a.b
length 3: abc becomes ab.c
length 4: abcd becomes abc.d

Note when the number is negative you also need to copy over the negative sign.

That may be a lot to get all at once, but try to get each step to work (or let it print 225 before you try to get 22.5) and not all at once.

"Divide and conquer."

Oh, and it may be really helpful to use the debugger (either in circuit or the MPLAB simulator) to see exactly what your code is actually doing. That's how I work these things out.
 

ErnieM

Joined Apr 24, 2011
8,415
The 16f690 has room for some 4096 instructions and that is plenty to read the A2D and convert that to a string. Like 5 times what is needed.

Personally, when I'm in a development mode I get a chip with extra rom and possibly use a different device in production. The chips are cheap, your time is not.
 

spinnaker

Joined Oct 29, 2009
7,830
The 16f690 has room for some 4096 instructions and that is plenty to read the A2D and convert that to a string. Like 5 times what is needed.

Personally, when I'm in a development mode I get a chip with extra rom and possibly use a different device in production. The chips are cheap, your time is not.

Probably true but I would like to add the OP should be encourage to check out the specs o the OP's own over the complete range of Microchip's products.

Microchip has an excellent parametric search tool to help withe the selection.

http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1005
 
Top