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.
Hello!
I've come across an example of generating 16-bit random numbers with the use of TimerA, ACLK and SMCLK. TI's wiki code for the MSP430 model is the following:
int TI_getRandomIntegerFromVLO(void) { unsigned int i; int result = 0; // setup Timer_A TA0CCTL1 = CM_1 + CCIS_1 + CAP; TA0CTL |= TASSEL__SMCLK + MC__CONTINUOUS; for(i=0 ; i<16 ; i++) { // shift left result result <<= 1; // wait until Capture flag is set while(!(TA0CCTL1 & CCIFG)); // clear flag TA0CCTL1 &= ~CCIFG; // check LSB if(TA0CCR1 & 0x01) { result |= 0x01; } // change the divison of timer input clock TA0CTL = (TA0CTL & 0xFCFF) | ((TA0CCR1 & 0x03) << 8); } return result; }
It is simple enough and I tried recreating it for MSP432 in Code Composer 6.1, but with no luck so far. Register addresses remain the same if I'm doing this correctly (TA0CCTL1 can get internal ACLK as input via CCIS_1 on both boards), but somehow it gets stuck at the "while(!(TA0CCTL1 & CCIFG));", never moving forward. The only thing I added is the line to set VLO as a source for ACLK:
CSCTL1 = (CSCTL1 & ~(SELA_M | DIVA_M)) | SELA_1;
Does anyone have any idea? Any help would be greatly appreciated.
Ilmars said:>Yes, ACLK has the frequency of VLO at around 9.6 kHz (pin output measured with oscilloscope).
Good. Then connect ACLK output to P2.4 configured as input and use CCIS_0 (CCI1A), check if it works this way - using external capture signal.
It works! I've physically connected P4.2 (ACLK) with P2.5 (input for CCR2), changed TA0CCTL1 to TA0CCTL2 and the output seems to be unsigned 16 bit integers. Thanks a lot! :)
Jimmy,
here might be the reason:
If you have a look into the technical reference manual on page 605, you will find the following:
You are using TA0CCTL1, so your code line
TA0CCTL1 = CM_1 + CCIS_1 + CAP;
results in CCI0B when selecting CCIS_1. Now look at this table on page 91 from the datasheet:
CCI0B is DVss. ACLK is CCI1B, so I guess if you were using TA1 instead of TA0, the internal connection to ACLK will work.
Although it is working for you now - could you test this just for clarity?
Dennis
Edit: But then your setting that is working would not fit :-\ So maybe my thought isn't correct...never used the capture mode so far.
Dennis,
this was indeed the case. When looking at the technical reference I only paid attention to CCIS bits, forgetting about TA0 / TA1 selection. It now works with internal ACLK when using TA1 and not TA0.
Setup code for internal signal:
TA1CCTL1 |= CAP | CM_1 | CCIS_1; TA1CTL |= TASSEL_2 | MC_2;
Thanks to both!
**Attention** This is a public forum