Timer A Capture, Random number

I’ve been trying to get a random number generator based on slaa338 http://focus.ti.com/lit/an/slaa338/slaa338.pdf , however I seem to be doing something wrong:

TACCTL0 = CM_1 + CCIS_1 + CAP;

TACTL = TASSEL_2 + MC_2;

while ((CCTL0 & CCIFG) != CCIFG); // Wait until capt

CCTL0 &= ~CCIFG; // Never happens

I’m not sure what I’m missing.

It looks like you are trying to capture the input from CCI0B. Is this what you intend? If you are, then the pin must be left floating so it must be configured as an input. Which controller model are you using as this will determine which pin is used as CCI0B. You will also need to set the PSEL register to select the alternate pin function.

Regards,

Greg

gm:
It looks like you are trying to capture the input from CCI0B. Is this what you intend? If you are, then the pin must be left floating so it must be configured as an input. Which controller model are you using as this will determine which pin is used as CCI0B. You will also need to set the PSEL register to select the alternate pin function.

Regards,

Greg

Trying to capture from DCO, looks like I have the clocks setup wrong. is MSP430F2131, I’m trying to run this without a crystal using the internal clocks.

Per the document:

Timer_A is setup in capture mode. SMCLK is set to the DCO and set as the input clock to Timer_A. ACLK

is set to the VLO, which is the trigger for the capture. Timer_A counts the number of DCO clock pulses

before the next VLO low-to-high transition occurs. The number of DCO clock pulses is saved by the timer

in a Capture/Compare Register (CCR). The LSB from the CCR is saved by left shifting it into a CPU

register (R12). This process is repeated until 16 LSBs have been saved, forming a 16-bit result that is

almost random.

slaa338 uses TimerA to capture the rising edge of VLO while counting DCO.

F2131 does not have VLO and you did not connect anyting to CCI0B. Thus there is no rising edge and it cannot capture anything.