Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
bcba03dbeThis file is pinned to the selected release. Download the original to open it in your design tool.
COMP(pwm2uart);
HAL_PIN(u) = 0.0;
HAL_PIN(v) = 0.0;
HAL_PIN(w) = 0.0;
HAL_PIN(uout) = 0.0;
HAL_PIN(vout) = 0.0;
HAL_PIN(wout) = 0.0;
HAL_PIN(enable) = 0.0;
HAL_PIN(volt) = 0.0;
HAL_PIN(pwm_max) = 0.0;
INIT(
);
RT_OUT(
const int res = 2400;
float vlt = PIN(volt);
float e = PIN(enable);
int min = CLAMP((1 - PIN(pwm_max)) / 2.0, 0.0, 1.0) * res;
int max = res - min;
if(vlt > 0.0 && e > 0.0){
data.data[0] = CLAMP(PIN(u) / vlt * res, min, max);
data.data[1] = CLAMP(PIN(v) / vlt * res, min, max);
data.data[2] = CLAMP(PIN(w) / vlt * res, min, max);
}
else{
data.data[0] = 0;
data.data[1] = 0;
data.data[2] = 0;
}
UART_DMA_Buffer[0] = 0x155;
UART_DMA_Buffer[1] = data.byte[0];
UART_DMA_Buffer[2] = data.byte[1];
UART_DMA_Buffer[3] = data.byte[2];
UART_DMA_Buffer[4] = data.byte[3];
UART_DMA_Buffer[5] = data.byte[4];
UART_DMA_Buffer[6] = data.byte[5];
//start DMA transfer
DMA_Cmd(UART_DRV_TX_DMA, DISABLE);
DMA_ClearFlag(UART_DRV_TX_DMA, UART_DRV_TX_DMA_TCIF);
DMA_Cmd(UART_DRV_TX_DMA, ENABLE);
);
ENDCOMP;