CMOS
Advanced Member level 3
Hi all,
I am re-coding the firmware of a weighing scale which uses a discretely made sigma-delta ADC using op-amps and counters and an 8051 microcontroller.
I am using moving-average filter for stability. Now the problem is if I increase the number of samples for averaging, the final count reduces to a considerable amount and vice versa. I don't get similar weight values for different window sizes!!
However I think this should not happen.. no matter what the filter window size is, the reading should fluctuate around same value for a given weight.
Any solutions ??
Here is my update weight ISR where averaging is carried out
I am re-coding the firmware of a weighing scale which uses a discretely made sigma-delta ADC using op-amps and counters and an 8051 microcontroller.
I am using moving-average filter for stability. Now the problem is if I increase the number of samples for averaging, the final count reduces to a considerable amount and vice versa. I don't get similar weight values for different window sizes!!
However I think this should not happen.. no matter what the filter window size is, the reading should fluctuate around same value for a given weight.
Any solutions ??
Here is my update weight ISR where averaging is carried out
Code:
#define AVG_FILTER_WINDOW_SIZE 8
void new_weight_interrupt(void) interrupt 2 using 0
{
EX1 = 0; // Disable INT1 interrupt
ET1 = 1; // Disable TMR0 interrupt
TR0 = 0; // Stop Timer-0
val_393 = P1;
val_393 &= 0x0F;
CLR_393 = 1;
new_weight = ((long)overflow) << 16;
new_weight |= ((long)TH0) << 8;
new_weight |= ((long)TL0);
new_weight <<= 4;
new_weight |= (long)val_393;
// AVERAGING IS DONE HERE
avg_weight += new_weight;
avg_weight /= AVG_FILTER_WINDOW_SIZE;
overflow = 0;
TH0 = 0;
TL0 = 0;
TR0 = 1;
CLR_393 = 0;
EX1 = 1;
ET1 = 1;
}