با سلام
من یه برنامه نوشتم که عرض پالس رو با استفاده از پایه اینتراپت صفر و تایمر صفر اندازه گیری می کنه, با استفاده از این تاپیک
http://www.eca.ir/forum2/index.php?topic=60627.30
ولی به شکل فجیعی جوابش نادرسته مثلا 500 میلی ثانیه رو نشون میده 32035 میکرو ثانیه , نمی دونم کجاش سوتی دادم اینم برنامه مون:(پیشاپیش مرسی..)
[code=c]//AVR Core Clock frequency: 1.000000 MHz
#include <mega16.h>
#include <alcd.h>
#include <stdlib.h>
unsigned char i=0;
unsigned char f_ok;
static unsigned char j=0;
unsigned char str[16];
long wpulse;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
j++;
if(j==1){
TCCR0=0x01;
TCNT0=0x00;
OCR0=0xC8;
}
if(j==2){
TCCR0=0x00;
GICR|=0x00;
j=0;
f_ok=1;
}
}
// Timer 0 output compare interrupt service routine
interrupt [TIM0_COMP] void timer0_comp_isr(void) //after every 200us Called
{
i++;
}
void main(void)
{
DDRA=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
//TCNT0=0x00;
//OCR0=0xC8;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Any change
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x01;
MCUCSR=0x00;
GIFR=0x40;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x02;
lcd_init(16);
// Global enable interrupts
#asm("sei"
while (1)
{
if(f_ok==1){
wpulse=(i*200)+TCNT0;//Pulse Width in microsec
ltoa(wpulse,str);
lcd_puts(str);
i=0;
f_ok=0;
TCNT0=0;
GICR|=0x40;
}
} }[/code]
من یه برنامه نوشتم که عرض پالس رو با استفاده از پایه اینتراپت صفر و تایمر صفر اندازه گیری می کنه, با استفاده از این تاپیک
http://www.eca.ir/forum2/index.php?topic=60627.30
ولی به شکل فجیعی جوابش نادرسته مثلا 500 میلی ثانیه رو نشون میده 32035 میکرو ثانیه , نمی دونم کجاش سوتی دادم اینم برنامه مون:(پیشاپیش مرسی..)
[code=c]//AVR Core Clock frequency: 1.000000 MHz
#include <mega16.h>
#include <alcd.h>
#include <stdlib.h>
unsigned char i=0;
unsigned char f_ok;
static unsigned char j=0;
unsigned char str[16];
long wpulse;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
j++;
if(j==1){
TCCR0=0x01;
TCNT0=0x00;
OCR0=0xC8;
}
if(j==2){
TCCR0=0x00;
GICR|=0x00;
j=0;
f_ok=1;
}
}
// Timer 0 output compare interrupt service routine
interrupt [TIM0_COMP] void timer0_comp_isr(void) //after every 200us Called
{
i++;
}
void main(void)
{
DDRA=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
//TCNT0=0x00;
//OCR0=0xC8;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Any change
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x01;
MCUCSR=0x00;
GIFR=0x40;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x02;
lcd_init(16);
// Global enable interrupts
#asm("sei"

while (1)
{
if(f_ok==1){
wpulse=(i*200)+TCNT0;//Pulse Width in microsec
ltoa(wpulse,str);
lcd_puts(str);
i=0;
f_ok=0;
TCNT0=0;
GICR|=0x40;
}
} }[/code]