예제 #1
0
/* Update value to DAC buffer*/
void Chip_DAC_UpdateValue(LPC_DAC_T *pDAC, uint32_t dac_value)
{
	uint32_t tmp;

	tmp = pDAC->CR & DAC_BIAS_EN;
	tmp |= DAC_VALUE(dac_value);
	/* Update value */
	pDAC->CR = tmp;
}
예제 #2
0
/*********************************************************************//**
 * @brief 		Update value to DAC
 * @param[in] 	DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC
 * @param[in] 	dac_value : value 10 bit to be converted to output
 * @return 		None
 ***********************************************************************/
void DAC_UpdateValue (LPC_DAC_TypeDef *DACx,uint32_t dac_value)
{
	uint32_t tmp;
	CHECK_PARAM(PARAM_DACx(DACx));
	tmp = DACx->DACR & DAC_BIAS_EN;
	tmp |= DAC_VALUE(dac_value);
	// Update value
	DACx->DACR = tmp;
}
예제 #3
0
/*********************************************************************//**
 * @brief 		Update value to DAC
 * @param[in] 	DAC_Id 	the ID of the DAC component that is using, should be: zero (0)
 * @param[in] 	dac_value : value 10 bit to be converted to output
 * @return 		None
 ***********************************************************************/
void DAC_UpdateValue (uint8_t DAC_Id,uint32_t dac_value)
{
	uint32_t tmp;

	LPC_DAC_TypeDef* pDac = DAC_GetPointer(DAC_Id);

	tmp = pDac->CR & DAC_BIAS_EN;

	tmp |= DAC_VALUE(dac_value);

	// Update value
	pDac->CR = tmp;
}
예제 #4
0
파일: dac.c 프로젝트: edarring/lpcopen
/* DMA routine for DAC example */
static void App_DMA_Test(void)
{
	uint32_t tmp = 0;
	volatile uint32_t i = 0;

	/* Initialize GPDMA controller */
	Chip_GPDMA_Init(LPC_GPDMA);
	/* Setting GPDMA interrupt */
	NVIC_DisableIRQ(DMA_IRQn);
	NVIC_SetPriority(DMA_IRQn, ((0x01 << 3) | 0x01));
	NVIC_EnableIRQ(DMA_IRQn);
	/* Get the free channel for DMA transfer */
	dmaChannelNum = Chip_DMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_DAC);

	/* Output DAC value until get 'x' character */
	while (DEBUGIN() != 'x') {
		/* Start D/A conversion */
		tmp++;
		if (tmp == (DATA_SIZE - 1)) {
			tmp = 0;
		}
		/* pre-format the data to DACR register */
		DMAbuffer = (uint32_t) (DAC_VALUE(tmp) | DAC_BIAS_EN);
		for (i = 0; i < 0x10000; i++) ;

		channelTC = 0;
		Chip_DMA_Transfer(LPC_GPDMA, dmaChannelNum,
						  (uint32_t) &DMAbuffer,
						  GPDMA_CONN_DAC,
						  GPDMA_TRANSFERTYPE_M2P_CONTROLLER_DMA,
						  1);

		/* Waiting for writing DAC value completed */
		while (channelTC == 0) {}
	}
	/* Disable interrupts, release DMA channel */
	Chip_DMA_Stop(LPC_GPDMA, dmaChannelNum);
	NVIC_DisableIRQ(DMA_IRQn);
}
예제 #5
0
int32_t Board_DAC_writeDMA(uint16_t* buffer, uint32_t size, bool flagCyclic)
{
   int32_t ret = -1;

   if (size != 0)
   {
	 NVIC_DisableIRQ(DMA_IRQn);
	 dacInfo.flagCyclic = flagCyclic;

         for (dacInfo.samples=0; dacInfo.samples<size; dacInfo.samples++)
  	 {
		dacInfo.dmaBuffer[dacInfo.samples] = (uint32_t) (DAC_VALUE(buffer[dacInfo.samples]));
		if(dacInfo.flagEnableBias)
		    dacInfo.dmaBuffer[dacInfo.samples]|= DAC_BIAS_EN;

		if(dacInfo.samples>= DMA_FIFO_SIZE)
			break;
	 }

	if(dacInfo.dmaChannelDAC==0xFF)
	{
		/* Get the free channel for DMA transfer */
		dacInfo.dmaChannelDAC = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, GPDMA_CONN_DAC);
	}
	else
	{
		Chip_GPDMA_Stop(LPC_GPDMA, dacInfo.dmaChannelDAC);
	}

	/* Start DMA transfer */
	Chip_GPDMA_Transfer(LPC_GPDMA, dacInfo.dmaChannelDAC,
							   (uint32_t) &dacInfo.dmaBuffer, GPDMA_CONN_DAC,
							   GPDMA_TRANSFERTYPE_M2P_CONTROLLER_DMA, dacInfo.samples);
	ret = dacInfo.samples*2;
	NVIC_EnableIRQ(DMA_IRQn);
   }
   return ret;
}