The voltage from DAC lower than usual

Status
Not open for further replies.

Max++

Junior Member level 3
Joined
May 24, 2006
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Thailand
Visit site
Activity points
1,495
I use STM32 discovery value line board. Normally, the voltage that get from DAC of this board will be 0-3V from the define value 0-4095. But right now, the voltage that I got it vary between 0-300mV only.
As I know, this board is the old board and never modify Vref. Could you please help, what should be cause of this problem?
 

Hello there,

Kindly ensure Vref line feeding enough voltage to DAC module.There my be a POT to control Vref.

**broken link removed**

Best regards,
 

Code:
#include "stm32f10x.h"

volatile uint32_t Timer=0;
int16_t vout;

/* Init Structure definition */
DAC_InitTypeDef   DAC_InitStructure;
GPIO_InitTypeDef  GPIO_InitStructure;

void Delay(volatile uint32_t ms) {
	volatile uint16_t i,j;
	for(i=0;i<ms;i++)
	for(j=0; j<3442; j++) ;
}

void GPIO_setup()
{
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |	
                         RCC_APB2Periph_GPIOC, ENABLE);  
  // Configure the GPIO Switch B1 pin (PA0)
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  // Configure the GPIO Switch SW2(PC13)
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
}

void GPIO_DAC1_setup()
{
  // Configure PA4 (DAC_OUT1) to Analog in
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void DAC1_setup()
{
  // DAC Periph clock enable 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

  // DAC channel1 Configuration 
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);

  /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
     automatically connected to the DAC converter. */
  DAC_Cmd(DAC_Channel_1, ENABLE);
}

/*--------------------------------------------------------------
  MAIN function
 *------------------------------------------------------------*/
int main (void) 
{
	uint8_t  reading1, previous1=0;
  vout=1000;    
	GPIO_setup();
  GPIO_DAC1_setup();
  DAC1_setup();

   while(1) 
  {
		reading1 = GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0);
    if((reading1 ==1) && (previous1 !=1)  )
    {
      Delay (10);            // delay 10 msec for debounce
			if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1)
			{
				vout=vout+1000;
				if(vout>=4095) 
					vout=4095;
				DAC_SetChannel1Data(DAC_Align_12b_R, vout);
				DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
			}
		}
		Delay(100);
    previous1=reading1;
	}
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…