avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-chat] Comparisson with negative values


From: John
Subject: [avr-chat] Comparisson with negative values
Date: Mon, 19 Nov 2007 18:30:41 +0100

My application is just a development from largedemo.
I have two potentiometers with the idea of developing a controller.
These are named reference and feedback.
 
volatile uint16_t reference;
volatile uint16_t feedback;
volatile uint16_t error;
 
// this works
 
if (reference > feedback) set_pwm(pwm + 1);
if (reference < feedback) set_pwm(pwm - 1);
 
// this does not work
 
error = reference - feedback;
 
if (error > 0) set_pwm(pwm + 1);
if (error < 0) set_pwm(pwm -1);
 
In the later case error can take positive or negative values.
In the former case only positive values are involved.
 
Would someone be as good as to send me the correct syntax
for a comparisson with negative numbers.
 
 
John

reply via email to

[Prev in Thread] Current Thread [Next in Thread]