imranahmed
Advanced Member level 3
- Joined
- Dec 4, 2011
- Messages
- 817
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Karachi,Pakistan
- Activity points
- 6,492
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
unsigned char a=0;
void InitTimer1(){
TCCR1B = 0x0B;
OCR1A = 12499;
TIFR = 0x00;
TIMSK = 0x04;
sei();
}
void main(void)
{
DDRD = 0xff;
PORTD = 0x00;
InitTimer1();
while(1)
{
PORTD = a;
}
}
ISR(TIMER1_OVF_vect)
{
a++;
}
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
unsigned char a=0;
void InitTimer1(){
TCCR1B = 0x0B;
OCR1AH = 0x30;
OCR1AL = 0xD3;
TIFR = 0xFF;
TIMSK = 0x04;
sei();
}
void main(void)
{
DDRD = 0xff;
PORTD = 0x00;
InitTimer1();
while(1)
{
PORTD = a;
}
}
ISR(TIMER1_COMPA_vect)
{
a++;
}
while(1)
{
PORTD = 0xa0;
delay by using timer interrupt
PORTD = 0x30;
delay by using timer interrupt
PORTD = 0x08;
delay by using timer interrupt
}
}
}
void Debounce()
{
uint8_t i;
for(i=0;i<20;i++)
{
_delay_loop_2(0);
}
}
void Wait()
{
uint8_t i;
for(i=0;i<10;i++)
{
_delay_loop_2(0);
}
}
//This is below done in main loop.
while(1)
{
if((PIND & (1<<PD6))== 0){
p++;
Debounce();
}
switch(p){
case 0:
Print1(read_adc(1)); //Yellow Volts
Wait();
Print(read_adc(3)); //Yellow Amps
Wait();
break;
case 1:
Red=(read_adc(0));
_delay_us(60);
Blue=(read_adc(2));
_delay_us(60);
YellowAmps=(read_adc(3));
_delay_us(60);
Red_Blue_Result=((Red+Blue)/2)*1.732;
Print1(Red_Blue_Result);
_delay_us(60);
Print(YellowAmps); //Yellow Amps
Wait();
break;
1) a simple filter could be like this: dv = dv + ( av - dv) * fc
Where dv is the value to display, and av the actual measured value and fc the filter constant.
Fc depends on how often the function is called, either every display update or every adc sample.
For a rule of thumb the cutoff frequency is the function call frequency * fc.
For exampl if you want a cutoff frequency ofc1 Hz and you call the function with 100Hz, then fc should be about 0.01.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?