cancel
Showing results for 
Search instead for 
Did you mean: 

How to send data to OP-AMP and get the value

Nicolas Bousmanne
Associate
Posted on May 31, 2017 at 17:02

Hello,

I'm still trying to continue the programmation of my STM32F405 board and I have (again) a little problem. I use a OP-AMP to compare 2 signals by sending him a integer. The return value is always the same even if I change the initial integer and I dont understand why...

I hope this is understandable.

Can you explain me what's wrong in my code or eventually show me some documentation ?

void gpio_initialize()

{

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    GPIO_InitTypeDef GPIO_initStruct_PA_an2;

    GPIO_initStruct_PA_an2.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;

    GPIO_initStruct_PA_an2.GPIO_Mode = GPIO_Mode_AN;

    GPIO_initStruct_PA_an2.GPIO_OType = GPIO_OType_PP;

    GPIO_initStruct_PA_an2.GPIO_PuPd = GPIO_PuPd_NOPULL;

    GPIO_initStruct_PA_an2.GPIO_Speed = GPIO_Speed_100MHz;

    GPIO_Init(GPIOA, &GPIO_initStruct_PA_an2);

}

void dac_initialize()

{

    DAC_InitTypeDef DAC_InitStructure;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

    DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;

    DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;// DAC_WaveGeneration_Triangle;

    DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;

    //DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;

    DAC_Init(DAC_Channel_1, &DAC_InitStructure);

    DAC_Init(DAC_Channel_2, &DAC_InitStructure);

    DAC_Cmd(DAC_Channel_1, ENABLE);

    DAC_Cmd(DAC_Channel_2, ENABLE);

    DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);

    DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);

}

void adc_initialize()

{

    ADC_InitTypeDef ADC_init_struct12b;

    //Clock configuration

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

    //ADC structure configuration

    ADC_DeInit();

    ADC_init_struct12b.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_init_struct12b.ADC_Resolution = ADC_Resolution_12b;

    ADC_init_struct12b.ADC_ContinuousConvMode = ENABLE;

    ADC_init_struct12b.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;

    ADC_init_struct12b.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

    ADC_init_struct12b.ADC_NbrOfConversion = 1;

    ADC_init_struct12b.ADC_ScanConvMode = DISABLE;

    ADC_Init(ADC1, &ADC_init_struct12b);//Initialize ADC with the previous configuration

    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_3Cycles);

    ADC_Cmd(ADC1, ENABLE);

}

int adc_convert_sence()

{

    ADC_SoftwareStartConv(ADC1);

    while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));

    return ADC_GetConversionValue(ADC1);

}

int main(void)

{

    gpio_initialize();

    adc_initialize();

    dac_initialize();

    systickInit(1000);

    

    DAC_SetChannel2Data(DAC_Align_12b_R, 2048);

    while (1)

    {

        DAC_SetChannel1Data(DAC_Align_12b_R, 0);

        delay_ms(20);

        resultSence = adc_convert_sence();

        printf('%d / ', resultSence);

        DAC_SetChannel1Data(DAC_Align_12b_R, 10);

        delay_ms(20);

        resultSence = adc_convert_sence();

        printf('%d / ', resultSence);

        DAC_SetChannel1Data(DAC_Align_12b_R, 500);

        delay_ms(20);

        resultSence = adc_convert_sence();

        printf('%d / ', resultSence);

    }

}

Thanking you in advance,

Nicolas-

1 REPLY 1
Zt Liu
Senior III
Posted on June 02, 2017 at 12:55

1 check DAC output with a digi-meter.

2 try to config the op amp as a buffer first, and check if you can read back the dac value.

3 check integrator RC constant to see whether it would be saturated after 20 msec.