Bitwise Logic

Thread Starter

PhotoMonger

Joined Jan 7, 2008
16
I know this is probably a stupid question but I can't for the life of me figure it out.

I'm running on an 8051 core, Ti CC2430.
I'm trying to wait until bit ADCCON1.ST (bit 7) has been cleared so I can collect my results. What would be the proper logic to check this bit.

/*Start a conversion by setting ADCCON1.ST=1*/
ADCCON1 |= 0x40;

/* Wait for the conversion to be done indicated by ADCCON1.ST=0 */
while ((ADCCON1 & 0x40));

/*Disable ADC channels since the EM uses them for other things*/
ADCCFG &= ~0xFF;

return(location);


Thanks,
Ian
 

Thread Starter

PhotoMonger

Joined Jan 7, 2008
16
Well I solved my problem. My theory is that it takes a few clock cycles to set everything up before I can correctly start and collect my samples. So.. I had to add in a few "NOP" calls to give the DMA time to update everything. Here is the code. If anyone could enlighten me that would be really great.

uint8* HalAdcReadSeries (uint8 channel, uint8 resolution)
{
uint8 *location = buffer;

#if (HAL_ADC == TRUE)

uint8 i,resbits;
bool complete = FALSE;
volatile uint8 tmp;
/* When doing multple consecutive ADC samples we must use the DMA controller to transfer the samples
* from the ADC registers into XDATA.
*/

ADCCFG |= 0xFF; //Set all PO pins to ADC inputs
ADCCON1 = HAL_ADC_STSEL | HAL_ADC_RAND_STOP | 0x03;
ADCCON3 = 0x05; //For some reson the last 4 bits of ADCCON2 can only be written by writing to ADCCON3
HAL_ADC_CLR_EOC(); //Writing to ADCCON3 will initiate a sample so we must clear the EOC bit to start our series sampling
ADCCON2 = HAL_ADC_REF_AVDD | HAL_ADC_DEC_RATE | 0x05;

switch (resolution)
{
case HAL_ADC_RESOLUTION_8:
resbits = HAL_ADC_DEC_064;
break;
case HAL_ADC_RESOLUTION_10:
resbits = HAL_ADC_DEC_128;
break;
case HAL_ADC_RESOLUTION_12:
resbits = HAL_ADC_DEC_256;
break;
case HAL_ADC_RESOLUTION_14:
default:
resbits = HAL_ADC_DEC_512;
break;
}

halDMADesc_t *ch;
ch = HAL_DMA_GET_DESC1234(3); //Use DMA3 channel3 as adc storage
HAL_DMA_SET_DEST(ch,buffer);
if(resolution == HAL_ADC_RESOLUTION_8) //Just read transfer most sig byte to XDATA
{
HAL_DMA_SET_SOURCE(ch,0xDFBB);
HAL_DMA_SET_WORD_SIZE(ch,0x00); //Trnsfer a 8-bit byte at a time
}
else //Transfer both bytes to XDATA
{
HAL_DMA_SET_SOURCE(ch,0xDFBA);
HAL_DMA_SET_WORD_SIZE(ch,0x01); //Trnsfer a 8-bit byte at a time
}

for(i=0; i<100; i++)
{
asm("NOP");
}

//Arm DMA for sampeling
HAL_DMA_CLEAR_IRQ(3);
HAL_DMA_ARM_CH(3);

/*Start a conversion by setting ADCCON1.ST=1*/
ADCCON1 |= 0x40;

/* Wait for the conversion to be done indicated by ADCCON1.ST=0 */
while(!(HAL_DMA_CHECK_IRQ(3)));

//Disable ADC channes since the EM uses them for other things
ADCCFG &= ~0xFF; //If we turn off the I/O ports our sample won't complete

#endif
return(location);
}


Thanks,
Ian
 
Top