|
本次实验的主题是psoc4中的adc模块,利用adc将模拟信号转化为数字信号,并连续的在oled屏幕上绘制出来,就是一个模拟示波器了。
此外,本次实验还需要Timer的配合,用作定时采集数据;改变Timer计时周期就可以改变示波器采样速率(<adc采样速率),由于oled屏幕采用的是IIC通信,上限速率为1Mbps,也成为该模拟示波器的一个局限。
TopDesign:
PSoC4中ADC_SAR_Seq简介:
Features
Selectable 8, 10 and 12 bit resolutions
Sample rates of up to 1 Msps with 12 bit resolution
Supports both Single Ended and Differential inputs
Different ranges of inputs with multiple reference options
Scan up to 8 channels automatically, or just a single input
Allows an “injection” channel to be added to the scan sequence
with firmware control at runtime
Hardware averaging support
其中adc设置为:单通道,差分,10bit
主要代码:
#include <project.h>
CY_ISR_PROTO(draw);
int div=0;
int16 value=0;
void main()
{
CyGlobalIntEnable;
OLED_Init();
OLED_clearDisplay();
OLED_setPos(17,0);
OLED_print68Str("ADC_read: ");
OLED_Display();
isr_timer_Start();
isr_timer_SetVector(draw);
ADC_Start();
ADC_StartConvert();
Timer_Start();
while(1)
{
OLED_clearPos(72,115,0,0);
OLED_setPos(72,0);
OLED_printNumber_sign(value);
OLED_Display();
}
}
CY_ISR(draw)
{
if(div<127)
{
int temp=value;
value=ADC_GetResult16(0)+3;
value=64-value/2047.0*56;
drawLine(div,temp,++div,value,1);
}
else
{
div=0;
OLED_clearPos(0,128,1,7);
}
}
演示视频与文件文件:
OLED_Wavetest.zip
(1.74 MB, 下载次数: 216)
|
|