This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Karthik R said:Yes i have checked, Its varying......
First you are doing inefficient timer delay for Ref to settle. Simple delay_cycles at default DCO freq can do the job.
What's that:
IntDegF = (temp/6.82)+33.8;
hi, this is code regarding delay for Ref to settle, Can u pls suggest what change has to be made so that code will exe without any problem, Pls help me as i'm new to MCu,
__enable_interrupt(); // Enable interrupts.
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
Karthik R said:so that code will exe without any problem
I did not say that your timer-based delay have problem. Perhaps it works. Such delay is just waste of timer peripheral and code memory. As I said - use __delay_cycles(Ncycles); function to do delay here.
Clearly your code have other problems like:
IntDegF = (temp/6.82)+33.8;
IntDegC=(temp/6.82);
Those lines actually are translated into:
IntDegF = (temp/6)+33;
IntDegC=(temp/6);
You can't do floating point math with integer variables!
If your code does not work - try examples, see how they do the job, compare to your code, check differences. Debug your code step by step to see that you are getting ADC values you expect, that your math is giving results you expect and so on.
This is highly unproductive to ask others in the internet to check your code instead of debugging it to see what's actually happening in your uC :D
I disagree. Using timers for delays is the right way to do things. That's what timers have been invented for. Also, a busy-waiting delay with __delay_cycles consumes way more energy than waiting for tiemr expiration in LPM.Ilmars said:I did not say that your timer-based delay have problem. Perhaps it works. Such delay is just waste of timer peripheral and code memory.
Ilmars said:Clearly your code have other problems like:IntDegF = (temp/6.82)+33.8;
IntDegC=(temp/6.82);Those lines actually are translated into:
IntDegF = (temp/6)+33;
IntDegC=(temp/6);You can't do floating point math with integer variables!
Well, you're wrong even if you're right.
First, of course you can do floating point math with integer values (if not, the compiler would throw an error). Whether it gives you the expected result, is a different story.
The compiler will cast the innteger part to float and then perform the operation, then truncate the result back to integer.
AFAIK
IntDegF = (temp/6.82)+33.8;
translates to
intDegF = (long) (((float)temp / 6.82)+33.8).
as the compiler promotes to the larger type of the two operands.
See here for a nice summary. With citations from the C standard (I know, citing standards is uncommon for me, I usually leave this to others, but this time I wanted to know.)
Karthik R said:I have got held up with this code for very long time and the temperature is not changing according to the change in the environment
Karthik R said:while(1)[...]
ADC10CTL0&= ~ENC;while(1){}__no_operation(); // SET BREAKPOINT HERE}
Jens-Michael Gross said:I have got held up with this code for very long time and the temperature is not changing according to the change in the environmentKarthik R said:while(1)[...]
ADC10CTL0&= ~ENC;while(1){}__no_operation(); // SET BREAKPOINT HERE}Well,the temperature might change, but your only measure it once, then your code gets caught in this inner while(1) loop and never does a second measurement.[/quote]
I'm really sorry for the late reply as i was travelling, can u pls tell , what change has to be made in the code so that i will get continuous reading and display the same, as i'm new to prog language Pls help me in this
thank you.
Thank you Jens-Michael Gross, for your reply , as u spotted the problem is in the while loop, i removed the loop and the code runs well and it does give the change in temperature according to environment , but i have a small prob , the temp value is not getting stabilized , Pls help me out in this
thank you
Jens-Michael Gross said:translates to
intDegF = (long) (((float)temp / 6.82)+33.8).
Ups. You are so right :) Thing is that I would never in my life write such kind of [...] type conversion for 16bit uC, especially to convert ADC'ed temperature to integer. So my mind played funny trick here :)
Jens-Michael Gross said:but this time I wanted to know
LOL. Me either. I suggest this in return.
Ilmars said:translates to
intDegF = (long) (((float)temp / 6.82)+33.8).
Ups. You are so right :) Thing is that I would never in my life write such kind of [...] type conversion for 16bit uC, especially to convert ADC'ed temperature to integer. So my mind played funny trick here :)
Jens-Michael Gross said:but this time I wanted to know
LOL. Me either. I suggest this in return.
[/quote]
Hi,
I'm sorry , i dint mention the change i have done int the code , the change is mentioned below, i found it on some web site, it works perfectly, intDegF = ((temp /5)*9/5)+32), but now i want to know how to stabilize the temp value, the value is oscillating too much when der is a change in external atmosphere. Pls help me out in this .
Thanking you
Karthik R said:the value is oscillating too much
How much? Please show sample data so we can see what you are talking about. Also specify what variation you expect.
Karthik R said:too much when der is a change in external atmosphere.
Please specify changes in the atmosphere.
HI
When a soldering iron is kept near the LM35 sensor , the room temperature value (i.e., 30 Deg C) is getting varied or jumping 4 to 5 values up and down to 30 deg C, and the jump is very fast, but it doesnt get stabilised also. I had recorded the video but i'm unable to upload it..... Pls help with this information.
Thank you
**Attention** This is a public forum