Jump to content
43oh

NatureTM

Members
  • Content Count

    218
  • Joined

  • Last visited

  • Days Won

    13

Reputation Activity

  1. Like
    NatureTM got a reaction from thanhtran in 2500V PSU   
    I bought a 2.5kV "laser" power supply from a surplus store this afternoon. It runs off of 9V and that's all the specs I have. The power input wires were yanked out of the base, so I got it at half price! A little drilling and soldering and I should be in business.
     
    This is the first time I've played with anything HV so I had a couple questions maybe someone can answer. I plan to be cautious when "experimenting," but how dangerous is this thing really? Will it be safer to run off a 9V battery vs 9 volts from a PSU I plug into the wall? I'm guessing it would be but I don't really know.
     
    I was hoping to make a TEA Laser (http://www.sparkbangbuzz.com/tealaser/tealaser7.htm) but it looks like I'd need more voltage. Maybe I could pair this with my MIDI stuff and make arc music (http://hackaday.com/2010/05/23/spark-plug-music/). Or, I'd like to hear if anyone has any interesting suggestions for a project.
     
    Also, this is too high of a voltage for my scope. Anyone know if I should expect AC or DC output and what kind of waveform? Or, is it safe to use with my scope and a high value series resistor? And, if I want to switch it on and off at a high speed, can I switch the inputs, or will I have to use HV components and switch the output?
     
    I guess I asked a ton of questions, and I'll probably be googling a bit in the meantime, but if anyone has any input or suggestions I'd really like to hear them. To quote GeekDoc, "I am but a babe in these woods."
  2. Like
    NatureTM got a reaction from lvagasi in Value Line series easy DCO setting library   
    Here's an existing TI lib I modified to work with the Value Line series and CCS.
     
    Since the G series doesn't come with factory-calibrated DCO settings, I wanted an easy way to set the MCLK to 16MHz or some other arbitrary frequency. A TI library existed for setting the DCO using an external watch crystal as a reference, however it didn't work with the G series. It just took some minor editing.
    I think this should be nice for Launchpad owners especially, since the kit comes with an external crystal and a 16MHz rated chip.
     
    DCO Library: http://naturetm.com/files/Launchpad%20setDCO%20lib.rar
  3. Like
    NatureTM reacted to jsolarski in Value Line series easy DCO setting library   
    You can also use the DCO calibration code to customize your calibration, recently I have changed a bunch of my F2013s to Default on 2MHz on startup.
     
    Basically I overwrote the 1MHz calibration with 2 MHz data, tested on my scope and it works like a charm, also loaded up another blink led program and they work with the 2MHz settings .
     
     
    http://justinstech.org/2011/05/msp430-c ... n-for-dco/
     
    What this means is you could set all 3 settings to whatever you need them to be.
    Tested DCO calibration down to 500K, im looking to go lower later, and works up to 16MHz, have not tested any higher.
  4. Like
    NatureTM got a reaction from EngIP in Are the ValueLine chip outputs current limited?   
    The other day I was driving some transistors, and I forgot to put a resistor between the base of the transistor and the MSP430 pin -- effectively a short. It took awhile, but I ended up frying the port. I could run and upload code and stop at breakpoints, but toggling pins didn't have an effect on the output. When I realized my mistake, I touched the MSP and it was pretty warm.
     
    I don't know if this really answers your question, but it seemed worth mentioning.
  5. Like
    NatureTM got a reaction from bluehash in Ideas to share more code   
    I guess there would be two stages to the selection: first selecting the part, and then selecting the user who will write the driver for it. The voting system seems like it would be good for selecting the part. Then, if multiple users want the chance to get the part and author the code, maybe the "thanks" leader-boards could be used to make the selection. It could be a reward for the most helpful users. RobG and zeke are high up in the toplist, and I think that really reflects their skill and helpfulness. This system might be discouraging to new members, however.
  6. Like
    NatureTM got a reaction from zeke in Flashing the missing DCO calibration constants   
    I guess it does belong in this thread. The other thread sets the DCO at runtime, while this thread and the code you posted actually flashes the calibrations after setting the DCO.
     
    The code looks nice, and I wonder if I should edit the first post of the thread to link to what you found instead.
  7. Like
    NatureTM got a reaction from karmik in Complete Newbie question about Timer_A   
    Looks like DanAndDusty beat me to it, but here's what I had. We pretty much said the same thing.
     
    If you only want the LED to be turned on once (so to speak,) you could disable the interrupt or stop the timer when you set the LED.
     

    // Timer A0 interrupt service routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { timerCount = (timerCount + 1) % COUNTDOWN; if(timerCount ==0){ P1OUT ^= (LED_0 + LED_1); // **** 1-shot occured, stop interrupt from repeating **** CCTL0 &= ~CCIE; // clears the interrupt enable bit } }
     
    Or you could use:
    // **** 1-shot occured, stop interrupt from repeating ****
    TACTL &= ~MC_2; // stop the timer altogether. May be preferable if you're done using TimerA
  8. Like
    NatureTM reacted to gordon in Value Line series easy DCO setting library   
    Just bumped into tinyos-msp430 (which is apparently not the same as the MSP430 support in mainline TinyOS).
     
    Relevance to this thread, notice "calibrate-dco" in the "featured downloads" section -- appears to be a quite beefed-up DCO calibration app, with goodies on the side (taking silicon errata into account for various devices when calibrating).
  9. Like
    NatureTM got a reaction from Rickta59 in Value Line series easy DCO setting library   
    Here's an existing TI lib I modified to work with the Value Line series and CCS.
     
    Since the G series doesn't come with factory-calibrated DCO settings, I wanted an easy way to set the MCLK to 16MHz or some other arbitrary frequency. A TI library existed for setting the DCO using an external watch crystal as a reference, however it didn't work with the G series. It just took some minor editing.
    I think this should be nice for Launchpad owners especially, since the kit comes with an external crystal and a 16MHz rated chip.
     
    DCO Library: http://naturetm.com/files/Launchpad%20setDCO%20lib.rar
  10. Like
    NatureTM reacted to GeekDoc in The Party Thread!   
    I hate to be the downer of the party, but I would like to ask all our US members to take a short time Monday (Memorial Day) to truly remember and understand what all of the fallen military members have really meant to this country's history, and to how you live your life today.
     
    (end of old vet's speech :| )
  11. Like
    NatureTM got a reaction from GeekDoc in The Party Thread!   
  12. Like
    NatureTM reacted to zeke in The Party Thread!   
    Oh YEAaaaaaaaaaaaaah!
     
    I feel a fever coming on!
    And it's not even Saturday!
     

  13. Like
    NatureTM got a reaction from zeke in The Party Thread!   
  14. Like
    NatureTM reacted to oPossum in High bit rate async serial ("RS-232") software tx   
    Inline asm version
     

    void tx(unsigned c) { __asm(" mov 0(SP), R14"); // Get the char passed on the stack to R14 // __asm(" mov #0x02, R15"); // Setup bitmask in R15 // __asm(" bic.b R15, &P1OUT"); // 0 Start bit __asm(" jmp $ + 2"); // // __asm(" rrc R14"); // Bit 0 __asm(" jc $ + 18"); // __asm(" bic.b R15, &P1OUT"); // 9 __asm(" nop"); // __asm(" rrc R14"); // Bit 1 __asm(" jc $ + 24"); // __asm(" bic.b R15, &P1OUT"); // 17 __asm(" jmp $ + 24"); // __asm(" bis.b R15, &P1OUT"); // 9 __asm(" nop"); // // __asm(" rrc R14"); // Bit 1 __asm(" jc $ + 8"); // __asm(" bic.b R15, &P1OUT"); // 17 __asm(" jmp $ + 8"); // __asm(" bis.b R15, &P1OUT"); // 17 __asm(" jmp $ + 2"); // // __asm(" rrc R14"); // Bit 2 __asm(" jc $ + 8"); // __asm(" bic.b R15, &P1OUT"); // 26 __asm(" jmp $ + 8"); // __asm(" bis.b R15, &P1OUT"); // 26 __asm(" jmp $ + 2"); // // __asm(" rrc R14"); // Bit 3 __asm(" jc $ + 18"); // __asm(" bic.b R15, &P1OUT"); // 35 __asm(" nop"); // __asm(" rrc R14"); // Bit 4 __asm(" jc $ + 24"); // __asm(" bic.b R15, &P1OUT"); // 43 __asm(" jmp $ + 24"); // __asm(" bis.b R15, &P1OUT"); // 35 __asm(" nop"); // // __asm(" rrc R14"); // Bit 4 __asm(" jc $ + 8"); // __asm(" bic.b R15, &P1OUT"); // 43 __asm(" jmp $ + 8"); // __asm(" bis.b R15, &P1OUT"); // 43 __asm(" jmp $ + 2"); // // __asm(" rrc R14"); // Bit 5 __asm(" jc $ + 8"); // __asm(" bic.b R15, &P1OUT"); // 52 __asm(" jmp $ + 8"); // __asm(" bis.b R15, &P1OUT"); // 52 __asm(" jmp $ + 2"); // // __asm(" rrc R14"); // Bit 6 __asm(" jc $ + 18"); // __asm(" bic.b R15, &P1OUT"); // 61 __asm(" nop"); // __asm(" rrc R14"); // Bit 7 __asm(" jc $ + 24"); // __asm(" bic.b R15, &P1OUT"); // 69 __asm(" jmp $ + 24"); // __asm(" bis.b R15, &P1OUT"); // 61 __asm(" nop"); // // __asm(" rrc R14"); // Bit 7 __asm(" jc $ + 8"); // __asm(" bic.b R15, &P1OUT"); // 69 __asm(" jmp $ + 8"); // __asm(" bis.b R15, &P1OUT"); // 69 __asm(" jmp $ + 2"); // // __asm(" nop"); // Stop Bit __asm(" jmp $ + 2"); // __asm(" bis.b R15, &P1OUT"); // 78 }
  15. Like
    NatureTM reacted to bluehash in Ideas to share more code   
    Posting here as some members miss out on reading the Announcements/Suggestion Posts.
     
    We were thinking about introducing a program where members were given an incentive to write and share code. Lets say member NatureTM is interested in using an accelerometer for his project, but would like some ready to use code. But he doesn't. On top of that, he'll have to invest in an accelerometer breakout. This is where 43oh and the community come in.
     
    Let's call this program "The Code Pot" or "The Community Pot", where you suggest what you need, and we'll try to get the hardware to you. We have been having advertising for a couple of months and we sure can spare some amount to this. There will also be a donate button, if anyone wishes to contribute to the post.
     
    So NatureTM selected a breakout for an accelerometer from Sparkfun. Once there is enough money in the Pot, we'll ship the the hardware to him, directly from the vendor. NatureTM will now be able to write code and share it. He's free to keep the hardware or share it. Be aware that all transactions and member assignments and will be public.
     
    Things to take care of.
    - Following proper code structure.
    - Abuse. Suggesting a hardware, but do not write software for it.
    - Shipping costs. Reasonable(
    - Still thinking...
     
    So how do you guys like it? Would you welcome this? We think it is a great learning and sharing opportunity.Looking forward to your views.
  16. Like
    NatureTM got a reaction from dangpzanco in Generating random numbers.   
    I ran my ADC-based random number generator's output through the DIEHARD battery of tests for randomness quality and it failed miserably. I tried different pins for the ADC and a few different things in the code and all the results were terrible. That should probably have been expected, but a little part of me was still hopeful. I guess we shouldn't use it for any kind of cryptography.
     
    I also took a closer look at how I was removing the bias. I think I just pulled that code out of my booty, because the fact that it led to low bias output seems to just have been luck. It works when the chances of getting a 1 (or 0, I forgot) are around 30%. DIEHARD thought either method had too much bias anyway.
     
    The good news is that I wrote a tiny bit of java to take the serial output and put it into a binary file for consumption by DIEHARD, along with a little MSP430 prog to send the data. 9600 is way too slow, so I run it through an FTDI. My point is, if anyone feels like playing around with randomness and has a function they want tested, I'd gladly run it through my setup, saving you the hassle.
  17. Like
    NatureTM reacted to EngIP in POV with G2211 and little else   
    Something I was messing about with today - I'm quite pleased with the results
     


     
    I suppose the next step would be to put it on a PCB and stick it to the fan in the conservatory, but I can see timing it in being a pain in the neck.
     
    Code:

    #include //This is the header file for your chip. void delay(unsigned int delayTime); void main(void) { WDTCTL = WDTPW + WDTHOLD; //Hold the WDT (WatchDog Timer) P1DIR = 0xff; //Set Port 1 (P1) to output. unsigned int i=250; //This is the delay value between each column (found by trial and error) while(1){ P1OUT = 0x00; delay(i); P1OUT = 0x7C; //Mr GreenFace's first column. delay(i); //The delay P1OUT = 0x82; delay(i); P1OUT = 0xA9; delay(i); P1OUT = 0xA1; delay(i); P1OUT = 0xA9; delay(i); P1OUT = 0x82; delay(i); P1OUT = 0x7C; //Mr GreenFace's last column. delay(i); P1OUT = 0x00; delay(i); } } void delay(unsigned int delayTime){ int x; for (x=0;x x=x*1; } }
  18. Like
    NatureTM reacted to bluehash in Free Digikey shipping tip   
    VIA Dangerousprototypes.com
  19. Like
    NatureTM got a reaction from dangpzanco in Generating random numbers.   
    I was looking for example code for RF2500 last night and came across some TI code for using the ADC as a random number generator. The function was in assembly, so I rewrote it in C:
     

    bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; }
     
    Pin 1.5 is floating unconnected, and is measured by the adc. The LSB is used as the random bit. There's a twist though. Pin 1.4 is also floating unconnected, and is used as Vref+, so the top end of the range is floating as well. I thought that was pretty clever. Nice, TI!
     
    I wrote a few console programs to help me visualize the randomness. It turned out the generator was biased toward producing 0's. This function used with the previous function seemed to remove the bias:
     

    bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } }
     
    To test for bias, I displayed a meandering line in a serial console. If I get more 0's than 1's, the line should slowly skew to the left or right:
     

    #include "msp430g2231.h" #include "config.h" #include "softserial.h" #include #define CONSOLE_WIDTH 80 bool getRandomBit(); bool get0BiasRandomBit(); void main(){ int linePositon = CONSOLE_WIDTH / 2; char cursorPosition; DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; WDTCTL = WDTPW + WDTHOLD; // Stop WDT SoftSerial_init(); _enable_interrupts(); while(1){ for(cursorPosition = 0; cursorPosition < linePositon; cursorPosition++) SoftSerial_xmit('8'); SoftSerial_xmit(' '); cursorPosition++; while(cursorPosition < CONSOLE_WIDTH){ SoftSerial_xmit('8'); cursorPosition++; } if(get0BiasRandomBit()) linePositon++; else linePositon--; if(linePositon < 0) linePositon = CONSOLE_WIDTH + linePositon; else if(linePositon >= CONSOLE_WIDTH - 1) linePositon = linePositon - CONSOLE_WIDTH; } } bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } } bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; }
     
    and some example output from this code:

     
    This sends a comma-separated list of random ints to the console:

    #include "msp430g2231.h" #include "config.h" #include "softserial.h" #include #include int adcGenRand16(); void reverse(char s[]); void itoa(int n, char s[]); void txString(char string[]); bool getRandomBit(); bool get0BiasRandomBit(); void main(){ int random; char string[7]; DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; WDTCTL = WDTPW + WDTHOLD; // Stop WDT SoftSerial_init(); _enable_interrupts(); while(1){ random = adcGenRand16(); itoa(random, string); txString(string); } } void txString(char string[]){ int iString = 0; while(string[iString] != 0){ SoftSerial_xmit(string[iString]); iString++; } SoftSerial_xmit(','); SoftSerial_xmit(' '); } bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } } bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; } int adcGenRand16(){ char bit; unsigned int random; for(bit = 0; bit < 16; bit++){ random <<= 1; random |= get0BiasRandomBit(); } return random; } /* itoa: convert n to characters in s */ void itoa(int n, char s[]) { int i, sign; if ((sign = n) < 0) /* record sign */ n = -n; /* make n positive */ i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ if (sign < 0) s[i++] = '-'; s[i] = '\0'; reverse(s); } /* reverse: reverse string s in place */ void reverse(char s[]) { int i, j; char c; for (i = 0, j = strlen(s)-1; i c = s[i]; s[i] = s[j]; s[j] = c; } }
     

     
    I guess I got a little sidetracked from my original purpose of getting started with the RF2500, but I had fun.
  20. Like
    NatureTM reacted to RobG in MIDI Monitor   
    Nature, you know what they say: it's not when you use it, it's how you use it
     
    I wasn't happy with my first version so I rewrote it and here it is, all new and improved. No more missed messages, headers are correct for the type of message, didn't bother to convert pitch bend values though. Still no SysEx but I think I will leave it at that.
     


     

    #include "msp430g2553.h" void send(char data, char registerSelect); void sendHeader(const char* header); void setLCDData(char startIndex, char data); void clearData(char startIndex); #define sendData(data) send(data, 1) #define sendFunction(data) send(data, 0) #define DATA_PIN BIT6 #define CLOCK_PIN BIT5 #define ENABLE_PIN BIT4 #define MIDI_IN_PIN BIT1 char charIndex = 0; char bitCounter = 0; char digitCounter = 0; char rxData = 0; char rxByte = 1; char channel = 0; char status = 0; char lastStatus = 0; char lcdData[16] = {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20}; const char headerAddr = 0x87; const char dataAddr = 0xC0; const char initSequence[4] = { 0x3C,0x0C,0x01,0x06 }; const char charMap[10] = { 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39 }; const char mainHeader[6] = { 0x4D,0x73,0x67,0x20,0x43,0x68 }; const char noteHeader[9] = { 0x4E,0x6F,0x74,0x65,0x20,0x56,0x65,0x6C,0x20 }; const char ctrlHeader[9] = { 0x43,0x6F,0x6E,0x74,0x20,0x56,0x61,0x6C,0x20 }; const char progHeader[9] = { 0x50,0x72,0x6F,0x67,0x20,0x20,0x20,0x20,0x20 }; const char presHeader[9] = { 0x50,0x72,0x65,0x73,0x20,0x20,0x20,0x20,0x20 }; const char pitchHeader[9] = { 0x4D,0x53,0x42,0x20,0x20,0x4C,0x53,0x42,0x20 }; const char msg[7][3] = { { 0x4F,0x46,0x46 } ,{ 0x20,0x4F,0x4E}, { 0x41,0x46,0x54}, { 0x43,0x43,0x48}, { 0x50,0x43,0x48}, { 0x43,0x48,0x50}, { 0x50,0x57,0x48} }; void main(void) { WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; _delay_cycles(100000); P1OUT &= ~(CLOCK_PIN + DATA_PIN); P1OUT |= ENABLE_PIN; P1DIR |= ENABLE_PIN + CLOCK_PIN + DATA_PIN; P1SEL = MIDI_IN_PIN; P1SEL2 = MIDI_IN_PIN; UCA0CTL1 |= UCSSEL_2; UCA0BR0 = 0x00; UCA0BR1 = 0x01; UCA0CTL1 &= ~UCSWRST; IE2 |= UCA0RXIE; while(charIndex < 4) { sendFunction(initSequence[charIndex]); charIndex++; _delay_cycles(16000); } charIndex = 0; while(charIndex < 6) { sendData(mainHeader[charIndex]); charIndex++; } __bis_SR_register(GIE); while(1) { if(lastStatus != status) { sendFunction(headerAddr); if(status == 3) { sendHeader(ctrlHeader); } else if(status == 4) { sendHeader(progHeader); } else if(status == 5) { sendHeader(presHeader); } else if(status == 6) { sendHeader(pitchHeader); } else { sendHeader(noteHeader); } lastStatus = status; } sendFunction(dataAddr); digitCounter = 0; while(digitCounter < 16) { sendData(lcdData[digitCounter]); digitCounter++; } } } #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { rxData = UCA0RXBUF; if(rxData & BIT7) { if(rxData < 0xF0) { status = (rxData >> 4) - 8; channel = (rxData & 0x0F) + 1; lcdData[0] = msg[status][0]; lcdData[1] = msg[status][1]; lcdData[2] = msg[status][2]; setLCDData(3, channel); } return; } else { if(rxByte == 1) { rxByte = 2; if(status == 4 || status == 5) { clearData(12); rxByte = 1; } else if (status == 6) { setLCDData(12, rxData); return; } setLCDData(8, rxData); } else { rxByte = 1; if(status == 6) { setLCDData(8, rxData); return; } setLCDData(12, rxData); } } } void clearData(char startIndex) { lcdData[startIndex] = 0x20; lcdData[startIndex + 1] = 0x20; lcdData[startIndex + 2] = 0x20; } void sendHeader(const char* header) { char hdrIndex = 0; while(hdrIndex < 9) { sendData(header[hdrIndex]); hdrIndex++; } } void setLCDData(char startIndex, char data) { // int to BCD clearData(startIndex); charIndex = startIndex + 2; lcdData[charIndex] = 0x30; while(data > 0) { lcdData[charIndex] = charMap[data % 10]; data /= 10; charIndex--; } } void send(char data, char registerSelect) { bitCounter = 0; while(bitCounter < 8) { (data & BIT7) ? (P1OUT |= DATA_PIN) : (P1OUT &= ~DATA_PIN); data <<= 1; P1OUT |= CLOCK_PIN; P1OUT &= ~CLOCK_PIN; bitCounter++; } registerSelect ? (P1OUT |= DATA_PIN) : (P1OUT &= ~DATA_PIN); P1OUT &= ~ENABLE_PIN; P1OUT |= ENABLE_PIN; }
  21. Like
    NatureTM got a reaction from GeekDoc in MSP430G2231 IO pull-up/-down resistors - good for anything?   
    It should work the way you say, so I wrote something quick to test it.
     

    #include void main(){ DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; WDTCTL = WDTPW + WDTHOLD; P1DIR &= 0x00; // all pins input P1REN |= 0xFF; // enable all internal resistors while(1){ P1OUT |= 0xFF; // set all internal resistors pull-up if(P1IN != 0xFF) // test if all are actually pulled high while(1); // pin(s) are low, fail, hold here P1OUT &= 0x00; // set all internal resistors pull-down if(P1IN != 0x00) // test if all are actually pulled low while(1); // pin(s) are high, fail, hold here } }
     
    I ran this on my launchpad, and it fails on the second test -- the pull-down test. It looks like pins 1.1, 1.2, and 1.3 were staying high. I pulled the TXD and RXD jumpers, and that fixed pins 1.1 and 1.2. Something on the emulator side must have been pulling them high. As for 1.3, I think the button debounce resistor is pulling it high.
     
    I think the other pins should work as you expect. Now that I think of it, this may have been mentioned on the forum before.
     
    Changing the second test to this stopped the blocking:

    P1OUT &= 0x00; // set all internal resistors pull-down if((P1IN & ~0x0E) != 0x00) // test if all (except 1.1, 1.2, 1.3) are actually pulled low while(1);
  22. Like
    NatureTM got a reaction from roger430 in Generating random numbers.   
    I was looking for example code for RF2500 last night and came across some TI code for using the ADC as a random number generator. The function was in assembly, so I rewrote it in C:
     

    bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; }
     
    Pin 1.5 is floating unconnected, and is measured by the adc. The LSB is used as the random bit. There's a twist though. Pin 1.4 is also floating unconnected, and is used as Vref+, so the top end of the range is floating as well. I thought that was pretty clever. Nice, TI!
     
    I wrote a few console programs to help me visualize the randomness. It turned out the generator was biased toward producing 0's. This function used with the previous function seemed to remove the bias:
     

    bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } }
     
    To test for bias, I displayed a meandering line in a serial console. If I get more 0's than 1's, the line should slowly skew to the left or right:
     

    #include "msp430g2231.h" #include "config.h" #include "softserial.h" #include #define CONSOLE_WIDTH 80 bool getRandomBit(); bool get0BiasRandomBit(); void main(){ int linePositon = CONSOLE_WIDTH / 2; char cursorPosition; DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; WDTCTL = WDTPW + WDTHOLD; // Stop WDT SoftSerial_init(); _enable_interrupts(); while(1){ for(cursorPosition = 0; cursorPosition < linePositon; cursorPosition++) SoftSerial_xmit('8'); SoftSerial_xmit(' '); cursorPosition++; while(cursorPosition < CONSOLE_WIDTH){ SoftSerial_xmit('8'); cursorPosition++; } if(get0BiasRandomBit()) linePositon++; else linePositon--; if(linePositon < 0) linePositon = CONSOLE_WIDTH + linePositon; else if(linePositon >= CONSOLE_WIDTH - 1) linePositon = linePositon - CONSOLE_WIDTH; } } bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } } bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; }
     
    and some example output from this code:

     
    This sends a comma-separated list of random ints to the console:

    #include "msp430g2231.h" #include "config.h" #include "softserial.h" #include #include int adcGenRand16(); void reverse(char s[]); void itoa(int n, char s[]); void txString(char string[]); bool getRandomBit(); bool get0BiasRandomBit(); void main(){ int random; char string[7]; DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; WDTCTL = WDTPW + WDTHOLD; // Stop WDT SoftSerial_init(); _enable_interrupts(); while(1){ random = adcGenRand16(); itoa(random, string); txString(string); } } void txString(char string[]){ int iString = 0; while(string[iString] != 0){ SoftSerial_xmit(string[iString]); iString++; } SoftSerial_xmit(','); SoftSerial_xmit(' '); } bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } } bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; } int adcGenRand16(){ char bit; unsigned int random; for(bit = 0; bit < 16; bit++){ random <<= 1; random |= get0BiasRandomBit(); } return random; } /* itoa: convert n to characters in s */ void itoa(int n, char s[]) { int i, sign; if ((sign = n) < 0) /* record sign */ n = -n; /* make n positive */ i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ if (sign < 0) s[i++] = '-'; s[i] = '\0'; reverse(s); } /* reverse: reverse string s in place */ void reverse(char s[]) { int i, j; char c; for (i = 0, j = strlen(s)-1; i c = s[i]; s[i] = s[j]; s[j] = c; } }
     

     
    I guess I got a little sidetracked from my original purpose of getting started with the RF2500, but I had fun.
  23. Like
    NatureTM got a reaction from jsolarski in Generating random numbers.   
    I was looking for example code for RF2500 last night and came across some TI code for using the ADC as a random number generator. The function was in assembly, so I rewrote it in C:
     

    bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; }
     
    Pin 1.5 is floating unconnected, and is measured by the adc. The LSB is used as the random bit. There's a twist though. Pin 1.4 is also floating unconnected, and is used as Vref+, so the top end of the range is floating as well. I thought that was pretty clever. Nice, TI!
     
    I wrote a few console programs to help me visualize the randomness. It turned out the generator was biased toward producing 0's. This function used with the previous function seemed to remove the bias:
     

    bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } }
     
    To test for bias, I displayed a meandering line in a serial console. If I get more 0's than 1's, the line should slowly skew to the left or right:
     

    #include "msp430g2231.h" #include "config.h" #include "softserial.h" #include #define CONSOLE_WIDTH 80 bool getRandomBit(); bool get0BiasRandomBit(); void main(){ int linePositon = CONSOLE_WIDTH / 2; char cursorPosition; DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; WDTCTL = WDTPW + WDTHOLD; // Stop WDT SoftSerial_init(); _enable_interrupts(); while(1){ for(cursorPosition = 0; cursorPosition < linePositon; cursorPosition++) SoftSerial_xmit('8'); SoftSerial_xmit(' '); cursorPosition++; while(cursorPosition < CONSOLE_WIDTH){ SoftSerial_xmit('8'); cursorPosition++; } if(get0BiasRandomBit()) linePositon++; else linePositon--; if(linePositon < 0) linePositon = CONSOLE_WIDTH + linePositon; else if(linePositon >= CONSOLE_WIDTH - 1) linePositon = linePositon - CONSOLE_WIDTH; } } bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } } bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; }
     
    and some example output from this code:

     
    This sends a comma-separated list of random ints to the console:

    #include "msp430g2231.h" #include "config.h" #include "softserial.h" #include #include int adcGenRand16(); void reverse(char s[]); void itoa(int n, char s[]); void txString(char string[]); bool getRandomBit(); bool get0BiasRandomBit(); void main(){ int random; char string[7]; DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; WDTCTL = WDTPW + WDTHOLD; // Stop WDT SoftSerial_init(); _enable_interrupts(); while(1){ random = adcGenRand16(); itoa(random, string); txString(string); } } void txString(char string[]){ int iString = 0; while(string[iString] != 0){ SoftSerial_xmit(string[iString]); iString++; } SoftSerial_xmit(','); SoftSerial_xmit(' '); } bool get0BiasRandomBit(){ if(getRandomBit()){ if(getRandomBit()) return 0; else return 1; } else{ if(getRandomBit()) return 1; else return 0; } } bool getRandomBit(){ ADC10CTL1 |= INCH_5; ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); return ADC10MEM & 0x01; } int adcGenRand16(){ char bit; unsigned int random; for(bit = 0; bit < 16; bit++){ random <<= 1; random |= get0BiasRandomBit(); } return random; } /* itoa: convert n to characters in s */ void itoa(int n, char s[]) { int i, sign; if ((sign = n) < 0) /* record sign */ n = -n; /* make n positive */ i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ if (sign < 0) s[i++] = '-'; s[i] = '\0'; reverse(s); } /* reverse: reverse string s in place */ void reverse(char s[]) { int i, j; char c; for (i = 0, j = strlen(s)-1; i c = s[i]; s[i] = s[j]; s[j] = c; } }
     

     
    I guess I got a little sidetracked from my original purpose of getting started with the RF2500, but I had fun.
  24. Like
    NatureTM got a reaction from legailutin in Full-duplex software UART for launchpad   
    By, "it just doesn't work," I assume you mean the echo is still working, but it's not storing to the array correctly.
     
    I think what might be happening is that you send a character from terminal, the program moves into that while loop, stores the character to array index 0, and then the loop is repeats. If there isn't already another character waiting, SoftSerial_read() returns -1, the loop exits, and nbr is reinitialized to 0. Next time you send a char, you just overwrite the character you already have in array index 0, when you wanted to place it into array index 1. I actually have some code for something similar.
     

    while(1){ while(SoftSerial_empty()){ // software wait for serial // do something } // we got a char while(dispStr[stringIndex - 1] != 13){ // keep adding characters to the array until we get char 13 (line feed) if ( !SoftSerial_empty() ) { while((c=SoftSerial_read()) != -1) { SoftSerial_xmit((uint8_t)c); dispStr[stringIndex] = c; stringIndex++; } } } dispStr[stringIndex - 1] = 0; // terminate string with null char (replace line feed) stringIndex = 0; }
     
    You could replace "while(dispStr[stringIndex - 1] != 13)" with "while(stingIndex < 16)". There are some ways to clean this example up, but it was just something I had thrown together for another project. I does work for me.
  25. Like
    NatureTM reacted to bluehash in SSD Crash :-(   
    Sorry to hear that.
     
    I was just reading this yesterday.
×
×
  • Create New...