|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2009-1-4 15:29:30
|
显示全部楼层
使用feng_matrix的"第二版无刷电调源代码",对模拟比较器中断函数做了些修改,可以通过检测流过FET的电流来判断过流。
SIGNAL(SIG_COMPARATOR)
{
unsigned char sense = 0;
do
{
if(SENSE_H) sense = 1; else sense = 0;
switch(Phase)
{
case 0:
STEUER_A_H;
if(sense)
{
STEUER_C_L;
TCNT2 = 1;
if(ZeitZumAdWandeln) AdConvert(0x02);
SENSE_FALLING_INT;
SENSE_B;
Phase++;
PhaseFG=8;
CntKommutierungen++;
}
else
{
STEUER_B_L;PhaseFG=Phase;
}
break;
case 1:
STEUER_C_L;
if(!sense)
{
STEUER_B_H;
TCNT2 = 1;
if(ZeitZumAdWandeln) AdConvert(0x02);
SENSE_A;
SENSE_RISING_INT;
Phase++;
PhaseFG=8;
CntKommutierungen++;
}
else
{
STEUER_A_H;PhaseFG=Phase;
}
break;
case 2:
STEUER_B_H;
if(sense)
{
STEUER_A_L;
TCNT2 = 1;
if(ZeitZumAdWandeln) AdConvert(0x00);
SENSE_C;
SENSE_FALLING_INT;
Phase++;
PhaseFG=8;
CntKommutierungen++;
}
else
{
STEUER_C_L;PhaseFG=Phase;
}
break;
case 3:
STEUER_A_L;
if(!sense)
{
STEUER_C_H;
TCNT2 = 1;
if(ZeitZumAdWandeln) AdConvert(0x00);
SENSE_B;
SENSE_RISING_INT;
Phase++;
PhaseFG=8;
CntKommutierungen++;
}
else
{
STEUER_B_H;PhaseFG=Phase;
}
break;
case 4:
STEUER_C_H;
if(sense)
{
STEUER_B_L;
TCNT2 = 1;
if(ZeitZumAdWandeln) AdConvert(0x01);
SENSE_A;
SENSE_FALLING_INT;
Phase++;
PhaseFG=8;
CntKommutierungen++;
}
else
{
STEUER_A_L;PhaseFG=Phase;
}
break;
case 5:
STEUER_B_L;
if(!sense)
{
STEUER_A_H;
TCNT2 = 1;
if(ZeitZumAdWandeln) AdConvert(0x01);
SENSE_C;
SENSE_RISING_INT;
Phase = 0;
PhaseFG=8;
CntKommutierungen++;
}
else
{
STEUER_C_H;PhaseFG=Phase;
}
break;
}
//send_data1(0xcc);
}
while((SENSE_L && sense) || (SENSE_H && !sense));
ZeitZumAdWandeln = 0;
}
//--------------------------------------------------
void AdConvert(unsigned char channel)
{
unsigned int i=0;
unsigned char sense;
sense = ADMUX; // Sense-Kanal merken
//ADMUX = 0x06; // Kanal 6
ADMUX = channel| IntRef; //Öض¨Òåµ½channel¿Ú
SFIOR = 0x00; // Analog Comperator aus
ADCSRA = 0xD3; // Converter ein, single
ADCSRA |= 0x10; // Ready löschen
//ADMUX = 0x06; // Kanal 6
ADMUX = channel| IntRef; //Öض¨Òåµ½channel¿Ú
ADCSRA |= 0x40; // Start
while (((ADCSRA & 0x10) == 0));
ADMUX = sense; // zurück auf den Sense-Kanal
i = ADCW ;
// if(i> 200) i = 200;
Strom =( i+Strom*7)/8;
ADCSRA = 0x00;
SFIOR = 0x08; // Analog Comperator ein
} |
|