Skip to content
Snippets Groups Projects
Commit 066bb00a authored by Ayoub Farah Hassan's avatar Ayoub Farah Hassan
Browse files

Adding some corrections

- Adding Vref (sent from master) to have the correct duty cycle in slave.
- Master sends 2 in status to reset slave counter (for recording variables) to 0, now master and slave record variables at the same time.
parent 77d115a9
No related tags found
No related merge requests found
......@@ -59,7 +59,7 @@ axs[2].plot(results['duty_cycle'],label = 'duty_cycle')
axs[2].set(ylabel='duty_cycle')
axs[3].plot(results['frequency'],label = 'frequency')
axs[3].set(ylabel='frequency')
axs[3].set(ylabel='frequency (Hz)')
plt.show()
......
......@@ -15,7 +15,7 @@ float output[3] = {0, 0, 0};
/* Controller parameters */
// PI parameters
float Kih = 1000;
float Kih = 4000;
float Kph = 0.5;
float Ts = 100e-6; // sampling time
......
......@@ -177,6 +177,8 @@ void reception_function(void)
Iref = rx_data.consigne.Iref*(100.0/32768.0);
Vref = rx_data.consigne.Vref*(40.0/32768.0);
frequency_main = rx_data.consigne.frequency*(800.0/32768.0);
if(rx_data.consigne.status == 2) counter = 0;
}
//---------------SETUP FUNCTIONS----------------------------------
......@@ -408,8 +410,10 @@ void loop_control_task()
tx_data.consigne.Vref = (int16_t)(Vref*(32768.0/40.0));
tx_data.consigne.frequency = (int16_t) (frequency_main*32768.0/800.0);
tx_data.consigne.status = 1;
if(counter == 0) tx_data.consigne.status = 2;
else tx_data.consigne.status = 1;
rs485Communication.startTransmission();
#ifdef NOCAP
record_array[counter].I_low = I1_low_value;
......@@ -421,7 +425,7 @@ void loop_control_task()
record_array[counter].V_low = V2_low_value;
#endif
if(counter_sin%4 == 0){
if(counter_sin%3 == 0){
record_array[counter].Vhigh_value = V_high;
record_array[counter].duty_cycle = duty_cycle;
record_array[counter].Iref = Iref;
......@@ -440,15 +444,14 @@ void loop_control_task()
#ifdef NOCAP
integral_mem += K_current*pid_period*(Iref - I1_low_value);
Vref = integral_mem + PR_control(Iref - I1_low_value, frequency_main);
duty_cycle = (Vref + integral_mem + PR_control(Iref - I1_low_value, frequency_main))/32.0;
#endif
#ifdef CAP
integral_mem += K_current*pid_period*(Iref - I2_low_value);
duty_cycle = (Vref + integral_mem + PR_control(Iref - I2_low_value, frequency_main))/32.0;
#endif
duty_cycle = (Vref)/32.0;
if (!pwm_enable)
{
pwm_enable = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment