|
|
@@ -4,6 +4,7 @@
|
|
|
#include "prot/can_foc_msg.h"
|
|
|
#include "foc/samples.h"
|
|
|
#include "foc/motor/current.h"
|
|
|
+#include "foc/motor/motor.h"
|
|
|
#include "libs/utils.h"
|
|
|
#include "libs/logger.h"
|
|
|
#include "os/os_task.h"
|
|
|
@@ -53,18 +54,16 @@ void can_process_factory_message(can_message_t *can_message){
|
|
|
}
|
|
|
u8 item = decode_u8(can_message->data);
|
|
|
if (item == 1) { //3相驱动测试
|
|
|
- u8 mask = decode_u8((u8 *)can_message->data + 1);
|
|
|
- pwm_3phase_sides(false, mask);
|
|
|
+ u8 duty = decode_u8((u8 *)can_message->data + 1);
|
|
|
+ pwm_3phase_sides(true, 0);
|
|
|
+ u16 duty_time = (u16)((float)duty * FOC_PWM_Half_Period / 100.0f);
|
|
|
+ pwm_update_duty(duty_time, duty_time, duty_time);
|
|
|
}else if (item == 2) {//获取所有电压的采集值
|
|
|
can_response_vols(can_message->src, can_message->key);
|
|
|
return;
|
|
|
}else if (item == 3) { //读取gpio状态
|
|
|
- encode_u16(response + 3, GPIOA_VALUE);
|
|
|
- encode_u16(response + 5, GPIOB_VALUE);
|
|
|
- encode_u16(response + 7, GPIOC_VALUE);
|
|
|
- encode_u16(response + 9, GPIOD_VALUE);
|
|
|
- encode_u16(response + 11, GPIOE_VALUE);
|
|
|
- rsplen += 10;
|
|
|
+ encode_u16(response + 3, gpio_get_pin_values());
|
|
|
+ rsplen += 4;
|
|
|
}else if (item == 4) { // u phase detect
|
|
|
int count = 20;
|
|
|
float uvw[3] = {0, 0, 0};
|
|
|
@@ -89,15 +88,23 @@ void can_process_factory_message(can_message_t *can_message){
|
|
|
rsplen += 6;
|
|
|
}else if (item == 5) { //phase current test
|
|
|
u8 start = decode_u8((u8 *)can_message->data + 1);
|
|
|
- if (start) {
|
|
|
+ if (start == 1) {
|
|
|
pwm_3phase_sides(true, 0); //use pwm output, disable timer break in
|
|
|
if (!start_pwm_adc()) {
|
|
|
response[2] = 1;
|
|
|
break;
|
|
|
}
|
|
|
- }else {
|
|
|
+ }else if (start == 0){
|
|
|
stop_pwm_adc();
|
|
|
pwm_3phase_init();
|
|
|
+ }else {
|
|
|
+ s16 ui = (s16)mot_contrl()->foc.in.curr_abc[0];
|
|
|
+ s16 vi = (s16)mot_contrl()->foc.in.curr_abc[1];
|
|
|
+ s16 wi = (s16)mot_contrl()->foc.in.curr_abc[2];
|
|
|
+ encode_s16(response + 3, ui);
|
|
|
+ encode_s16(response + 5, ui);
|
|
|
+ encode_s16(response + 7, ui);
|
|
|
+ rsplen += 6;
|
|
|
}
|
|
|
}
|
|
|
break;
|