arek944
Newbie level 3
- Joined
- Feb 22, 2011
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Poland, Olsztyn
- Activity points
- 1,314
Hello,
I'm building a peristaltic pump controller on ATmega88 and I'd like to display approximate dose applied on LCD. Calculations are quite simple:
where:
x_speed_val is pump efficiency in [ml/min] - max value is 170 (170 gives 17.0 ml/min)
x_time_meter is time set in [sec] - max value is 600 (10 minutes)
So solving the equation for max values I should get: dose = 170 x 600 / 60 = 1700 (1700 means that 170.0ml has been pumped).
But my dispay function doesn't work that way. It displays the applied dose value corret until about 109.0ml (1090) afterwards the display function starts counting from 0.
Code for disp function:
version 1:
version 2:
Both versions of the display function work the same way. Can anyone help me out? It seems like ATmega88 can't handle uint32_t variable and all of calculations are cast on uint16_t.
I'm building a peristaltic pump controller on ATmega88 and I'd like to display approximate dose applied on LCD. Calculations are quite simple:
Code:
dose = ((x_speed_val * x_time_meter) / 60);
x_speed_val is pump efficiency in [ml/min] - max value is 170 (170 gives 17.0 ml/min)
x_time_meter is time set in [sec] - max value is 600 (10 minutes)
So solving the equation for max values I should get: dose = 170 x 600 / 60 = 1700 (1700 means that 170.0ml has been pumped).
But my dispay function doesn't work that way. It displays the applied dose value corret until about 109.0ml (1090) afterwards the display function starts counting from 0.
Code for disp function:
Code:
volatile uint8_t x_speed_val = 0;
volatile uint16_t x_time_meter = 0;
volatile uint32_t dose = 0;
Code:
if (update_lcd5)
{
dose = ((x_speed_val * x_time_meter) / 60);
LCD_XY(1,0);
LCD_WRITE_DOSE(dose);
update_lcd5 = F;
}
version 1:
Code:
void LCD_WRITE_DOSE (uint32_t num_sign)
{
uint8_t num[4];
uint32_t Dig_0, Dig_1, Dig_2, Dig_3;
Dig_3 = num_sign/1000;
num[3] = Dig_3 + '0';
num_sign = num_sign - (Dig_3 * 1000);
Dig_2 = num_sign/100;
num[2] = Dig_2 + '0';
num_sign = num_sign - (Dig_2 * 100);
Dig_1 = num_sign/10;
num[1] = Dig_1 + '0';
num_sign = num_sign - (Dig_1 * 10);
Dig_0 = num_sign;
num[0] = Dig_0 + '0';
LCD_WRITE_CHAR(num[3]);
LCD_WRITE_CHAR(num[2]);
LCD_WRITE_CHAR(num[1]);
LCD_WRITE_CHAR('.');
LCD_WRITE_CHAR(num[0]);
}
version 2:
Code:
void LCD_WRITE_DOSE (uint32_t num_sign)
{
uint8_t i;
uint8_t num[4];
num_sign = (num_sign-20) * 5;
for (i=0; i<=3; num_sign/=10, i++)
{
num[i] = num_sign % 10 +'0';
}
LCD_WRITE_CHAR(num[3]);
LCD_WRITE_CHAR(num[2]);
LCD_WRITE_CHAR(num[1]);
LCD_WRITE_CHAR('.');
LCD_WRITE_CHAR(num[0]);
}
Both versions of the display function work the same way. Can anyone help me out? It seems like ATmega88 can't handle uint32_t variable and all of calculations are cast on uint16_t.