Search the Community

Showing results for tags 'random number'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • News
    • Announcements
    • Suggestions
    • New users say Hi!
  • Spotlight!
    • Sponsor Spotlight
    • Sponsor Giveaways
  • Energia
    • Energia - MSP
    • Energia - TivaC/CC3XXX
    • Energia - C2000
    • Energia Libraries
  • MSP Technical Forums
    • General
    • Compilers and IDEs
    • Development Kits
    • Programmers and Debuggers
    • Code vault
    • Projects
    • Booster Packs
    • Energia
  • Tiva-C, Hercules, CCXXXX ARM Technical Forums
    • General
    • SensorTag
    • Tiva-C, Hercules, CC3XXX Launchpad Booster Packs
    • Code Vault
    • Projects
    • Compilers and IDEs
    • Development Kits and Custom Boards
  • Beagle ARM Cortex A8 Technical Forums
    • General
    • Code Snippets and Scripts
    • Cases, Capes and Plugin Boards
    • Projects
  • General Electronics Forum
    • General Electronics
    • Other Microcontrollers
  • Connect
    • Embedded Systems/Test Equipment Deals
    • Buy, Trade and Sell
    • The 43oh Store
    • Community Projects
    • Fireside Chat
  • C2000 Technical Forums
    • General
    • Development Kits
    • Code Vault
    • Projects
    • BoosterPacks

Calendars

There are no results to display.


Found 2 results

  1. How can I get a random number in Energia which is different on each reset?
  2. In an attempt to port one of my projects from AVR to the MSP430G2553 and failing horribly because the printf() function in CCS does not fit into the 512 bytes RAM, I did manage to port a single function. The function, READrnd(), reads some pre generated random numbers from flash memory. I use them to give my projects some (predefined) randomness. For example, the project I want to port uses the predefined random numbers to "randomly" turn on and off 8 relays. I am going to use it for some night/day simulation in houses on a model railroad track. Anyway, with the MSP430 version of the online number generator you can generate random numbers. Here are the sources. randomvals.h: /* generated using: http://atoomnet.net/?p=462 */ #ifndef RANDOMVALS_H_ #define RANDOMVALS_H_ //32 guaranteed random numbers const uint8_t random0[] PROGMEM = { 0x87, 0x22, 0xFB, 0x0D, 0x23, 0x03, 0x60, 0x3F, 0x7A, 0x65, 0xC5, 0xF2, 0x10, 0xF2, 0x2A, 0xB3, 0x7D, 0xD4, 0x5D, 0x8B, 0xD5, 0xF5, 0x1B, 0x4C, 0xC7, 0x45, 0xAF, 0x5E, 0x81, 0xAB, 0x71, 0xF8, }; #endif /* RANDOMVALS_H_ */ random.h: #ifndef RANDOM_H_ #define RANDOM_H_ #include <stdint.h> uint8_t READrnd(void); #endif /* RANDOM_H_ */ random.c: #include <stdint.h> #include "randomvals.h" uint16_t ptrRnd = 0; //Read a random value from randomvals.h, wrap when reaching the end of the table. uint8_t READrnd() { uint8_t rnd = random0[ptrRnd++]; if (ptrRnd==sizeof(random0)) ptrRnd = 0; return rnd; } With these files you have (in this example) 32 bytes of random numbers to work with. Here is the example program running on the TI launchpad I used to test the above sources. Led1 and led2 will flash seemingly random. main.c: #include <msp430.h> #include <stdint.h> #include "random.h" int main(void) { int i; WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR = 0xFF; //Port 1 all pins output for(; { uint8_t randomValue = READrnd(); //Get 8-bit random value from array P1OUT = randomValue; //Output random value to port 1 //Do nothing for some time for(i = 10000; i >= 0; i--) asm("nop"); } } All settings are default except the optimization: -O4 --opt_for_speed=0 The asm("nop") forces the compiler to not optimize away the (for it) pointless for-loop. I hope you like it and, as a beginner in the MSP430 architecture all feedback is welcome.