Plotting data from adc in matlab
8 views (last 30 days)
Show older comments
code is below. How can I plot the dene[i] in code in matlab?
#include <stm32f4xx.h>
#include <stm32f4xx_conf.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_adc.h>
#include <stm32f4xx_gpio.h>
ADC_InitTypeDef ADC_init_structure; //Structure for adc confguration
GPIO_InitTypeDef alper; //Structure for analog input pin
int i;
static char dene1[2048];
static char dene2[2048];
static char dene3[2048];
static char dene4[2048];
static char dene5[1808];
float dum1;
int ms10Ticks; /* counts 1ms timeTicks */
/*----------------------------------------------------------------------------
SysTick_Handler
*----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
ms10Ticks++;
ADC_SoftwareStartConv(ADC1);//ADC1->CR2 |= (1<<30);
}
/*----------------------------------------------------------------------------
MAIN function
*----------------------------------------------------------------------------*/
int main (void) {
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
GPIO_StructInit(&alper);
alper.GPIO_Pin = GPIO_Pin_5;//The channel 15 is connected to PC5
alper.GPIO_Mode = GPIO_Mode_AN; //The PC5 pin is configured in analog mode
alper.GPIO_PuPd = GPIO_PuPd_NOPULL; //We don't need any pull up or pull down
GPIO_Init(GPIOC,&alper);//Affecting the port with the initialization structure configuration
//GPIOC->MODER |= (3<<10); // PC5--> ADC.15 input olarak ayarla
//GPIOC->PUPDR = 0x00000000; // pull up-down yok
ADC_DeInit();
ADC_init_structure.ADC_DataAlign = ADC_DataAlign_Right;//data converted will be shifted to right
ADC_init_structure.ADC_Resolution = ADC_Resolution_12b;//Input voltage is converted into a 12bit number giving a maximum value of 4096
ADC_init_structure.ADC_ContinuousConvMode = DISABLE; //the conversion is continuous, the input data is converted once
ADC_init_structure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//no trigger for conversion
ADC_init_structure.ADC_NbrOfConversion = 1;
ADC_init_structure.ADC_ScanConvMode = DISABLE;//The scan is configured in one channel
ADC_Init(ADC1,&ADC_init_structure);//Initialize ADC with the previous configuration
//Enable ADC conversion
ADC_Cmd(ADC1,ENABLE);
//Select the channel to be read from
ADC_RegularChannelConfig(ADC1,ADC_Channel_15,1,ADC_SampleTime_144Cycles);
SystemCoreClockUpdate(); /* Get Core Clock Frequency */
if (SysTick_Config(SystemCoreClock / 10000)) { /* SysTick 10 msec interrupts */
while (1); /* Capture error */
}
while(1) { /* Loop forever */
if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)){//if((ADC1->SR & 0x00000002))
if(i<2048)
dene1[i]=(ADC_GetConversionValue(ADC1));
else if(i>2048 && i<4096)
dene2[i-2048]=(ADC_GetConversionValue(ADC1));
else if(i>4096 && i<6144)
dene3[i-4096]=(ADC_GetConversionValue(ADC1));
else if(i>6144 && i<8192)
dene4[i-6144]=(ADC_GetConversionValue(ADC1));
else
dene5[i-8192]=(ADC_GetConversionValue(ADC1));
i++;
if(i==10000){
i=0;
}
}
}
}
0 Comments
Answers (0)
See Also
Categories
Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!