E biết vậy nhưng ý e hỏi là khi nó đang thực hiện ngắt thì nó có đếm không hay là khi thực hiện xong ngắt và trở về chương trình chính nó mới đếm tiếp ?
ngắt của e nó thế này :
Code:
void timer0()
{
set_timer0(6); // T = 16*(256 - 6)*0.2us = 800us (ne^'u dùng tha.ch anh 4M thi thay 0.2us thành 1us)
++count;
set_adc_channel(0); // RA0/AN0(Pin2) is analog input channel
delay_us(10);
ap_adc=read_adc();
ap_dc=ap_dc+ap_adc;
set_adc_channel(1);
delay_us(10);
dong_adc=read_adc();
dong_dc=dong_dc+dong_adc;
power=(ap_adc-v_offset)*(dong_adc-i_offset);
value=power+ value;
if(count==625) //800*200=240000
{
count=0;
v_offset=ap_dc/625;
i_offset=dong_dc/625;
power_tb=(value/625)*1.13; //Ki=480
//Kv=639
//power_tb=(ap_adc*Kv*(5/1024))*(dong_adc*Ki*(5/1024))
power_sum=power_tb*0.5/(3600*1000); //power_tb*0.2/(3600*1000) __10 chu ky
temp=power_sum+temp;
if(temp>=0.001)
{
sum=sum+temp;
temp=temp-0.001;
RB7=1;
delay_ms(20);
RB7=0;
}
ap_dc=0;
dong_dc=0;
value=0;
}
}