第一步、应变片介绍
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
第二部分:应变片如何测量应变力的(对应的R1\R2\R3\R4实际上的贴片方法):
电桥的四个臂上接工作应变片,都参与机械变形,同处一个温度
场,温度影响相互抵消,电压输出灵敏度高。当 4 个应变片的材料、
阻值都想同时,可推导出以下公式:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
第三部分、原理图(带器件参数):
部分图片来自网络
(注:以上原理图中的R1\R2\R3\R4均为图二对应的电阻。应和图二所示一致。)
第四部分、程序代码:
51代码采集部分:
/*=============================================
AD24位数值提取函数
一般提取6、7、8位数据
=============================================*/
unsigned long ReadCount(void)
{
// unsigned long Count;
unsigned char i;
ADSK=;
Count=;
while(ADDO);
for (i=;i<;i++)
{
ADSK=;
Count=Count<<;
ADSK=;
if(ADDO) Count++;
}
ADSK=;
Count=Count^0x800000;//抑或
ADSK=;
return(Count);
}
STM32代码:
/*=============================================
AD24位数值提取函数
一般提取6、7、8位数据
=============================================*/
//#define ADD0_R GPIO_ResetBits(GPIOA,GPIO_Pin_1)
//#define ADD0_S GPIO_SetBits(GPIOA,GPIO_Pin_1)
//#define ADSK_R GPIO_ResetBits(GPIOA,GPIO_Pin_2)
//#define ADSK_S GPIO_SetBits(GPIOA,GPIO_Pin_2) unsigned long ADC_ReadCount(void)
{
unsigned char i;
unsigned long Count;
Count=;
GPIO_ResetBits(GPIOC,GPIO_Pin_5);//ADSK=0;
delay_us();
while(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4)==)// while(ADDO);
delay_us();
for (i=;i<;i++)
{
GPIO_SetBits(GPIOC,GPIO_Pin_5);//ADSK=1;
delay_us();
Count=Count<<;
GPIO_ResetBits(GPIOC,GPIO_Pin_5);//ADSK=0;
delay_us();
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4)==) Count++;
delay_us();
}
GPIO_SetBits(GPIOC,GPIO_Pin_5);//ADSK=1;
delay_us();
Count=Count^0x800000;//抑或
GPIO_ResetBits(GPIOC,GPIO_Pin_5);//ADSK=0;
delay_us();
return(Count);
}
完整测试代码:
51带串口收发采集书籍的完整代码:
#include<reg52.h>
#include <math.h>
#define uint unsigned int
#define uchar unsigned char
uchar flag ,a ,i;
uchar code table[]="I Get ";
///////////////////////////////////////
sbit ADDO = P1^;
sbit ADSK = P1^;
unsigned long Count;
void delay_50ms(uint t);
/*=============================================
AD24位数值提取函数
一般提取6、7、8位数据
=============================================*/
unsigned long ReadCount(void)
{
// unsigned long Count;
unsigned char i;
ADSK=;
Count=;
while(ADDO);
for (i=;i<;i++)
{
ADSK=;
Count=Count<<;
ADSK=;
if(ADDO) Count++;
}
ADSK=;
Count=Count^0x800000;//抑或
ADSK=;
return(Count);
}
/*============================================
求平均值函数
===============================================*/
long averageValue(uchar times)
{
uchar i;
long sum = ;
for (i = ; i < times; i++)
{
sum += ReadCount();
} return sum / times;
}
/*===============================================
串口初始化函数
===============================================*/
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=;REN=;SM0=;SM1=;EA=;ES=; }
void delay_50ms(uint t)
{
uint j;
for( ;t>;t--)
for(j=;j>;j--); } void main()
{ unsigned long num;
uchar s[];
init();
while()
{
/************************************/
num=averageValue();
num=num-;
num=num*;
for(i=;i>;i--)
{
s[i-]=(uchar)num%+0x30;
if(num<)
s[i-]=0x30;
num=num /;
}
s[]='G';
/************************************/
/*==================================================
long val = (averageValue() - _offset);//_offset
return (float) val / _scale;//再.H函数中设置scale = 416.f =====================================================*/ ES=;//关闭串口中断
for(i=;i<;i++)
{
SBUF=s[i];//通过串口发送数据
while(!TI);//检查是否发送数据发送完毕
TI=;
}
delay_50ms();
} } void set() interrupt
{
RI=;
a=SBUF;
flag=; }
STM32完整代码:
c代码.c 文件
#include<reg52.h>
#include <math.h>
#include <stdio.h>
#define uint unsigned int
#define uchar unsigned char
uchar flag ,a ,i;
uchar code table[]="I Get ";
///////////////////////////////////////
sbit ADDO = P1^;
sbit ADSK = P1^;
unsigned long Count;
void delay_50ms(uint t);
/*=============================================
AD24位数值提取函数
一般提取6、7、8位数据
=============================================*/
unsigned long ReadCount(void)
{
// unsigned long Count;
unsigned char i;
ADSK=;
Count=;
while(ADDO);
for (i=;i<;i++)
{
ADSK=;
Count=Count<<;
ADSK=;
if(ADDO) Count++;
}
ADSK=;
Count=Count^0x800000;//抑或
ADSK=;
return(Count);
}
/*============================================
求平均值函数
===============================================*/
long averageValue(uchar times)
{
uchar i;
long sum = ;
for (i = ; i < times; i++)
{
sum += ReadCount();
} return sum / times;
}
/*===============================================
串口初始化函数
===============================================*/
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=;REN=;SM0=;SM1=;EA=;ES=; }
void delay_50ms(uint t)
{
uint j;
for( ;t>;t--)
for(j=;j>;j--); } void main()
{ unsigned long num;
uchar s[];
init();
while()
{
/************************************/
num=averageValue();
num=num-;
num=num*;
sprintf(s,"称得重量:%f g",num); /************************************/
/*==================================================
long val = (averageValue() - _offset);//_offset
return (float) val / _scale;//再.H函数中设置scale = 416.f =====================================================*/ ES=;//关闭串口中断
for(i=;i<;i++)
{
SBUF=s[i];//通过串口发送数据
while(!TI);//检查是否发送数据发送完毕
TI=;
}
delay_50ms();
} } void set() interrupt
{
RI=;
a=SBUF;
flag=; }
.h文件:
#ifndef __AD24_H
#define __AD24_H
#include "stm32f10x.h"
#include "delay.h"
void ADC24_Configtion(void);
long averageValue(unsigned char times); #endif
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
附录:(此处R1\R2\R3\R4不一定和第二部分的图2中的R1\R2\R3\R4对应)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------贴应变片-------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
贴应变片:
用锉刀和粗砂纸等工具将试件在钢板上的贴片位置的油污、漆层、锈迹、电镀层除去,再用细砂纸打磨成 45°交叉纹,之后用镊子镊起丙酮棉球将贴片处擦洗干净,至棉球洁白为止。
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------应变片的其他贴法:-----------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
应变片的其他贴法:
温度补偿: