## Problem with major  or minor compare???

cancel
Showing results for
Did you mean:

## Problem with major  or minor compare???

1,097 Views
Contributor I
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.

Posted: Fri Sep 02, 2005 4:29 am

Hello!

I have the following rummy problem.
I measure voltage with the ATD-Module. In a ISR, I write the Value of
ATD0DR0 in a struct.

It looks like this:
Code:
`struct value { volatile short volt; volatile float volt_calc; }var; // (void)init_value(void) { var.volt=0; var.volt_calc=0; } #pragma interrupt_handler isratd void isratd(void) { var.volt=ATD0DR0; } // (void)calc(void) { asm ("sei"); var.volt_calc=var.volt*3.967 asm("cli"); }`

Okay, that works perfectly.
I can display the value of var.volt_calc over a printf-command on the
screen.
But now, I have problems with the following command.
An example:
if (var.volt_calc<20.5){;}
This query is only true, when the value of var.volt_calc is equal 0.
It´s false, when i.e. the value is 1 or 4 or 7.4 etc.
I don´t know, what´s wrong.

I use the ICC compiler with a S12DJ64 controller.
Please, help me, if you have an idea?!?!

Cheers

Posted: Fri Sep 02, 2005 11:36 am

Hello,

I tried your code (slightly modified) in CodeWarrior, it worked for me... You could maybe try a workaround, something like:
Code:
`float dummy; ... dummy = (var.volt_calc) /20.5; if (dummy < 1.0){   // smaller } `

or
Code:
`float dummy; ... dummy = ((var.volt_calc) /20.5)-1.0; if (dummy < 0.0){   // smaller } `

maybe also do printf's of the dummy variable to see what's the value of it.

Then I have a question to you, if I may:
I'm trying to use the HW I2C on my S12DP256B, but it doesn't work. Have you gotten your code to work? Could you tell me your configuration words?

MfG,

Posted: Fri Sep 02, 2005 11:46 am

Hello

Thank you for the comment. It is rummy, that your code is working. But I will test your example soon. Now I am not at work.
I use a monitor program and interrupts. It is possible, that this monitor program is the cause of my problem?!?!

Okay, now to your problem "I2C":
Yes it´s working. But I don´t use interrupts in my I2C routine and it is probably not very professional, but it works.
I can send you the code perhaps per Mail?!?!

Cheers

Posted: Fri Sep 02, 2005 12:31 pm

Servus,

I would not really expect the monitor to be the problem, but I'd have to see where the code-parts are placed to be sure.
I would more expect the problem to be with missing type-casting or parantheses, but that also seemed okay.

Turning off the interrupts while doing the calculation (as you do) is btw. a good idea

Labels (1)

0 Replies