聚豐項目 > 基于AB32VG1開發板的比例閥驅動
比例閥驅動是電液系統的主要應用之一,液壓比例閥是液壓系統的重要組成元件,比例閥的出現以及性能的不斷提升,對液壓設備的動作復雜程度、動作精度,可操控性、智能化有非常重要的意義。而液壓比例閥的驅動裝置對液壓比例閥的性能發揮起到關鍵作用,我們希望能采用國產的芯片實現比例閥的驅動,保證國產比例閥的性能。
hh_wolf
分享hh_wolf
團隊成員
hh_wolf 工程師
硬件部分主要包括以下三部分:
(1)主控裝置:AB32VG1開發板
(2)電流驅動裝置:場效應驅動模塊
(3)執行裝置:比例閥線圈
(4)供電裝置:24V 7A 直流電源
1.AB32VG1開發板
(1)開發平臺:RT-Thread Studio
(2)組態配置
比例閥主要是采用PWM電流驅動,采用閉環控制可以提高控制精度,所以組態配置中使能PWM信號和ADC0通道。此外,在PWM信號上疊加震顫能提高比例閥的動態響應,降低滯環,所以使能了硬件定時器timer。
(3)主要代碼
①PWM信號配置
?? int pwm_pv_sample(int argc, char *argv[])
{
period = 500000; /* 周期為0.5ms,單位為納秒ns */
dir = 1; /* PWM脈沖寬度值的增減方向 */
pulse = 0; /* PWM脈沖寬度值,單位為納秒ns */
/* 查找設備 */
pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);
if (pwm_dev == RT_NULL)
{
rt_kprintf("pwm sample run failed! can't find %s device!\n", PWM_DEV_NAME);
return RT_ERROR;
}
/* 設置PWM周期和脈沖寬度默認值 */
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
/* 使能設備 */
rt_pwm_enable(pwm_dev, PWM_DEV_CHANNEL);
②震顫信號產生
//-----------pwm
/* 定時器超時回調函數 */
RT_SECTION(".irq.timer")
rt_err_t timeout_cb(rt_device_t dev, rt_size_t size)
{
// rt_kprintf("this is hwtimer timeout callback fucntion!\n");
// rt_kprintf("tick is :%d !\n", rt_tick_get());
rt_pin_write(pin, !rt_pin_read(pin));
if (dir)
{
pulse += 5000; // 從0值開始每次增加5000ns
}
else
{
pulse -= 5000; // 從最大值開始每次減少5000ns
}
if (pulse >= period)
{
dir = 0;
}
if (0 == pulse)
{
dir = 1;
}
// 設置PWM周期和脈沖寬度
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
return 0;
}
③電流大小反饋
int adc_vol_sample(int argc, char *argv[])
{
rt_adc_device_t adc_dev;
rt_uint32_t value_A5,value_A4,value_A3,value_A1,value_A0, vol_A5,vol_A4,vol_A3,vol_A1,vol_A0;
rt_err_t ret = RT_EOK;
/* 查找設備 */
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
if (adc_dev == RT_NULL)
{
rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
return RT_ERROR;
}
/* 使能設備 */
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL_A5);
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL_A4);
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL_A3);
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL_A1);
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL_A0);
/* 讀取采樣值 */
value_A5 = rt_adc_read(adc_dev, ADC_DEV_CHANNEL_A5);
value_A4 = rt_adc_read(adc_dev, ADC_DEV_CHANNEL_A4);
value_A3= rt_adc_read(adc_dev, ADC_DEV_CHANNEL_A3);
value_A1 = rt_adc_read(adc_dev, ADC_DEV_CHANNEL_A1);
value_A0 = rt_adc_read(adc_dev, ADC_DEV_CHANNEL_A0);
rt_kprintf("the value is :%d,%d,%d,%d,%d \n", value_A5,value_A4,value_A3,value_A1,value_A0);
/* 轉換為對應電壓值 */
vol_A5 = value_A5 * REFER_VOLTAGE / CONVERT_BITS;
vol_A4 = value_A4 * REFER_VOLTAGE / CONVERT_BITS;
vol_A3 = value_A3 * REFER_VOLTAGE / CONVERT_BITS;
vol_A1 = value_A1 * REFER_VOLTAGE / CONVERT_BITS;
vol_A0 = value_A0 * REFER_VOLTAGE / CONVERT_BITS;
rt_kprintf("the voltage is :%d.%02d ,%d.%02d,%d.%02d,%d.%02d,%d.%02d\n", vol_A5 / 100, vol_A5 % 100,vol_A4 / 100, vol_A4 % 100,vol_A3 / 100, vol_A3 % 100,vol_A1 / 100, vol_A1 % 100,vol_A0 / 100, vol_A0 % 100);
/* 關閉通道 */
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL_A5);
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL_A4);
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL_A3);
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL_A1);
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL_A0);
return ret;
}