CC3200-UART-ADC-PWM
来源:互联网 发布:linux php不支持mysql 编辑:程序博客网 时间:2024/06/05 06:37
在CC3200SDK-1.2.0上测试可用,下面是main函数的代码:
注意:需使用example adc project 进行代码融合
//采集电压以PWM的方式输出,串口接收相关指令,执行相关操作,显示相关信息#include <string.h>#include <stdint.h>#include <stdlib.h>#include <stdbool.h>#include "utils.h"#include "hw_memmap.h"#include "hw_common_reg.h"#include "hw_types.h"#include "hw_adc.h"#include "hw_ints.h"#include "hw_gprcm.h"#include "rom.h"#include "rom_map.h"#include "interrupt.h"#include "prcm.h"#include "uart.h"#include "pinmux.h"#include "pin.h"#include "adc.h"#include "gpio.h"#include "adc_userinput.h"#include "uart_if.h"#include "gpio_if.h"#include "hw_apps_rcm.h"#include "timer.h"#define USER_INPUT #define UART_PRINT Report#define FOREVER 1#define APP_NAME "ADC Reference"#define NO_OF_SAMPLES 128#define CONSOLE UARTA0_BASE#define UartGetChar() MAP_UARTCharGet(CONSOLE)#define UartPutChar(c) MAP_UARTCharPut(CONSOLE,c)unsigned long pulAdcSamples[4096];#define TIMER_INTERVAL_RELOAD 40035 /* =(255*157) */#define DUTYCYCLE_GRANULARITY 157#define MAX_STRING_LENGTH 80#if defined(ccs)extern void (* const g_pfnVectors[])(void);#endif#if defined(ewarm)extern uVectorEntry __vector_table;#endifstatic void BoardInit(void);static void DisplayBanner(char * AppName);void UpdateDutyCycle(unsigned long ulBase, unsigned long ulTimer, unsigned char ucLevel){ MAP_TimerMatchSet(ulBase,ulTimer,(ucLevel*DUTYCYCLE_GRANULARITY));}void SetupTimerPWMMode(unsigned long ulBase, unsigned long ulTimer, unsigned long ulConfig, unsigned char ucInvert){ MAP_TimerConfigure(ulBase,ulConfig); MAP_TimerPrescaleSet(ulBase,ulTimer,0); MAP_TimerControlLevel(ulBase,ulTimer,ucInvert); MAP_TimerLoadSet(ulBase,ulTimer,TIMER_INTERVAL_RELOAD); MAP_TimerMatchSet(ulBase,ulTimer,TIMER_INTERVAL_RELOAD);}void InitPWMModules(){ MAP_PRCMPeripheralClkEnable(PRCM_TIMERA2, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralClkEnable(PRCM_TIMERA3, PRCM_RUN_MODE_CLK); SetupTimerPWMMode(TIMERA2_BASE, TIMER_B, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM), 1); SetupTimerPWMMode(TIMERA3_BASE, TIMER_A, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM), 1); SetupTimerPWMMode(TIMERA3_BASE, TIMER_B, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM), 1); MAP_TimerEnable(TIMERA2_BASE,TIMER_B); MAP_TimerEnable(TIMERA3_BASE,TIMER_A); MAP_TimerEnable(TIMERA3_BASE,TIMER_B);}void DeInitPWMModules(){ MAP_TimerDisable(TIMERA2_BASE, TIMER_B); MAP_TimerDisable(TIMERA3_BASE, TIMER_A); MAP_TimerDisable(TIMERA3_BASE, TIMER_B); MAP_PRCMPeripheralClkDisable(PRCM_TIMERA2, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralClkDisable(PRCM_TIMERA3, PRCM_RUN_MODE_CLK);}static voidDisplayBanner(char * AppName){ Report("\n\n\n\r"); Report("\t\t *************************************************\n\r"); Report("\t\t CC3200 %s Application \n\r", AppName); Report("\t\t *************************************************\n\r"); Report("\n\n\n\r");}static voidBoardInit(void){#ifndef USE_TIRTOS#if defined(ccs) MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);#endif#if defined(ewarm) MAP_IntVTableBaseSet((unsigned long)&__vector_table);#endif#endif MAP_IntMasterEnable(); MAP_IntEnable(FAULT_SYSTICK); PRCMCC3200MCUInit();}void main(){ unsigned int uiChannel; unsigned int uiIndex=0; unsigned long ulSample; float Brightness; char cString[MAX_STRING_LENGTH+1]; char cCharacter; int iStringLength = 0; BoardInit(); PinMuxConfig(); InitPWMModules(); InitTerm(); DisplayBanner(APP_NAME); while(FOREVER) { uiIndex=0;#ifdef CC3200_ES_1_2_1 // // Enable ADC clocks.###IMPORTANT###Need to be removed for PG 1.32 // HWREG(GPRCM_BASE + GPRCM_O_ADC_CLK_CONFIG) = 0x00000043; HWREG(ADC_BASE + ADC_O_ADC_CTRL) = 0x00000004; HWREG(ADC_BASE + ADC_O_ADC_SPARE0) = 0x00000100; HWREG(ADC_BASE + ADC_O_ADC_SPARE1) = 0x0355AA00;#endif MAP_PinTypeADC(PIN_58,PIN_MODE_255); uiChannel = ADC_CH_1; //设置ADC输入通道 MAP_ADCTimerConfig(ADC_BASE,2^17); MAP_ADCTimerEnable(ADC_BASE); MAP_ADCEnable(ADC_BASE); MAP_ADCChannelEnable(ADC_BASE, uiChannel); while(uiIndex < NO_OF_SAMPLES + 4) { if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel)) { ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel); pulAdcSamples[uiIndex++] = ulSample; } } MAP_ADCChannelDisable(ADC_BASE, uiChannel); uiIndex = 0; UART_PRINT("\n\r"); Brightness = (((((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.4)/4096)*100; //采集电压 UART_PRINT("%f\n\r",(Brightness)); UartPutChar(Brightness); //从串口输出 MAP_UtilsDelay(80000000); cCharacter = UartGetChar(); //从串口输入// UartPutChar(cCharacter); cString[iStringLength] = cCharacter; iStringLength++; switch(cString[0]) { case '0': UpdateDutyCycle(TIMERA2_BASE, TIMER_B, Brightness); //更新PWM占空比 break; case '1': UpdateDutyCycle(TIMERA3_BASE, TIMER_B, Brightness); break; case '2': UpdateDutyCycle(TIMERA3_BASE, TIMER_A, Brightness); break; default : break; } }}
阅读全文
0 0
- CC3200-UART-ADC-PWM
- msp430f5529 uart pwm adc
- CC3200-ADC
- CC3200-PWM
- nRF51822 ADC PWM
- adc和pwm
- 第三章 学习CC3200的ADC
- STC12CA560S2 ADC/PWM相关例程
- PWM实现ADC和DAC
- PWM实现ADC和DAC
- 一起学CC3200系列教程之ADC采集
- 一起学习CC3200系列教程之PWM模式
- STM32 ADC DMA,UART利用DMA传送ADC数据
- STM32+DMA+UART+ADC+内部温度传感器
- 【玩STM32】STM32Duino的引脚映射,ADC,PWM等介绍
- stm32如何实现PWM输出及周期内ADC采样
- 基于fl2440的ADC以及Uart控制(c语言)
- 关于ADC的采样率和UART的波特率
- [noip2010]:导弹拦截
- 关于QML监控系统粘贴板的问题
- 【论文笔记】Learning Deconvolution Network for Semantic Segmentation
- linux之redis启动脚本编写v1.0
- 初识activity工作流
- CC3200-UART-ADC-PWM
- PWA初探
- 关于android studio ndk Error:(115) *** Android NDK: Aborting . Stop.错误
- Linux系统目录结构
- Maven项目pom.xml文件报xxx\target\classes\META-INF\MANIFEST.MF (系统找不到指定的路径)的问题解决
- Spring MVC与JAX-RS比较与分析
- element-ui 表格实现单元格可编辑的方法
- 如何创建一个对象
- Fundebug能够捕获这些BUG