Changed delay calculation for open loop commutation

This commit is contained in:
Eyck Jentzsch 2018-10-21 22:29:45 +02:00
parent 458c75c5e4
commit 188bd2b5dd
3 changed files with 11 additions and 26 deletions

View File

@ -40,17 +40,6 @@ std::array<uint32_t, 6> senseTable { //! channels to sense during the applied pa
SENSU_N, //5 SENSU_N, //5
SENSV_P //6 SENSV_P //6
}; };
std::array<unsigned int, 18> startupDelays{
/*
200, 150, 100, 80, 70, 65,
60, 55, 50, 45, 40, 35,
25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25
*/
150, 90, 70, 50, 40, 35,
30, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25
};
bool ccw=false; bool ccw=false;
@ -156,12 +145,8 @@ unsigned read_adc(unsigned channel){
* Since Timer/Counter1 is used in this function, it must never be called when * Since Timer/Counter1 is used in this function, it must never be called when
* sensorless operation is running. * sensorless operation is running.
*/ */
void fixed_delay(unsigned short delay){
pwm0::oneshot_delay(STARTUP_DELAY_MULTIPLIER*delay);
}
unsigned short measured_zc_time(unsigned short max_delay){ unsigned short measured_zc_time(unsigned short max_delay){
long delay_us = max_delay * STARTUP_DELAY_MULTIPLIER; long delay_us = max_delay;
auto scaling_factor=0; auto scaling_factor=0;
while(delay_us/(1<<scaling_factor) > std::numeric_limits<unsigned short>::max()){ while(delay_us/(1<<scaling_factor) > std::numeric_limits<unsigned short>::max()){
scaling_factor++; scaling_factor++;
@ -200,20 +185,23 @@ void next_commutation_step(void) {
} }
void start_open_loop(void){ void start_open_loop(void){
auto delay = 30120U;
std::array<double, 2> multiplier={0.83, 1.0};
nextCommutationStep = 0; nextCommutationStep = 0;
//Preposition. //Preposition.
gpio0::port_reg() = (gpio0::port_reg() & ~DRIVE_MASK) | driveTable[nextCommutationStep]; gpio0::port_reg() = (gpio0::port_reg() & ~DRIVE_MASK) | driveTable[nextCommutationStep];
fixed_delay(STARTUP_LOCK_DELAY); //fixed_delay(STARTUP_LOCK_DELAY);
pwm0::oneshot_delay(STARTUP_DELAY);
next_commutation_step(); next_commutation_step();
auto nextDrivePattern = driveTable[nextCommutationStep]; auto nextDrivePattern = driveTable[nextCommutationStep];
const size_t size=startupDelays.size(); for (size_t i = 0; i < 12; i++){
for (size_t i = 0; i < startupDelays.size()+6*10; i++){
gpio0::port_reg() = (gpio0::port_reg() & ~DRIVE_MASK & 0x00ffffff) gpio0::port_reg() = (gpio0::port_reg() & ~DRIVE_MASK & 0x00ffffff)
| nextDrivePattern | nextCommutationStep<<24; | nextDrivePattern | nextCommutationStep<<24;
auto channel=senseTable[nextCommutationStep]&0x3; auto channel=senseTable[nextCommutationStep]&0x3;
auto zcPolRise = senseTable[nextCommutationStep]<4; auto zcPolRise = senseTable[nextCommutationStep]<4;
auto bemf_0=read_adc(channel); auto bemf_0=read_adc(channel);
fixed_delay(startupDelays[i>=size?size-1:i]); delay*=multiplier[(i/6)%multiplier.size()];
pwm0::oneshot_delay(delay);
auto bemf_1=read_adc(channel); auto bemf_1=read_adc(channel);
auto bemf = bemf_1>bemf_0?bemf_1-bemf_0:bemf_0-bemf_1; auto bemf = bemf_1>bemf_0?bemf_1-bemf_0:bemf_0-bemf_1;
next_commutation_step(); next_commutation_step();
@ -229,8 +217,7 @@ void run_closed_loop(void){
for(;;){ for(;;){
gpio0::port_reg() = (gpio0::port_reg() & ~DRIVE_MASK & 0x00ffffff) gpio0::port_reg() = (gpio0::port_reg() & ~DRIVE_MASK & 0x00ffffff)
| nextDrivePattern | nextCommutationStep<<24; | nextDrivePattern | nextCommutationStep<<24;
zc_delay=measured_zc_time(500); zc_delay=measured_zc_time(50000);
pwm0::oneshot_delay(zc_delay);
next_commutation_step(); next_commutation_step();
nextDrivePattern = driveTable[nextCommutationStep]; nextDrivePattern = driveTable[nextCommutationStep];
} }

View File

@ -29,13 +29,11 @@ enum {
DRIVE_MASK=(1<<UL)|(1<<UH)| (1<<VL)|(1<<VH)| (1<<WL)|(1<<WH) DRIVE_MASK=(1<<UL)|(1<<UH)| (1<<VL)|(1<<VH)| (1<<WL)|(1<<WH)
}; };
//! Startup delays are given in microseconds times STARTUP_DELAY_MULTIPLIER.
const auto STARTUP_DELAY_MULTIPLIER=150;
/*! /*!
* Number of milliseconds to lock rotor in first commutation step before * Number of 10 microseconds to lock rotor in first commutation step before
* the timed startup sequence is initiated. * the timed startup sequence is initiated.
*/ */
const auto STARTUP_LOCK_DELAY=1000; const auto STARTUP_DELAY=25000U;
extern "C" void handle_m_ext_interrupt(); extern "C" void handle_m_ext_interrupt();
extern "C" void handle_m_time_interrupt(); extern "C" void handle_m_time_interrupt();