Первоисточник. https://www.vbesmens.de/en/downloadse.html
Конкретно вот этот проект https://www.vbesmens.de/images/Downloads/UPCX530PowerBoard.zip
Перезапуск происходит в разных местах (поэтому грешу на прерывание. Ватчдог вроде выключен).
int main(void)
{
int cs;
ModeBLDC=0;
setup_io(); // make all i/o pins go the right dir
ModeBLDC=!((Hall1)&&(Hall2)&&(Hall3)); // switch to BLDC if one or more of the 3 hall pins are low
setErr(); // error on
setup_uart(); // setup the serial interface to the PC
setup_TMR1(); // set up 1ms timer
IEC0bits.T1IE = 1; // Enable interrupts for timer 1 needed for delays in following routines
// 1/2 seconds startup delay
timer_test = 5000;
while (timer_test);
if (ModeBLDC) printf("BLDC Mode\r\n");
else printf("DC Mode\r\n");
printf("\r\nPowerup\r\ni/o,uart,timer OK\r\n");
ПЕРЕЗАПУСК ПРОИСХОДИТ НА ЭТОМ ОТРЕЗКЕ обозначу волнистой линией
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setup_pwm(); // start PWM
set_pwm(0.0);
printf("pwm OK\r\n");
init_pid();
printf("pid OK\r\n");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setup_encoder(); // 16 bit quadrature encoder module setup
printf("encoder OK\r\n");
setup_capture(); // 2 pins with quadrature cmd from PC
printf("capture OK\r\n");
// some junk for the serial channel
printf(C_VERSION);
printf(C_INFO1);
printf(C_INFO2);
printf(C_INFO3);
clearErr(); // led off when init finished
restore_setup(); // restore config from eeprom
// Read array named "setupEE" from DataEEPROM and place
// the result into array in RAM named, "setup"
cs = calc_cksum(sizeof(PID)/sizeof(int),(int*)&PID);
if ( cs != PID.cksum)
{
printf("No valid setup found in EEPROM, using defaults.\r\n"); // opps, no valid setup detected
init_pid();
clear_EE();
save_setup();
}
else
{
printf("Using setup from eeprom.. ? for help\r\n");
PID.error =0; /* to avoid some bad bugs */
PID.output = 0;
PID.command = 0;
PID.feedback = 0;
print_tuning();
}
new_cmd = last_cmd = new_fb = last_fb = 0;
set_pwm( 0.0 );
// make sure we dont move on enabling
cmd_posn = POSCNT; // make 16bit incr registers match
PID.feedback = PID.command = 0L; // make 32 bit counter match
new_cmd = last_cmd = new_fb = last_fb = 0;
PID.error_i = 0.0; // reset integrator
PID.enable = 0;
while (1)
{
// look for serial cmds
// doing this while svo is enabled will cause bumps in servo loop
// because of serial i/o time ( unless we get smart and move svo loop
// into an isr )
if (rxrdy) process_serial_buffer();
test_handle_print();
if(error_flags & 0b00000001) // "maxerror exceeded" error
{
setErr();
printf("MAXERROR exceeded!\r\n");
}
}
return 0;
}
И есть еще одно место в модуле commands.c
void print_tuning(void)
{
// __asm__ volatile ("DISI #0x3FFF");
printf("\rCurrent Settings:\r\n");
Из ВСЕГО СПИСКА ВЫВОДИТСЯ ТОЛЬКО ЭТА СТРОКА (см. принт скрин выше)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printf("servo enabled = %d\r\n", PID.enable);
printf("(p) = %f\r\n", (double)PID.pgain);
printf("(i) = %f\r\n", (double)PID.igain);
printf("(d) = %f\r\n", (double)PID.dgain);
printf("FF(0) = %f\r\n", (double)PID.ff0gain);
printf("FF(1) = %f\r\n", (double)PID.ff1gain);
printf("dead(b)and = %f\r\n",(double)PID.deadband);
printf("(m)ax Output = %.2f\r\n",(double)PID.maxoutput);
printf("(f)ault error = %f\r\n", (double)PID.maxerror);
printf("(x)pc cmd multiplier = %hu\r\n", PID.multiplier);
printf("(t)icks per servo cycle= %hu\r\n",PID.ticksperservo);
printf("(h)all timeout= %lu\r\n",PID.HallTimeout);
printf("char(g)e elcos= %u\r\n",PID.DoChargeElcos);
printf("phase (a)dvance= %u\r\n",PID.PhaseAdvance);
printf("SVM (c)ycle= %u\r\n",PID.SVMCycle);
// DISICNT = 0;
}
Т.е. из всех операторов printf идущих подряд выполняется только один. Иногда два...
Что то похоже перезапускает проц. (((