#include "vl6180.h"
#include "iic.h"
#include "main.h"
uint8 data_reg;
/*********************************************************************************************************
* 函 数 名: VL6180X_CheckID
* 功能说明: 获取VL6180X的ID
* 返 回 值: VL6180X_ID
*********************************************************************************************************/
uint8 VL6180X_Read_ID(void)
{
uint8 data_ID;
data_ID = VL6180x_ReadBytes(DEV_ADDR, VL6180X_IDENTIFICATION_MODEL_ID);
return data_ID;
}
//调整收敛值
void VL6180_MUL(uint tt_mul){
uchar dataTemp;
//调整收敛值;
dataTemp = tt_mul>>8;
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, dataTemp); // set early convergence estimate to 5% //small:0x0400, big:0x02ff
dataTemp = tt_mul & 0xFF;
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE + 1, dataTemp); // set early convergence estimate to 5%
}
uint8 VL6180X_Init(){
uchar dataTemp;
if(VL6180X_Read_ID() == VL6180X_IDENTIFICATION_MODEL_ID_RETURN){
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSTEM_MODE_GPIO0, 0x60); // set up GPIO 0 (set to high impedence for now)
VL6180X_WriteBytes(DEV_ADDR, 0x0207, 0x01);
data_reg = VL6180x_ReadBytes(DEV_ADDR, 0x0207);
VL6180X_WriteBytes(DEV_ADDR, 0x0208, 0x01);
VL6180X_WriteBytes(DEV_ADDR, 0x0096, 0x00);
VL6180X_WriteBytes(DEV_ADDR, 0x0097, 0xFD); //常规距离,启用
//VL6180X_WriteBytes(DEV_ADDR, 0x0097, 0x7F); //加大检测距离
VL6180X_WriteBytes(DEV_ADDR, 0x00e3, 0x00);
VL6180X_WriteBytes(DEV_ADDR, 0x00e4, 0x04);
data_reg = VL6180x_ReadBytes(DEV_ADDR, 0x00e4);
VL6180X_WriteBytes(DEV_ADDR, 0x00e5, 0x02);
VL6180X_WriteBytes(DEV_ADDR, 0x00e6, 0x01);
VL6180X_WriteBytes(DEV_ADDR, 0x00e7, 0x03);
VL6180X_WriteBytes(DEV_ADDR, 0x00f5, 0x02);
VL6180X_WriteBytes(DEV_ADDR, 0x00d9, 0x05);
VL6180X_WriteBytes(DEV_ADDR, 0x00db, 0xce);
VL6180X_WriteBytes(DEV_ADDR, 0x00dc, 0x03);
VL6180X_WriteBytes(DEV_ADDR, 0x00dd, 0xf8);
VL6180X_WriteBytes(DEV_ADDR, 0x009f, 0x00);
VL6180X_WriteBytes(DEV_ADDR, 0x00a3, 0x3c); //常规距离,启用
//VL6180X_WriteBytes(DEV_ADDR, 0x00a3, 0x28); //加大检测距离
VL6180X_WriteBytes(DEV_ADDR, 0x00b7, 0x00);
VL6180X_WriteBytes(DEV_ADDR, 0x00bb, 0x3c); //常规距离,启用
//VL6180X_WriteBytes(DEV_ADDR, 0x00bb, 0x28); //加大检测距离
VL6180X_WriteBytes(DEV_ADDR, 0x00b2, 0x09);
VL6180X_WriteBytes(DEV_ADDR, 0x00ca, 0x09);
VL6180X_WriteBytes(DEV_ADDR, 0x0198, 0x01);
VL6180X_WriteBytes(DEV_ADDR, 0x01b0, 0x17);
VL6180X_WriteBytes(DEV_ADDR, 0x01ad, 0x00);
VL6180X_WriteBytes(DEV_ADDR, 0x00ff, 0x05);
VL6180X_WriteBytes(DEV_ADDR, 0x0100, 0x05);
VL6180X_WriteBytes(DEV_ADDR, 0x0199, 0x05);
VL6180X_WriteBytes(DEV_ADDR, 0x01a6, 0x1b);
VL6180X_WriteBytes(DEV_ADDR, 0x01ac, 0x3e);
VL6180X_WriteBytes(DEV_ADDR, 0x01a7, 0x1f);
VL6180X_WriteBytes(DEV_ADDR, 0x0030, 0x00);
data_reg = VL6180x_ReadBytes(DEV_ADDR, 0x0030);
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_INTERMEASUREMENT_PERIOD, 0x0A); // 100 ms interval in steps of 10 ms
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_VHV_REPEAT_RATE, 0xFF); // sets number of range measurements after which autocalibrate is performed
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_VHV_RECALIBRATE, 0x01); // perform temperature calibration of the ranging sensor
// Set Early Convergence Estimate for lower power consumption
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_MAX_CONVERGENCE_TIME, 0x1F); // set max convergence time to 50 ms (steps of 1 ms)
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_RANGE_CHECK_ENABLES, 0x10 | 0x01); // enable (0x01) early convergence estimate
// This ECE is calculated as follows:
// [(1 - % below threshold) x 0.5 x 15630]/ range max convergence time
// This is ~123 ms for 50 ms max convergence time and 80% below threshold
// This is a sixteen bit (2 byte) register with the first byte MSByte and the second LSByte
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, 0x02); // set early convergence estimate to 5% //small:0x0400, big:0x02ff
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE + 1, 0x7F); // set early convergence estimate to 5%
// Configure ALS
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSALS_INTERMEASUREMENT_PERIOD, 0x0A); // set to 100 ms
data_reg = VL6180x_ReadBytes(DEV_ADDR, VL6180X_SYSALS_INTERMEASUREMENT_PERIOD);
// Following is a 16-bit register with the first MSByte reserved
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSALS_INTEGRATION_PERIOD, 0x00);
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSALS_INTEGRATION_PERIOD+1, 0x63); // set ALS integration time to 100 ms in steps of 1 ms
// The internal readout averaging sample period can be adjusted from 0 to 255. Increasing the sampling
// period decreases noise but also reduces the effective max convergence time and increases power consumption:
// Effective max convergence time = max convergence time - readout averaging period (see
// Section 2.5: Range timing). Each unit sample period corresponds to around 64.5 ?s additional
// processing time. The recommended setting is 48 which equates to around 4.3 ms
VL6180X_WriteBytes(DEV_ADDR, VL6180X_READOUT_AVERAGING_SAMPLE_PERIOD, 0x30); // compromise between low noise and increased execution time
// Gain can be 0 = 20, 1 = 10, 2 = 5, 3 = 2.5, 4 = 1.67, 5 = 1.25, 6 = 1.0 and 7 = 40
// These are value possible for the lower nibble. The upper nibble must be 4
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSALS_ANALOGUE_GAIN, 0x40 | 1); // Sets light and dark gain (don't change upper nibble)
data_reg = VL6180x_ReadBytes(DEV_ADDR, VL6180X_SYSALS_ANALOGUE_GAIN);
// Scalar (1 - 32, bits 4:0) to multiply raw ALS count for additonal gain, if necessary
VL6180X_WriteBytes(DEV_ADDR, VL6180X_FIRMWARE_RESULT_SCALER, 0x01);
// Configure the interrupts
//VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSTEM_MODE_GPIO0, 0x00); // set up GPIO 0 (set to high impedence for now)
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSTEM_MODE_GPIO1, 0x00); // set up GPIO 1 (set to high impedence for now)
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSTEM_INTERRUPT_CONFIG_GPIO, 0x24); // enable sample ready interrupt
#if 0
// enable continuous range mode
if(VL6180XMode == contRangeMode) {
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSRANGE_START, 0x03); // start auto range mode
}
// enable continuous ALS mode
if(VL6180XMode == contALSMode) {
// Configure ALS
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSALS_INTERMEASUREMENT_PERIOD, 0x32); // set to 100 ms
// Following is a 16-bit register with the first MSByte reserved
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSALS_INTEGRATION_PERIOD+1, 0x32); // set ALS integration time to 50 ms in steps of 1 ms
VL6180X_WriteBytes(DEV_ADDR, VL6180X_SYSALS_START, 0x03); // start auto range mode
}
没有合适的资源?快使用搜索试试~ 我知道了~
VL6180驱动调优,项目上已验证
共4个文件
h:2个
c:2个
需积分: 0 0 下载量 158 浏览量
2024-03-04
18:07:42
上传
评论
收藏 7KB RAR 举报
温馨提示
1、项目上真实运行驱动,C语言,支持单次和连续测距模式。 2、早期收敛参数测试数据,可参考:https://blog.csdn.net/linyongui/article/details/136458758?spm=1001.2014.3001.5501 3、支持wrap around(环绕串扰)过滤,非API方式,可实现62cm以内稳定测距,实测对62cm~150cm范围的镜面反射串扰过滤效果良好,有需要的朋友可以下载测试下,验证不易,希望对使用这个模块的朋友有些帮助!
资源推荐
资源详情
资源评论
收起资源包目录
iic&VL6180驱动.rar (4个子文件)
iic.h 1KB
vl6180.c 12KB
iic.c 3KB
vl6180.h 8KB
共 4 条
- 1
资源评论
linyongui
- 粉丝: 7
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功