stm32f4 bir periyod için geçen zamanı nasıl bulurum ?

Başlatan serkan, 06 Mart 2019, 20:23:56

serkan

 
void ADC_Configuration(void)
{
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;

ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE; // 1 Channel
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; 
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_15Cycles); // PC1

ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);

ADC_DMACmd(ADC1, ENABLE);

ADC_Cmd(ADC1, ENABLE);
ADC_SoftwareStartConv(ADC1);
}

void TIM2_Configuration(void)
{
 
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  TIM_TimeBaseStructure.TIM_Prescaler = ((SystemCoreClock / 2) / 1000000) - 1;
  TIM_TimeBaseStructure.TIM_Period =1;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
  TIM_Cmd(TIM2, ENABLE);
}


int main(void) {


  SystemInit();
  RCC_Configuration();
  GPIO_Configuration();
  TIM2_Configuration();
  TM_Delay_Init();
  ADC_Configuration(); 
  DMA_Configuration();
  lcd_Init();
  LcdClear(BLACK);
ADC_SoftwareStartConv(ADC1);

uint16_t ornek=1024;
int yeni[ornek];
int eski[ornek]; 
 gecikme=10;
 trig_ger=11;
 
  adc_carpi = 3.333;
  adcbolu   = 80; 
 
  while(1)  {

 trigger(trig_ger);   

  for( int i = 0;i < ornek; i ++){ 
yeni[i] =(((int32_t)ADC_GetConversionValue(ADC1)*adc_carpi)/adcbolu);
  TM_DelayMicros(gecikme); //burada gecikme olmassa dalga sekli oluşmuyor.
  }

  for( int i =0; i<ornek; i ++)
{
    DrawPixel(i + 1,239-eski[i + 1],i + 2,239-eski[i + 2],BLACK);
    DrawPixel(i + 1,239-yeni[i + 1],i + 2,239-yeni[i + 2],WHITE);
    eski[i]=yeni[i];
   }

  }
}