基于GD32F350的数字式电容表设计方案

gd32f350开发板使用了兆易最新推出的arm cortex-m4的32位通用微控制器gd32f350rb,这款芯片自带2路比较器,非常适合用来制作一款低成本的数字式电容表。
设计方案:
图1是由比较器构成的rc自激振荡电路,r1、r2为比较器正端提供1/2偏压,r3是正反馈电阻,待测电容cx与rt、ct决定了振荡器的输出频率,基本不受供电电压影响。比较器负输入端与输出端的波形见图2。当rt和ct固定不变时,比较器输出端pt1输出的方波频率与待测电容cx的容量成反比。
图1
图2
利用gd32f350rb片内自带的轨对轨比较器cmp0,只要外加少量阻容元件,就能构成图1的rc自激振荡电路。然后配置gd32f350的timer1每1秒中断1次,读取脉冲个数并计算就能得到待测电容cx的值。这款低成本的数字电容表的测量范围(具有2位小数的3个自动切换的量程):
1.00pf- 1999.99pf
2.00nf- 999.99nf
1.00uf- 10.00uf
方案实施:
a、硬件资源:
参阅gd32f350手册可知,gd32f350内置的通用比较器可连接的资源非常丰富,用户可以很灵活方便组成各种不同应用功能。本方案(见图3)使用图中红框的连接引脚实现图1自激振荡器功能。比较器的输出直接触发gd32f350内部的exti进行计数。
图3
同时,为开发板配置了一片oled显示屏用来显示测试结果,相关原理图见图4。使用洞洞板焊接了所需的外扩电路。
图4
b、软件资源:
软件流程很简单,见图5.
图5
c、中断资源:
1、adc_cmp_irqn
2、cmp0输出中断exti21
3、timer1_irqn
d、开发环境:
1、使用mdk5;
2、下载gigadevice.gd32f30x0_dfp.1.0.0.pack为mdk5添加驱动补丁。
3、 下载gd官方gd32f3x0_firmware_library_v1.0.0.rar固件库,直接利用gd32f3x0_firmware_library_v1.0.0template文件夹的演示工程修改添加代码。
在gd_eval_led_init()函数中配置了led4来监测1秒中断的工作状况,在官方gd32f3x0_eval.h定义的led有误,请参考http://bbs.eeworld.com.cn/thread-869871-1-1.html进行修改。
e、主要代码
图4
b、软件资源:
软件流程很简单,见图5.
图5
c、中断资源:
1、adc_cmp_irqn
2、cmp0输出中断exti21
3、timer1_irqn
d、开发环境:
1、使用mdk5;
2、下载gigadevice.gd32f30x0_dfp.1.0.0.pack为mdk5添加驱动补丁。
3、 下载gd官方gd32f3x0_firmware_library_v1.0.0.rar固件库,直接利用gd32f3x0_firmware_library_v1.0.0template文件夹的演示工程修改添加代码。
在gd_eval_led_init()函数中配置了led4来监测1秒中断的工作状况,在官方gd32f3x0_eval.h定义的led有误,请参考http://bbs.eeworld.com.cn/thread-869871-1-1.html进行修改。
e、主要代码
main()
#include gd32f3x0.h
#include
#include gd32f3x0_eval.h
#include oled.h
static void rcu_config(void);
static void gpio_config(void);
static void nvic_configuration(void);
static void cmp_config(void);
static void timer1_configuration(void);
static void to_buf(void);
__io uint32_t cap_value,cmp_count=0x00;__io uint32_t cap;
uint8_t number_buf[12],cap_ok=0;
int main(void)
{
systeminit();
rcu_config();
gpio_config();
gd_eval_led_init(led4);
oled_init();
oled_clear();
cmp_config();
timer1_configuration();
nvic_configuration();
lcd_print(8,0,基于gd32f350的,type16x16,type8x16);
lcd_print(24,16,数字电容表,type16x16,type8x16);
cap_ok=0x00;
while(1)
{
while(cap_ok==0x00);
to_buf();
lcd_print(16,40,number_buf,type16x16,type8x16);
cap_ok=0x00;
cmp_count=0;
}
}
cmp_config()
static void cmp_config(void)
{
cmp_mode_init(cmp0,cmp_verylowspeed , cmp_pa5, cmp_hysteresis_high);
cmp_output_init(cmp0,cmp_output_none,cmp_output_polarity_noinverted);//cmp_output_timer2ic0
cmp_enable(cmp0);
}
gpio_config()
static void gpio_config(void)
{
gpio_output_options_set(gpioa,gpio_otype_pp, gpio_ospeed_50mhz,gpio_pin_1|gpio_pin_5);
gpio_mode_set(gpioa,gpio_mode_analog, gpio_pupd_pullup, gpio_pin_1|gpio_pin_5);
gpio_output_options_set(gpioa, gpio_otype_pp, gpio_ospeed_50mhz,gpio_pin_6);
gpio_mode_set(gpioa,gpio_mode_af, gpio_pupd_pullup, gpio_pin_6);
gpio_af_set(gpioa,gpio_af_7, gpio_pin_6);
gpio_output_options_set(gpiob,gpio_otype_pp, gpio_ospeed_50mhz,gpio_pin_0|gpio_pin_1|gpio_pin_12|gpio_pin_14|gpio_pin_15);
gpio_mode_set(gpiob,gpio_mode_output,gpio_pupd_pullup,gpio_pin_0|gpio_pin_1|gpio_pin_12|gpio_pin_14|gpio_pin_15);
}
nvic_configuration()
static void nvic_configuration(void)
{
nvic_priority_group_set(nvic_prigroup_pre1_sub3);
nvic_irq_enable(timer1_irqn,1, 1);
nvic_irq_enable(adc_cmp_irqn,0, 1);
exti_init(exti_21,exti_interrupt,exti_trig_rising);
exti_interrupt_enable(exti_21);
}
timer1_configuration()
void timer1_configuration(void)
{timer_oc_parameter_struct timer_ocintpara;
timer_parameter_structtimer_initpara;
timer_deinit(timer1);
timer_initpara.prescaler=5399;
timer_initpara.alignedmode=timer_counter_edge;
timer_initpara.counterdirection=timer_counter_up;
timer_initpara.period=1480;
timer_initpara.clockdivision=timer_ckdiv_div1;
timer_initpara.repetitioncounter= 0;
timer_init(timer1,&timer_initpara);
timer_ocintpara.ocpolarity=timer_oc_polarity_high;
timer_ocintpara.outputstate= timer_ccx_enable;
timer_channel_output_config(timer1,timer_ch_0,&timer_ocintpara);
timer_channel_output_pulse_value_config(timer1,timer_ch_0,740);
timer_channel_output_mode_config(timer1,timer_ch_0,timer_oc_mode_timing);
timer_channel_output_shadow_config(timer1,timer_ch_0,timer_oc_shadow_disable);
timer_interrupt_enable(timer1,timer_int_ch0);
timer_interrupt_flag_clear(timer1,timer_int_ch0);
timer_enable(timer1);
}
adc_cmp_irqhandler()
void adc_cmp_irqhandler(void)
{
cmp_count++;
exti_pd|=0x200000;
}
timer1_irqhandler()
void timer1_irqhandler(void)
{
if(set== timer_interrupt_flag_get(timer1, timer_int_ch0))
{
timer_interrupt_flag_clear(timer1,timer_int_ch0);
cap_value=cmp_count;
gd_eval_led_toggle(led4);
cap_ok=0x01;
}
}
oled驱动代码网上彼彼皆是,就不再重复贴出了。
运行结果见图6
图6

OPPO如何把AI秀出新高度?
Quest:KACE服务台
噪声对策基础(四):噪声滤片状铁氧体磁珠
传统的实体车钥匙正在快速消亡 车钥匙是如何被干掉的?
首届全球IC企业家大会达成共识:半导体是全球化产业开放合作才能共赢
基于GD32F350的数字式电容表设计方案
未来十年,小米的核心战略将升级为“手机x AIoT”
比亚迪战略投资亿太诺
人工智能快速发展及人性化,人类是否会变得更好?
如果用机器人替代人力,制造业怎么办?
知豆领衔中国首次新能源整车众筹
Qt(C++)使用QChart动态显示3个设备的温度变化曲线
PROTEL技术大全之第三篇
RF电路板分区设计的问题探讨
深圳公交搭载人脸识别系统 让市民享受到更加便利的出行服务
如何轻松掌握机器学习概念和在工业自动化中的应用
小米MIUI9怎么样?小米MIUI9第三批测试又来了,曝光三大新功能
新机不是小米6? 何来惊艳众人
支持jesd204b协议高速DAC芯片AD9144-FMC-EBZ
2017千元级热门CPU比拼,谁才是强者