Jump to content
43oh

Sir Ferdek

Members
  • Content Count

    17
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Sir Ferdek got a reaction from bluehash in CCS 5: How to Program Two MSPs at Once?   
    You can install Windows on virtual machine and give him exclusive access to the usb port where one of your launchpad is connected. That's how I sniffed usb communication when I've needed linux tools but device worked only under windows . Inception...
  2. Like
    Sir Ferdek got a reaction from Nytblade in CCS 5: How to Program Two MSPs at Once?   
    You can install Windows on virtual machine and give him exclusive access to the usb port where one of your launchpad is connected. That's how I sniffed usb communication when I've needed linux tools but device worked only under windows . Inception...
  3. Like
    Sir Ferdek got a reaction from bluehash in random() not working?   
    //****************************************** //Description: Random number generation using MSP's internal clocks //based on TI's slaa338 //****************************************** //ACLK - set to LFXT1 = VLO BCSCTL3 |= LFXT1S_2; //clear OSCFault flag //wait for clock fault system to react do{ IFG1 &= ~OFIFG; // Clear OSCFault flag } while(BCSCTL3 & LFXT1OF); //DCO default @1MHz, //MCLK - default DCO/1 //SMCLK - default DCO/1 //prepare timer TACCTL0 |= CM_1 + CCIS_1 + CAP; TACTL |= TASSEL_2 + MC_2; //workaround for DCO freeze problem void setRSELx(unsigned char target){ unsigned char current = BCSCTL1 & 0x0F; if((target > 0x0D && current < 0x0C) || (current > 0x0D && target < 0x0C)){ BCSCTL1 = (BCSCTL1 & 0xF0) | 0x0D; } BCSCTL1 = (BCSCTL1 & 0xF0) | (target & 0x0F); } unsigned getRandomCLK(void){ register unsigned i,j; register unsigned maj=0; //majority vote holder register char ACLK_div=0; //ACLK divider randomness register unsigned rnd=0; //return value unsigned bcs_tmp=0; for(i=0;i<16;++i){ maj = 0; for(j=0;j<5;++j){ //wait for capture while(!(TACCTL0 & CCIFG)); //capture occured, clear flag TACCTL0 &= ~CCIFG; if(TACCR0 & 0x01){ maj++; } } rnd <<= 1; //make space for new bit if(maj > 0x02){ //see if there are two or more 1's rnd |= 0x0001; //if so, set new bit } else { rnd &= ~(0x0001); //if not, clear new bit } ACLK_div = rnd<<4; ACLK_div &= 0x30; BCSCTL1 ^= ACLK_div; //now xor DCO modulation bits (see 'slau144i', 5.3.1) DCOCTL ^= 0x1F; //add to RSEL bits to change DCO speed //NOTE: see errata page 3 for DCO freeze problem description bcs_tmp = ((BCSCTL1 + 0x05) & 0x0F); setRSELx(bcs_tmp); } return rnd; //capture timer is left running }
     
    Optimizations are welcome.
  4. Like
    Sir Ferdek got a reaction from bluehash in random() not working?   
    Yes, of course. I just need to find some time to refactor and comment it (you know, exam session is coming ). What's more, there are some drawbacks which should be mentioned before implementing.
     
    First of all, it modifies DCO (modulation, RSELx) to add some randomness.
    Secondly, generating one number, then returning to original frequency, then generating number again makes runstest() think they are less random (no idea why, but it made HUGE difference).The solution to that problem was to batch generate whole table of random numbers and read them one after another when needed. Unfortunately, this creates huge security flaw as they are held in memory, so one can peek and "guess" what the next number is going to be.
    Thirtly, this method was tested by me only at 1MHz DCO speed. No idea what will happen at higher frequencies (notice how dramatically it changes DCO/VLO ratio on which this generator is based).
     
    Anyway, there is still some hope. According to the [tipdf]slaa338[/tipdf] we can use this method only to generate random seed for stream cipher mentioned there (http://eprint.iacr.org/2006/019.pdf). It could be done directly after PUC/POR, changing clocks wouldn't make difference. Or invoke hardware generator just from time to time in order to reinitialize cipher with new seed. Endless posibilities.
     
    Oh, and for your curiosity - generating 1M of random bits @1MHz and transfering them via UART @9600N1 took ~45 minutes . So IMHO it's not the way to go
  5. Like
    Sir Ferdek got a reaction from RomixNL in random() not working?   
    http://www.ti.com/mcu/docs/litabsmultiplefilelist.tsp?sectionId=96&tabId=1502&literatureNumber=slaa338&docCategoryId=1&familyId=914
     
    [tipdf]slaa338[/tipdf]
     
    I have it rewritten in plain C, so let me know if you want it. This method of generating random numbers satisfy requirements for noncritical systems. I have done some accurate tests on 1M samples of bits and compared it to other methods as my project for course assesment and results are quite satisfactory:
    - 50.19% of zeroes, 49.81% of ones
    - FFT is smooth and even without serious frequency peaks
    - runstest() in MATLAB returns 0.3 (1 means that series of data is random with 95% probability, for comparison MATLAB's pseudorandom generator scores less than 0.03)
    - passes birth paradox test
     
     
    PS: Where do I have to look for Energia's source code if I'd like to contribute some lines of mine?
  6. Like
    Sir Ferdek reacted to RobG in [solved] DCO stops when RSELx = 0xF   
    See errata page 3.
     
  7. Like
    Sir Ferdek got a reaction from iVenky in adc sampling time problem   
    If you want to connect ADC12OSC to oscilloscope you need to:
    1) set ADC12CLK to use ADC12OSC (this is default, so no need to do that)
    2) using P2SELx and P2SEL2x change function of P2.7 to give you the output of ADC12CLK
     
    For instance, when using launchpad, I would have to:

    P1DIR |= BIT3; P1SEL |= BIT3; P1SEL2 &= ~BIT3;
     
    Be warned:
    "The ADC10OSC, generated internally, is in the 5-MHz range, but varies with individual devices, supply
    voltage, and temperature. See the device-specific data sheet for the ADC10OSC specification."
  8. Like
    Sir Ferdek got a reaction from iVenky in adc sampling time problem   
    Hello.
    First of all, set GIE bit only once, before the 'while(1)' loop:

    __bis_SR_register(GIE); while (1) { ADC12CTL0 |= ADC12SC; // Start sampling/conversion __bis_SR_register(LPM0_bits); // LPM0, ADC12_ISR will force exit }
     
    Next, rewrite your interrupt procedure and learn some GNU C tricks (dunno if it works with IAR/CCS, but if they call them C compilers, it should :think: ). Honestly, this is the part of your code that makes sampling so freaking slow. You're simply killing CPU with unneeded calculations and memory operations. Try this (not tested ):

    #pragma vector = ADC12_VECTOR __interrupt void ADC12_ISR(void) //oh yeah, another IAR/CCS user { // Toggled this to check the sampling rate P5OUT^=0x02; P4OUT = ADC12MEM0; P3OUT = ADC12MEM0 >> 4; //or ((ADC12MEM0 >> 4) && 0xF0) if you like. __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 }
    Nice, huh?
     
    If it doesn't help, then set DCO to something like 8~16MHz and let the smile on your face appear.
  9. Like
    Sir Ferdek got a reaction from iVenky in adc sampling time problem   
    In your case (single channel single-conversion mode) the answer is: no, not automaticaly. You start ADC by setting ADC12SC bit, which is automagicaly cleared after the conversion. And you set it in the while(1) loop, after waking up from LPM0
    Try this:

    if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF) while(1); // If calibration data is erased // trap CPU BCSCTL1 = CALBC1_16MHZ; // Set range DCOCTL = CALDCO_16MHZ; // Set DCO step + modulation
×
×
  • Create New...