聚丰项目 > 基于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;
}