Jump to content
43oh

larryfraz

Members
  • Content Count

    27
  • Joined

  • Last visited

Reputation Activity

  1. Like
    larryfraz reacted to shluzzzoid in ds1394 RTC + led driver tm1638   
    Hello!
     
    This is my project Real Time Clock. The project used RTC module ds1394, temperature sensor ds18b20 and driver 7-segment display tm1638. msp430g2553 MCU integrates devices with two hardware ports SPI (USART1, USART2).
    Clock Functions:- Showing the time, date, day of the week;
    - Set the alarm;
    - Shows the temperature of the sensor ds18b20;
    - Control the brightness of the indicator.
     
    Video:

     
    Russian description
    Source code

     
    Video:


     
    My project site
     
    Project includes:
    - DS1394 msp430 launchpad interface
    - ds18b20 maxim + msp430 launchpad
    - Library for TM1638 to MSP430
     
     
    PS: my son was born! Now I do not know whether the time to continue the projects. I hope that I can find the time to do a good description of the projects.
     
    PPS: Sorry for my english...
  2. Like
    larryfraz reacted to M-Three in DSP Libraries for Cortex-M3 and other ARM microcontrollers   
    I was looking around for a general dsp library to do FFTs when I came across this page.
     
    Has a sh*t ton of stuff, hopefully helpful to you guys.
     
     
    Four groups of functions:
     
    Windowing function
    Fast Fourier Transform
    Complex magnitude (absolute value of complex frequency)
    Miscellaneous functions: logarithm(x), exp(x), pseudorandom generator
     
    Three library versions
    GCC ( Rowley CrossWorks, Raisonance, …)
    Keil MDK-ARM
    IAR Embedded Workbench
     
     
    Windowing functions (e.g. Hamming window)
    Windowing is very common step before FFT calculation
    Perform speed optimized windowing of input signal before FFT
    16 to 32 bit version performs proper scaling of 16 bit signal for 32 bit FFT
     
     
    FFT functions
    Complex and real FFT, 16 and 32bit FFT versions
    Radix4/2 FFT – sizes 4,8,16,32,64,128,256,512,1024,2048 and 4096
    Inverse FFT available
    Real FFT enables much more efficient processing of the real signals
    16 bit FFT precision comparable with other fixed point implementation – precision determined by necessary scaling by 0.5 in every FFT stage
    32 bit FFT increases dynamic range by 90 dB , needs extra 20% to 50% cycles
    Coefficients located in Flash. RAM location means faster FFT for higher latencies.
     
     
    Magnitude functions
    Calculate complex frequency magnitude mag=sqrt (re^2 + im^2)
    Based on custom 32 bit square root algorithm (7/13 cycles)
    Multiple versions of different speed / precision tradeoffs for 64 bit sqrt
     
     
    Logarithm and exponent functions
    Calculate log2(x) and exp2(x) = 2^x
    log2 input, exp2 output: 16q16 unsigned 1/65536 to 65535+65535/65536
    log2 output, exp2 input : 5q27 signed -15.99999 to 15.99999
    speed: 11/10 cycles ; precision 0.4 ppm / 3 ppm for log2 / exp2
    single multiply conversion to log10(x), ln(x), 10^x, e^x and generic base log, exp
     
    Parallel MLS pseudorandom generator for ARM cpu
    Maximum Length Sequence generated by Linear Feedback Shift Registers
    Periode 2^31-1 to 2^64-1 words (1 to 64 bits wide)
    1 to 64 bits generated in parallel
    Order of magnitude faster than bit based approach, 3-10 cycles per whole word
  3. Like
    larryfraz reacted to Lyon in Using Hardware PWM on Tiva Launchpad   
    Hi,
    I apologize, my fault - the startup.gcc provided was from StrelarisWare version 9453, so the only correction is to add #include <stdint.h> at the beginning of startup_gcc.c file, and you need to place it as the first include, since there are already other two files.
    Please take care to provide an include path to the stdint.h file in your compiler installation if not already specified.
    L
  4. Like
    larryfraz reacted to Druzyek in RPN Scientific Calculator   
    Overview
    This is a scientific calculator I built that uses RPN notation. Features:
    BCD number format with 1-255 places Internal accuracy configurable from 6 to 32 decimal places Two separate 200 level stacks Optional scientific notation Functions: (a)sin, (a)cos, (a)tan, y^x, x root y, e^x, ln, 10^x, log, mod 20x4 character LCD 42 buttons The source code is available on https://github.com/druzyek/RPN_Calculator.
     

     
    Software
    The interface shows 4 levels of the stack, similar to some HP calculators. While I was writing the code for BCD calculations, I used a console program to test the routines. You can download it from GitHub if you want to test out the functionality: rpnmain_pc.c It will compile for Windows if #WINDOWS is defined or for Linux with the ncurses library if #LINUX is defined.
    On Windows: gcc -o rpncalc.exe rpnmain_pc.c On Linux: gcc -lncurses -o rpncalc rpnmain_pc.c Numbers are stored in unpacked BCD format on an external SRAM chip. I wanted to access this memory using variables but there is no convenient way to do this since every variable requires a function to access it. A simple functions like:
    X+=Y*Z-Q; would become something like this (assuming we are passing pointers):
    RAM_Write(X,RAM_Read(X)+(RAM_Read(Y)*RAM_Read(Z)-RAM_Read(Q)); To simplify things, I wrote a preprocessor program that looks for any variables that need to be stored in external RAM and converts access to them to function calls. External variables are all stored as pointers, so the PC version will work exactly the same with or without the preprocessor. To mark variables as external, #pragma directives are used. These are usually ignored by the compiler if they are not recognized, so they are a convenient way to communicate with the preprocessor. Here is an example:
    //Before processing void puts(unsigned char *msg) { #pragma MM_VAR msg for (int i=0;msg[i];i++) putchar(msg[i]); } int main() { #pragma MM_OFFSET 200 #pragma MM_DECLARE unsigned char text1[30]; unsigned char text2[30]; #pragma MM_END text1[0]='A'; text1[1]=0; puts(text1); } //After processing void puts(unsigned char *msg) { #pragma MM_VAR msg for (int i=0;RAM_Read(msg+i);i++) putchar(RAM_Read(msg+i)); } int main() { #pragma MM_OFFSET 200 #pragma MM_DECLARE unsigned char *text1=(unsigned char*)200; unsigned char *text2=(unsigned char*)230; #pragma MM_END RAM_Write(text1+0,'A'); RAM_Write(text1+1,0); puts(text1); } The trig and log functions are computed using CORDIC routines. This is a very efficient way to compute these functions for processors that cannot multiply or divide quickly. Instead, a lookup table is used with adds and shifts, which are much faster. I was able to speed the shifting up even more by using another lookup table that let me right shift 4 digits at a time. One way to measure the accuracy of calculations is with the calculator forensic found here: http://www.rskey.org/~mwsebastian/miscprj/forensics.htm. After setting accuracy to 24 places arcsin(arccos(arctan(tan(cos(sin(9)))))) evaluates to this:

     
    The settings page allows the accuracy to be set from 6 to 32 decimal places. With the default of 12, trig functions calculate in about a second. With 32 decimal places calculations take 3-4 seconds. After setting the accuracy, the program finds the largest element in the CORDIC table that is still significant, so that no time is wasted on elements that have no effect on the answer. The settings page also shows the current battery charge.

     
    When I began this project I wasn't sure how much I could fit into 16kB of firmware space. In the end it grew bigger than this and I had to use two MSP430s to hold everything. Part of this is due to all of the functions used to access external memory. The interface code also added a lot more to the size than I expected but I was able to add checks for most of the functions and add some meaningful error messages.

     
    Hardware
    My design uses two MSP430G2553s connected over UART. One of them (the master) reads the keyboard matrix, updates the LCD, and manages the interface. The other is connected to the data lines of 128k of parallel SRAM and does all of the calculating. The address lines of the SRAM are driven by two 74HC595 shift registers controlled by the second MSP430. The 17th address pin is controlled by the first MSP430 and allows the program to switch between two separate stacks. Here is the schematic: 

     
    The keypad is formed from 42 tactile buttons arranged in a 6x7 matrix and read with a 74HC165 shift register by the master MSP430. The LCD and keyboard share the same pins since they are never used at the same time. Here is the layout of the keys.

     
    The LCD is an HD44780 compatible 20x4 character LCD. It is rated for 5v but the logic works fine at 3.6v. The contrast needs to be close to 5v for anything to show up on the screen, so I used a 555 timer and some diodes to supply around -1.2v to the contrast pin. The result is very solid and clear.
     
    The calculator runs on four AA batteries regulated by an LM1117 configured to supply around 3.5 volts. To run at 16MHz the MSP430s need at least 3.3 volts. The wiggle room between the two voltages will let me see when the batteries are starting to wear down. By the time the voltage gets down to 3.3v, the batteries will be down to 1.15v or so, which can be considered dead.
     
    The PCB is made from perfboard. The top of the board contains female headers so that the keyboard and LCD can be unplugged. Part of the board had to be cut away so that it will fit in the case with the batteries. Although it is quite small, I ended up using over three meters of wire.

     
    The case is soldered out of copper clad. I used a lot of solder on it and it feels very sturdy. I will give it a coat of paint tomorrow before assembling everything.

  5. Like
    larryfraz reacted to Lyon in Using Hardware PWM on Tiva Launchpad   
    Hi,
    Some more useful things:
    L
    gcc-lk-start.zip
  6. Like
    larryfraz reacted to Lyon in Using Hardware PWM on Tiva Launchpad   
    Hi,
    A small picture of the project on Eclipse:
     

  7. Like
    larryfraz reacted to Lyon in Using Hardware PWM on Tiva Launchpad   
    Hi,
    There some problems with your project: 1) You do not need two initializations files, namely startup_gcc.c and LM4F_startup.c. Remove the last one from your project and keep only that from TI (although small changes are needed, later…). As you note, you get some warnings, while the first one compiles OK. 2) Do not know what is LM4F.ld - if from the same author like Makefile, then could be buggy, and bugs shows up when used on little bit more bigger/complex projects than blinky one. 3) The linker must be called from gcc, not directly - this is the recommendation and the good practice. Good to pass the switch -nostartfiles, since you provide your own in startup_gcc.c 4) The Makefile uses some settings from TI for working with floating point (uses softfp libraries) - for this project may not be important, but if really using fp, the hardfp library could be an advantage (is smaller than softfp). 5) The paths: I do not know where this project is created - TI recommendation is to be done inside StellarisWare/TivaWare folder - so if yours is not there, again, the paths shown in Makefile could cause problems. I do not use TI recommendation, made the project elsewhere and add the right path. Correct yours, add them to Makefile (where points this: STELLARISWARE_PATH=../../../../  ??). 6) If you prefix your calls with ROM_ as I have done, then you do not need to compile/link the driverlib, since it is included on-chip. 7) A much more easier approach is to use Eclipse+GCC - together with GNU ARM Eclipse  plug-in (from here: http://sourceforge.net/projects/gnuarmeclipse/)- you do not need to write Makefiles, all this process is managed by the plug-in (it is called "managed make").  8) If you will get warnings from compiling startup_gcc.c, I will tell you how to avoid them.   L
  8. Like
    larryfraz reacted to Lyon in Using Hardware PWM on Tiva Launchpad   
    Hi,
    I checked the posted code and compile correctly, with shown settings. I have slightly modified it, to allow ROM functions calls. The tested version is this:
     
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_gpio.h"
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pwm.h"
    #include "driverlib/rom.h"

    int
    main(void)
    { unsigned long ulPeriod;

        ROM_FPUEnable();
    ROM_FPUStackingEnable();

    //Set the clock
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL |SYSCTL_OSC_MAIN |
             SYSCTL_XTAL_16MHZ);

    //Configure PWM Clock to match system
    ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    // Enable the peripherals used by this program.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //The Tiva Launchpad has two modules (0 and 1). Module 1 covers the LED pins
    ulPeriod = ROM_SysCtlClockGet() / 200; //PWM frequency 200HZ

    //Configure PF1,PF2,PF3 Pins as PWM
    ROM_GPIOPinConfigure(GPIO_PF1_M1PWM5);
    ROM_GPIOPinConfigure(GPIO_PF2_M1PWM6);
    ROM_GPIOPinConfigure(GPIO_PF3_M1PWM7);
    ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

    //Configure PWM Options
    //PWM_GEN_2 Covers M1PWM4 and M1PWM5
    //PWM_GEN_3 Covers M1PWM6 and M1PWM7 See page 207 4/11/13 DriverLib doc
    ROM_PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    ROM_PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);

    //Set the Period (expressed in clock ticks)
    ROM_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ulPeriod);
    ROM_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ulPeriod);

    //Set PWM duty-50% (Period /2)
    ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ulPeriod/2);
    ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6,ulPeriod/2);
    ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7,ulPeriod/2);

    // Enable the PWM generator
    ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_2);
    ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_3);

    // Turn on the Output pins
    ROM_PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT |PWM_OUT_6_BIT|PWM_OUT_7_BIT, true);

    //Do nothing
    while(1)
    {

    }

    }
     
    For the next several days I do not have an board available to test it...
    The settings are here:
     
    // tried to post a picture, but seems to not work… 
    DEBUG PART_TM4C123GH6PM TARGET_IS_BLIZZARD_RA1 gcc  
    Check again - or at least post the errors or some settings.
    L
  9. Like
    larryfraz reacted to Lyon in Using Hardware PWM on Tiva Launchpad   
    Hi,
    Please review your defines, hope this one: PART=TM4C123GH6PM is only a typing mistake. It should be PART_TM4C123GH6PM.
    L
  10. Like
    larryfraz reacted to bluehash in Algorithmic synth project   
    Looks pretty neat. I'm dumb on the MIDI side, hopefully @@RobG will appreciate this. Maybe explain like I'm five 
    Also, add a link to this page from the POTM  contest thread, so people know you have entered.
  11. Like
    larryfraz got a reaction from RobG in Algorithmic synth project   
    My POTM entry.
     

     
    MIDI_CV.zip
  12. Like
    larryfraz got a reaction from bluehash in Algorithmic synth project   
    This is a simple algorithmic synthesis MSP430 hack of the little Korg Monotron ribbon synth, using CV and gate from the Launchpad through a prototype board from the 43oh store. It receives midi clock and some controllers through uart and a standard midi input circuit and jack. CV output is boosted to about 5V with an op amp, no lowpass filtering done, the gate comes off the pin directly. Directions on hacking the Monotron itself are available from many sites.
  13. Like
    larryfraz reacted to gonya707 in Stellaris Drum Machine   
    How come I didn't see this before?
     
    I'm already working on the MIDI support for this, and probably I'll make a drum version of my MIDI sequencer. Thank you for this useful resource.
  14. Like
    larryfraz reacted to oPossum in Stellaris Drum Machine   
    OK, set a breakpoint in the ISR to determine if the timer setup is working properly.
     
    There may be some difference in the Tiva PWM vs the Stellaris PWM that is the problem.
     
    I don't have a Tiva LP, so can't test it myself.
  15. Like
    larryfraz reacted to oPossum in Stellaris Drum Machine   
    This is a quick test of playback of vintage drum machine sounds. In the 80's there where several popular drum machines that used samples of real drums stored in 27xx series EPROMs. They would simply sequentially address the EPROM and the data was sent to a companding DAC (Am6070). Some sounds also had a filter or envelope applied - this code does not do that. These old machines had numerous EPROM chips to store the samples. With modern flash technology it is possible to put a complete sample set right in the microcontroller itself.
     
    Right now this just loops through all the samples in a set. There is no MIDI or any sort of trigger support yet.
     
    Samples are included for:
    Linn LM-1
    Linndrum (LM-2)
    Linn 9000 Drum Computer
    Oberheim DX
    Oberheim DMX
     
     

    StellarisDrums.zip
  16. Like
    larryfraz reacted to Rickta59 in Petit FatFs sound player   
    I've been experimenting with playing sound. I'm using the code below to read raw 8bit unsigned PCM files
    from the SDCard booster pack. I've attached the main routine. It is heavily commented so I'm not going
    to say much more than here it is. The Petit Fat Filesystem code can be found on the documents tab
    of the SDCard booster on the 43oh.com store.
     
    I also want to thank oPossum and woodgrainn with their help creating a decent low pass RC filter. I ended up
    using an LM386 as an amplifier on the P1.2 PWM output. Here is the schematic for that:
     
    http://compendiumarcana.com/forumpics/pwm_amp.png
     
    -rick
     

    /* * pcmplayer.cpp - play a 15.625kHz 8bit mono sound file using PWM. * * This snippet plays raw PCM audio files from an SDcard. It looks * for files named 0.raw, 1.raw ... 9.raw and attempts to play them * in a loop. To create these files, use the Audacity program to * sample sound files, convert stereo to mono, then export them * as 8bit unsigned data 15625Hz without a header. * * The SDcard I/O is handled using Petit FatFs and works with both FAT16 * and FAT32 formatted cards. PetitFS has a streaming read feature which * allows you process each byte from the file without buffering using * its callback feature. * * * Inspired from various sources: * * http://www.arduino.cc/playground/Code/PCMAudio * http://elm-chan.org/fsw/ff/00index_p.html * http://en.wikipedia.org/wiki/Pulse-code_modulation * http://en.wikipedia.org/wiki/Pulse-width_modulation * http://en.wikipedia.org/wiki/Low-pass_filter * http://sim.okawa-denshi.jp/en/CRtool.php * http://www.ti.com/lit/an/slaa497/slaa497.pdf * http://www.proaxis.com/~wagnerj/PWMfil/PWM%20Filters.pdf * * help on low pass filtering from oPossum and woodgrainn * * 3920 bytes on a msp430g2553 with msp430-gcc 4.6.3 -Os */ /** * pins used on msp430g2553 * * +-- --+ * | V | * | | * P1.2 TA0.1<<< | * | | * | | * | >>>> MOSI P1.7 * P1.5 SCK <<<< <<<< MISO P1.6 * P2.0 CS <<<< | * | | * | | * +-----+ * * P1.2 - PWM output, run through a low pass RC filter. I'm using * a 470ohm resistor, and 100nF cap played back on cheap airline * headphones. Don't use these values with PC audio card mic or * line in. * * P1.5, P1.6, P1.7 SCLK, MISO, MOSI (USCI SPI) connect to SD card * P2.0 CS connect to SD card * */ #include #include extern "C" { #include "spi.h" #include "diskio.h" #include "pff.h" } #include "mmc.h" #include "ringbuffer.h" static const uint32_t TIMERA_CLK = 16000000; // SMCLK_FREQ/1 static const uint32_t SAMPLE_RATE = 15625; // nice power of 2 friendly value sample rate RingBuffer sample_buffer = {{0}, 0,0}; // structure to buffer our samples /* * on_streaming_data() - called when pf_read completes a read * * pf_read in streaming mode calls this function after each byte * is read. When we get a new value we stuff it into a ring buffer. * The ISR reads from this ring_buffer. This function is the * producer, the ISR is the consumer. */ void on_streaming_data(uint8_t sample) { register int16_t rc, scaled_sample; scaled_sample = sample < 24 ? 24 : sample; // avoid low range glitches scaled_sample <<= 2; // scale it up from 0-255 to 0-1023 do { /* * stuff this at the end of our circular queue * if rc == -1 then it would overflow, wait for * ISR to read a byte */ rc = sample_buffer.push_back(scaled_sample); } while (rc == -1); } /** * Timer0 CCR0 overflow handler * * This method is called each time the CCR0 value counts up to 1023. * We grab the next sample from the circular buffer and scale it * up from the 8 bit unsigned value read from the disk to match * the CCR0 scale. */ #pragma vector = TIMER0_A0_VECTOR void __interrupt TIMER0_OVERFLOW_VECTOR_ISR(void) { // P1OUT ^= BIT0; TACCR1 = sample_buffer.pop_front(); // P1OUT ^= BIT0; } int main(void) { FRESULT res; // PetitFS variables DRESULT dres; FATFS fs; WDTCTL = WDTPW + WDTHOLD; // Stop WDT DCOCTL = 0; // Run at 16 MHz BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; //DCOCTL += 3; // fine tune 15.9MHz to 16.0MHz on my chip __delay_cycles(0xffff); // delay for power up and stabilization spi_initialize(); // configure SPI for Petit FatFs 8MHz // P1OUT &= ~BIT0; P1DIR |= BIT2 /*| BIT0*/; // P1.2 output P1SEL |= BIT2; // P1.2 use TA0.1 //P1DIR |= BIT4; P1SEL |= BIT4; // output SMCLK, useful for measuring /** * configure TimerA0 with a 15.625k frequency, * setup TA0.1 (P1.2) for the PWM output. */ TACCR0 = (TIMERA_CLK/SAMPLE_RATE)-1; // PWM Period 15.625k (64 us) TACCR1 = TACCR0/2; // Set initial PWM duty cycle to 50% TACCTL0 = CCIE; // Enable CCRO CCIFG interrupt. The TACCR0 CCIFG // interrupt flag is set when the timer counts to // the TACCR0 value. TACCTL1 = OUTMOD_7; // Output is reset (0) when timer counts // to TACCR1, It is set (1) when timer counts // to TACCR0 value TACTL = TASSEL_2 | ID_0 | MC_1; // use SMCLK / 1, in UP MODE to CCR0 // value 1024-1 cycles((16MHz/1)/15.625kHz) __enable_interrupt(); /** * play the same songs in a loop */ while(1) { dres = disk_initialize(); if ( dres == RES_OK ) { res = pf_mount(&fs); if ( res == FR_OK ) { int n; char fileName[] = "0.raw"; for ( n=0; n < 10; n++ ) { fileName[0] = n+'0'; res = pf_open(fileName); if ( res == FR_OK ) { WORD bytes_read; do { res = pf_read(0, 32768, &bytes_read); /* pf_read calls on_streaming_data() for each byte read */ if (res != FR_OK) { break; } } while (bytes_read == 32768); /* read a cluster at a time */ } } } } } return 0; }
  17. Like
    larryfraz got a reaction from bluehash in 'Fauxtrane'   
    No,but here's a link. It's doing the fast line that comes in 30 seconds or so in.--  http://t.co/BkjF98sMcS
    Also here, with other synths. Its driving a Korg Monotron in both. --- https://soundcloud.com/zadok-strawberry/fauxtrane-et-al-1
  18. Like
    larryfraz got a reaction from bluehash in 'Fauxtrane'   
    A very simple, probability table ascending melodic line CV generator
    #include <msp430g2553.h> /* output arpeggio of notes to a randomized beat pattern gate turns off for last 1/4 of duration of note beat is fixed at 120 ToDo: add midi in for clock redo rnd() with seed value& algorithm, not just a table */ #define CLOCKHZ 16000000 #define nNotes 24 #define BUTTON BIT3 #define BPM 120 #define TICKS_PER_BAR 32 #define BEAT_PER_SECOND BPM/60 #define MAX_MIDI_CHANNELS 16 #define MAX_POLYPHONY 8 unsigned char notes[MAX_POLYPHONY] = {0}; unsigned char note_index; static const int period = 128; // period of ccro = period for midi 0-127 const long cycles_per_second = CLOCKHZ/128; const int ticks_per_second = BEAT_PER_SECOND*TICKS_PER_BAR; unsigned char midi_off =0; unsigned char curr_note; static const unsigned int durProb[] = {1,1,3,3,4,4,8,8}; static const unsigned int durTable[] = {32,16,8,6,4,3,2,1}; static const int int_prob[] = {3,1,4,4,4,6,4,6}; static const int intervals[] = {1,2,3,4,5,7,10,12}; unsigned char midi_fifo[32]; unsigned char midi_fifoIn=0; unsigned char midi_fifoOut=0; /* * main.c */ static const unsigned int randVals[32] ={ 0xFF, 0x68, 0xF9, 0xB8, 0x10, 0xA1, 0xB6, 0x65, 0xBF, 0x6E, 0x32, 0x2C, 0x95, 0x09, 0xDC, 0x0D, 0xA7, 0x86, 0x00, 0x93, 0xC7, 0x5F, 0x95, 0xA9, 0x5E, 0xFB, 0xC7, 0x22, 0x09, 0xC1, 0xC7, 0xA9, }; unsigned int rnd(); unsigned int getInterval( ); unsigned int getDuration(); void shiftLeft(unsigned char c); void update_state(); void note_on(unsigned char note); void note_off(unsigned char note); unsigned int X = 1; //const int M = 256; //const int a = 65; //const int c = 27; int ptrRnd = 0; int offVal = 0; const unsigned int num_steps = 32; int index, cycles=0; unsigned int z=1; unsigned int counter; const int tableSize = 8; const unsigned int pattern[16]= {4,2,4, 8,6,1,2,3,2, 1, 4,2, 1,2,6,8}; char patternPtr=0; //unsigned char midi_note_num, midi_done, midi_note_vel, midi_rec_state, midi_note_chan, midi_cc_chan=0; void main(void) { DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; BCSCTL2 |= DIVS_1; // SMCLK = MCLK/2 =8MHZ WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR = BIT7 | BIT6 | BIT5 | BIT4 | BIT2 | BIT0; // Direction P1SEL = BIT6 | BIT4 | BIT1; // Select Timer A output, SMCLK output, UART Rx P1SEL2 |= BIT1; P1REN = BIT2 + BIT5; P1OUT = BIT2;//BIT2 + BIT6; TACCR0 = period; // Setup Timer A for 32768 Hz period TACCR1 = TA0CCR0/2; // Setup Timer A compare to midpoint TACCTL1 = OUTMOD_7; // Setup Timer A reset/set output mode TACTL = TASSEL_2 | MC_1; // Timer A config: SMCLK, count up TACCTL0 |= CCIE; // Enable period interrupt //USCI init UCA0CTL1 |= UCSWRST; // UCB0CTL1 |= UCSWRST; //UCA0CTL0 = UCMODE_3; UCA0CTL1 = UCSSEL_2 + UCSWRST; UCA0BR0 = 8; // DIVIDES SMCLK = 31250 = MIDI SPEC w/UCOS16 oversample UCA0BR1 = 0; // UCA0MCTL |= UCOS16; // 16x oversample IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt _BIS_SR(GIE); // // _enable_interrupts(); // Enable interrupts // #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A0 (void){ int cycles_per_tick = cycles_per_second/ticks_per_second; P1OUT |= BIT5; TA0CCR0 = period; TA0CCR1 = z ; if(counter>0){ counter--; if(counter < offVal) P1OUT &= ~BIT5;// turn off for last quarter of duration } else { counter=cycles_per_tick*pattern[patternPtr++];//cycles_per_tick*getDuration(); if (patternPtr>=16) patternPtr = 0; if(rnd()<32) offVal = counter; else offVal = counter>>2; z=z + getInterval(); if(z>= period) z-=period; } } unsigned int rnd(){ if(ptrRnd>=32) ptrRnd = 0; X = randVals[ptrRnd++];// X=(a * X + c) % M ;// 0 to 255 return X; } unsigned int getInterval( ){ unsigned int random = 0; unsigned int counter = 0;//lastIndex; unsigned int sum = 0; //tally of probabilty vals random = rnd(); while(sum<=random){ sum += int_prob[counter++ ]; if (counter>= tableSize) counter = 0; } return intervals[counter]; } unsigned int getDuration() { unsigned int random =0; unsigned int counter = 0; unsigned int sum = 0; random = rnd() ; while ( sum < random){ sum = sum+ durProb[counter++]; if (counter>= 8) counter = 0; P1OUT ^= BIT0; } //add up to random probability, then get the actual duration return durTable[counter];//it wont execute this command!?! }  
  19. Like
    larryfraz reacted to cde in i2c Explorer   
    NOTE: This was built using IAR, for an msp430 with the USI peripheral. It will need editing to work on USCI peripherals or if compiled in CCS or GCC.
    Updated 12/12/12: http://forum.43oh.com/topic/126-i2c-explorer/?p=25918
     

    I like i2c, and have one main project I want to create based on turning a scrolling led display into a computer/net/micro controller accessible one (it has an i2c eeprom, and its original mc is still in use).

    Having gotten the launchpad, it was one step closer to completion. The next step was getting i2c protocol working and such. With the builtin USI of the launchpad, and Joby's SPI explorer (which uses NJ's uart to boot), I was able to make an i2c Explorer.

    It uses the UART code without modification (except that I am using IAR instead of mspgcc or CCS) and modified Joby's command processing, with the i2c USI built from scratch.

    There are a handful of commands.
    [- i2c START
    bx or 0bx- Transmit Binary number
    hx or 0x- Transmit Hex number
    x- Transmit Decimal number
    r read with Acknowledge (Ack)
    n read with No-Acknowledge (Nack)
    s Search for i2c Slaves
    ]- i2c STOP

    Nearly the same commands as the buspirate/busninja/spi-explorer. I broke out the nack read because it was easier, allows more control, and not all i2c slaves want/expect a nack on the last read.

    It is not completely refined. Still some stuff that needs to be removed/polished (Slave search should only output on responded addresses, instead of needing someone to search through all 255 address tests responses.)

    Bus speed is non-standard as far as I can see (USI Clock is SMCLK at 1mhz, divided at 128 as per TI's USI application note. 1mhz/128 = 7812hz = ~8khz???) This needs to be fixed, and a TI introduction to USI/USCI powerpoint shows that the bus can be driven at 500khz at 1mhz clock. Probably just needs the correct divider selection (Divide clock by 2 for 500k (400k i2c speed) or by 8 for 125k (100k i2c speed).

    This is beta/preliminary release. Only been tested with a PCF8574. Code clocks in at 1920 bytes, with no optimization (Standard IAR project with no defaults changed). UART at 9600 like normal, pin 1.7 is sda, pin 1.6 is scl (can't be changed due to USI so remove the p1.6 led jumper) and p1.0 is a status light.

    Will be testing with faster speed and more i2c devices soon.
    i2c.zip
  20. Like
    larryfraz reacted to SirPatrick in DIY MSP430 wifi connectivity with retail router   
    I have been working on a few different projects that could be described as wireless sensor nodes. Just to get something working I decided to hack a retail router to give my MSP430 wireless capabilities. The first step was to install OpenWRT Linux onto the router to make it configurable. After that I mounted the file system onto a flash drive that was using the built in USB port on the router. From there I broke out the convenient 3.3v  serial connection and hooked it up to my MSP430. Currently I am working on a full write up that will include compiling OpenWRT from source and detailed step by step instructions to install all the needed packages. I am also finishing up some scripts that should automate the hard stuff and give your launchpad a wireless connection in no time.
     
     
    Decided I would add some some pictures and examples for everyone to look at while I finish the write up / automation scripts. This is by no means a finished or polished project. 
     
    Here is a link to the Imgur album with short descriptions.
    http://imgur.com/a/xzga5
     
     
     
     
    And here is a video of me using the wireless capabilities to trigger a relay. I will update this post when I finish everything else. 
    http://www.youtube.com/watch?v=aU0LfrJBSKE
     
     
     
     
  21. Like
    larryfraz reacted to nemui-kuma in 16 voice wavetable synth/sampler with MSP430G2553   
    Hey forum!
    I always wanted to make a synthesizer , so i chose the msp430 launchpad, because it's one of the most inappropriate chip i can use for it  :grin:
    When i started to make it i didn't have real goal, i just wanted to make a sound, so this project is kind if all over the place but i have learned a lot doing it so it was totally worth it.
     
     
    The DAC used is a  TI TLC5615, it's not the best choice, but i only had this in my parts bin.
    Probably any other SPI DAC could be used with minimal modification, or even PWM.
    (I don't sound good with PWM IMO.)
    The TLC5615 needs 5 volts, but it seem to run good with 3.6 volt from the launchpad,or you could use TP3 (the USB 5V) but that can be noisy, I used a separate 5V supply.
     
    The crystal is required, because it tunes the DCO on every start up to a pre-defined value
    ( i ran it at 19Mhz without any problems)
    If you change the frequency , you only need to change the bit rate divider for the USCI UART.
     
     
    There are a lot to optimize/rewrite but i kind of grew tired of playing with variables to get a few more bytes of free ram.
    Maybe i'll rewrite it on an F5510 as it would be a much better choice because it has 8 x Ram as much ram and a hardware multiplier.
     
     
     
    This is a synth with 16 voice of polyphony. It accepts midi massages from 1-8 and 10 (for the drum sounds). Each midi channel has it's own different settings for: -MIDI program  -LFO width and speed  (CC01 for combined mod wheel control, CC02 for width,CC03 for speed -Oscillator type (simple with any waveform or with ADSR square or sine wave) -Pitch bend -Portamento on/of (CC65) -Portamento speed (CC05) -Channel volume (CC07)  It plays 8 sine/square with ADSR, 4 with any waveform (now only Saw and triangle), and 4 drum sounds simultaneously.   Here are two songs i recorded with it: Soundcloud.   I have attached the CCS Project with the source codes in a ZIP, the schematics, and a picture of how it look on my breadboard.  
     


    mSpYNTH.zip
    mysy
  22. Like
    larryfraz reacted to NatureTM in Music with only a speaker, a LP, and 30 lines of code   
    Hi everyone, it's been awhile.
     
    I just wanted to share something interesting lasershark mentioned on my blog awhile ago.  It's basically a way to make music with one line of code.  It took about 15 minutes to implement on a g2553 and only requires a launchpad and a speaker.  I found it pretty entertaining.  Just connect one terminal of the speaker to Port 1.2 and the other to ground, or drive it with a transistor.
     
    Original project @ http://canonical.org/~kragen/bytebeat/
     
    #include "msp430g2553.h" #define MCLK 8000000 #define OUTPUT_SAMPLES_PER_SECOND 8000 #define PIN_SPEAKER BIT2 unsigned long t = 0; unsigned char sample; void main(void) { WDTCTL = WDTPW + WDTHOLD; DCOCTL = CALDCO_8MHZ; BCSCTL1 = CALBC1_8MHZ; P1SEL |= PIN_SPEAKER; P1DIR |= PIN_SPEAKER; TA0CTL = TASSEL_2 | MC_1; TA0CCR0 = (0x0001 << 8) - 1; TA0CCTL1 |= OUTMOD_7; TA1CTL = TASSEL_2 | MC_1; TA1CCR0 = MCLK / OUTPUT_SAMPLES_PER_SECOND - 1; TA1CCTL0 |= CCIE; _enable_interrupts(); while(1){ sample = ((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7; // sample = t*(((t>>12)|(t>>8))&(63&(t>>4))); // sample = (t*(t>>5|t>>8))>>(t>>16); // sample = t*(((t>>9)|(t>>13))&(25&(t>>6))); // sample = t*(((t>>11)&(t>>8))&(123&(t>>3))); // sample = (t*5&t>>7)|(t*3&t>>10); // sample = (t&t%255)-(t*3&t>>13&t>>6); // sample = t>>4|t&((t>>5)/(t>>7-(t>>15)&-t>>7-(t>>15))); // sample = (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1; // sample = ((t*(t>>12)&(201*t/100)&(199*t/100))&(t*(t>>14)&(t*301/100)&(t*399/100)))+((t*(t>>16)&(t*202/100)&(t*198/100))-(t*(t>>17)&(t*302/100)&(t*298/100))); // sample = t*(t^t+(t>>15|1)^(t-1280^t)>>10); // sample = t&t>>8; //44 khz // sample = ((t/2*(15&(0x234568a0>>(t>>8&28))))|t/2>>(t>>11)^t>>12)+(t/16&t&24); // sample = ((t*("36364689"[t>>13&7]&15))/12&128)+(((((t>>12)^(t>>12)-2)%11*t)/4|t>>13)&127); t++; LPM0; } } #pragma vector = TIMER1_A0_VECTOR __interrupt void T1A0_ISR(void) { TA0CCR1 = sample; LPM0_EXIT; }  
    Switch which "sample =" line is uncommented to change the "song."  The songs are from http://pelulamu.net/countercomplex/music_formula_collection.txt and there are more in that file.
     
     
  23. Like
    larryfraz got a reaction from abecedarian in 2-osc PWM Midi Synth   
    I put together a 2 oscillator PWM MIDI synthesizer based on NatureTM's (thanks!) 'simple synth'. No DAC is needed. The second oscillator can be detuned and has a blend control, both accessed via midi cc's. A clip of it, and the code, are on my site at the perspectivesound blog. I haven't added adsr, I may add some more features soon.
  24. Like
    larryfraz reacted to RobG in MIDI Arpeggiator   
    This is one of the things you can do with my MIDI Booster Pack, create a simple MIDI Arpeggiator.
     
    There are eight preset patterns, functionality to record custom ones will be added at a later time.
    Program Change changes the pattern.
    MIDI Stop and MIDI Start are implemented to stop and start the sequence.
    Speed can be adjusted using a controller.
    Note's velocity is used for the whole pattern, making patterns more dynamic.
     


  25. Like
    larryfraz reacted to RobG in 2-osc PWM Midi Synth   
    Try this:
     

    P1SEL = RXD; P1SEL2 = RXD; UCA0CTL1 |= UCSSEL_2; UCA0BR0 = 0x80; 31.25k @ 4MHz UCA0BR1 = 0x00; UCA0CTL1 &= ~UCSWRST; IE2 |= UCA0RXIE;
×
×
  • Create New...