This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Sync using the two block continues read (ADC10 DTC)

Hi everyone,

I am trying to use the two block continues transfer (DTC) using the MPS430 microcontroller. I have created a very simple program that it seems to work fine, but I am trying to figure out what it is the best way to synchronize the writing to the each block and the reading from the main program. I am using a variable called readingBlockNum to synchronize between the called to the interrupt (when a block has been written)and the main loop, but I doubt that it is the best way to do it.

I would appreciate if anyone can suggest a better solution


volatile char readingBlockNum = 0;

void main()
{
	int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT // Some clk configuration... adc_Setup(); while(1) { // Adding some dummy processing for(i = 0;i<100;i++) { readingBlockNum = 1; __delay_cycles(100); } for(i = 0;i<100;i++) { readingBlockNum = 2; __delay_cycles(100); } // Enable the ADC ADC10CTL0 |= ENC + ADC10SC; // Enable Conversion and conversion start } } void adc_Setup() { ADC10CTL1 = ADC10SSEL_0 + CONSEQ_2; // Repeat single channel and ADC10OSC (5MHz)CLK ADC10CTL0 = ADC10SHT_1 + MSC + ADC10ON + ADC10IE; ADC10AE0 |= 0x01; // P1.0 ADC option select ADC10DTC0 |= ADC10TB + ADC10CT; // Continous two block transfers ADC10DTC1 = 0x64; // 100*2 conversions ADC10SA = (int)adc; ADC10CTL0 |= ENC + ADC10SC; // Start sampling continously __enable_interrupt(); // Enable interrupts } #pragma vector = ADC10_VECTOR __interrupt void ADC10_ISR(void) { if (ADC10DTC0 & ADC10B1) { if(readingBlockNum == 2) // if the main is currently reading the 2 block, we stop to overwrite to the 2 block ADC10CTL0 &= ~ENC; } else { if(readingBlockNum == 1) // if the main is currently reading the 1 block, we stop to overwrite to the 1 block ADC10CTL0 &= ~ENC; } }

  • Antonio,

    What you have seems reasonable to me from a quick glance. I focused primarily on the logic inside the interrupt, but I can't think offhand of a better solution than what you have. The only optimization might be to switch readingBlockNum to a boolean called readingBlockOne that is true (1) when you are actively reading block one and false (0) when you are reading block 2. Comparing as a boolean (zero vs non-zero) is faster than checking equality to another number (basically, you subtract that number from yours, then do a zero compare). However, we are talking maybe a couple clock cycles...probably not worth the effort.

    There may be a software guru (which I am not and do not pretend to be) that comes along and provides a super clean and elegant solution. However, what you have looks clean enough and as long as it works, then I wouldn't worry about it.

    Mike
  • Thanks a lot Mike for answering my question, I have already changed the boolean value.

**Attention** This is a public forum