电子设计题目要求:
一、设计任务
设计并制作一台数字显示的多功能电信号测量仪
二、要求
1、基本要求
(1)频率测量:可测量方波、正弦波;频率:0.1Hz~64KHz,测量误差≤0.1%。
(2)幅值测量:可测量方波、正弦波;幅度(峰值): 0.1V~5V;测量误差≤0.1%。
(3)采用LED或LCD显示十进制数字,可同时显示幅值和频率。
真心不知道该怎么实现。为之奈何啊?谁有没有好想法啊?
谢谢…_… 附上我的ADC采样程序跟方波频率程序,太拙了
/*ADC采样,1HZ */
#include
#include
#include"inc/hw_memmap.h"
#include"inc/hw_types.h"
#include"inc/hw_ints.h"
#include"driverlib/sysctl.h"
#include"driverlib/gpio.h"
#include"driverlib/timer.h"
#include"driverlib/adc.h"
#include"driverlib/pin_map.h"
#include"driverlib/debug.h"
#include"driverlib/interrupt.h"
#include"LCD_module.h"
uint32_t ui32ADCData[1];
float ADC_Value = 0;
uint32_t ui32Period = 0;
uint32_t ui32PinRead ;
uint32_t ui32TOF = 0;
void IntHandler()
{
uint32_t ui32Status = 0;
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0x00);
SysCtlDelay(2000000);
ui32Status = ADCIntStatus(ADC0_BASE,3,false);
if(ui32Status && ADC_INT_SS3)
{
ui32TOF = 1;
ADCSequenceDataGet(ADC0_BASE, 3, ui32ADCData);
ADC_Value = (3.3) * (ui32ADCData[0]) / 0xFFF;
}
ADCIntClear(ADC0_BASE,3);
}
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_6);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, 0x02);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC);
ui32Period = SysCtlClockGet();
TimerLoadSet(TIMER0_BASE,TIMER_A,ui32Period - 1);
TimerADCEventSet(TIMER0_BASE,TIMER_ADC_TIMEOUT_A);
TimerEnable(TIMER0_BASE,TIMER_A);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE,GPIO_PIN_0);
GPIOPadConfigSet(GPIO_PORTE_BASE,GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
ADCSequenceConfigure(ADC0_BASE,3,ADC_TRIGGER_TIMER,0);
ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH3|ADC_CTL_IE|ADC_CTL_END);
ADCIntRegister(ADC0_BASE,3,IntHandler);
IntEnable(INT_ADC0SS3_TM4C123);
ADCIntEnable(ADC0_BASE,3);
ADCSequenceEnable(ADC0_BASE,3);
IntMasterEnable();
LCD_pin_init();
LCD_initialization();
LCD_clear_screen();
while(1)
{
TimerControlTrigger(TIMER0_BASE,TIMER_A,true);
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0x40);
LCD_string_16x8(1,1,"ADC_V = ");
LCD_num_16x8(2,1,0,ADC_Value);
LCD_num_16x8(3,1,0,ui32TOF);
}
}
/*Frequence Counter*/
#include
#include
#include"inc/hw_memmap.h"
#include"inc/hw_types.h"
#include"inc/hw_ints.h"
#include"LCD_module.h"
#include"grlib/grlib.h"
#include"driverlib/sysctl.h"
#include"driverlib/gpio.h"
#include"driverlib/debug.h"
#include"driverlib/pin_map.h"
#include"driverlib/interrupt.h"
#include"driverlib/timer.h"
uint32_t ui32Time[5];
uint32_t t = 0;
uint32_t ui32Freq = 0;
uint32_t ui32Period = 0;
uint8_t ui8State = 0;
uint32_t ui32TD = 1;
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_6);
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0x00);
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE,GPIO_PIN_4);
GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
GPIOPinConfigure(GPIO_PB4_T1CCP0);
GPIOPinTypeTimer(GPIO_PORTB_BASE,GPIO_PIN_4);
LCD_pin_init();
LCD_initialization();
LCD_clear_screen();
TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC);
ui32Period = SysCtlClockGet() ;
TimerLoadSet(TIMER0_BASE,TIMER_A,ui32Period-1);
IntEnable(INT_TIMER0A_TM4C123);
TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
IntMasterEnable();
TimerConfigure(TIMER1_BASE,TIMER_CFG_A_CAP_COUNT_UP |TIMER_CFG_SPLIT_PAIR);
TimerControlEvent(TIMER1_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
/* IntEnable(INT_TIMER1B_TM4C123);
TimerIntEnable(TIMER0_BASE,TIMER_CAPA_EVENT);
IntMasterEnable();*/
TimerEnable(TIMER0_BASE,TIMER_A);
TimerEnable(TIMER1_BASE,TIMER_A);
while(1)
{
LCD_string_16x8(1,1,"The Freq is:");
LCD_num_16x8(2,1,0,ui32Freq);
LCD_string_16x8(3,1,"Hz");
LCD_num_16x8(4,1,0,t);
LCD_num_16x8(4,3,0,ui32Time[t]);
}
}
void IntHandler()
{
ui32Time[t] = TimerValueGet(TIMER1_BASE,TIMER_A);
t++;
if(t == 5)
{
ui32TD = ui32Time[4] - ui32Time[0];
ui32Freq = ui32TD/5 ;
t=0;
ui32Time[0] = 0;
}
if(ui8State)
ui8State = 0;
else
ui8State = 0x40;
TimerIntClear(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
// SysCtlDelay(200000);
}
文中LCD的函数在头文件里。