Jump to content

ender

Members
  • Content Count

    8
  • Joined

  • Last visited

  • Days Won

    1
  1. ender

    header files in CCS

    That worked, thanks mate! and thanks Joby! for the project in the first place. For anyone trying to port this project to CCS, here's the full transformed code: #include "msp430G2211.h" #include #include #include /****************************************************/ #define SWITCH_BIT BIT3 // Launchpad switch on P1.3 #define LED_BIT BIT0 // Launchpad LED on P1.0 #define CAP_BIT BIT7 // RC circuit on P1.7 /****************************************************/ // WDT Timer providing a system tick #define TICKS_PER_SEC (1000/32) // Time to sample background noise level #define SAMPLING_PERIOD (TICKS_PER_SEC * 1) /****************************************************/ typedef enum { TRIGGER_RECALIBRATE, // start sampling background noise level TRIGGER_SAMPLING, // sampling background noise TRIGGER_RUNNING // running normally } state_t; static state_t state = TRIGGER_RECALIBRATE; // trigger state static uint32_t min_sample; // low noise value static uint32_t max_sample; // high noise value static uint32_t sampling_timeout; // tick counter for stopping sampling (SAMPLING_PERIOD) /****************************************************/ static volatile uint32_t sys_ticks = 0; // global tick counter static volatile uint32_t rc_discharge_time = 0; // last discharge time static volatile bool measuring = false; // is discharge being measured /****************************************************/ static void cpu_init(void) { // configure watchdog timer as 32ms interval timer IFG1 &=~WDTIFG; IE1 &=~WDTIE; WDTCTL = WDTPW + WDTHOLD; WDTCTL = WDT_MDLY_32; IE1 |= WDTIE; // configure system clock BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz } // Watchdog interval timer #pragma vector = WDT_VECTOR __interrupt void WDT_ISR(void) { sys_ticks++; } // Port1 ISR #pragma vector = PORT1_VECTOR __interrupt void P1_ISR(void) { uint32_t tar = TAR; // store TAR as early as possible if((P1IFG & CAP_BIT) == CAP_BIT) // cap discharged { rc_discharge_time = tar - rc_discharge_time; measuring = false; P1IE &= ~CAP_BIT; // interrupt disable } else if((P1IFG & SWITCH_BIT) == SWITCH_BIT) // switch pressed { state = TRIGGER_RECALIBRATE; } P1IFG = 0x00; // clear interrupt flags } // wait a short time (for cap to charge) void wait(void) { volatile int i; for(i=0;i<32;i++); } // test if an RC discharge time looks like a trigger or not static bool isTrigger(uint32_t sample) { switch(state) { case TRIGGER_RECALIBRATE: // Sample background noise for SAMPLING_PERIOD sampling_timeout = sys_ticks + SAMPLING_PERIOD; min_sample = 0xFFFFFFFF; max_sample = 0x00000000; state = TRIGGER_SAMPLING; // DROP THROUGH case TRIGGER_SAMPLING: if (sample < min_sample) min_sample = sample-1; if (sample > max_sample) max_sample = sample+1; if (sys_ticks >= sampling_timeout) // sampling time over state = TRIGGER_RUNNING; break; case TRIGGER_RUNNING: if (sample < min_sample) state = TRIGGER_RECALIBRATE; // the environment has changed, recalibrate else { if (sample > max_sample) return true; } break; } return false; } // Begin measuring RC discharge time static void start_measuring(void) { measuring = true; // SMCLK continuous TACTL = TASSEL_2 | MC_2; TACCR0 = 0x00; // drive capacitor high, charge it up P1DIR |= CAP_BIT; P1OUT |= CAP_BIT; wait(); // wait for cap to charge // store start count TAR = 0; rc_discharge_time = TAR; // interrupt when capacitor drops below pin's "high" voltage P1IES |= CAP_BIT; // interrupt on hi to lo edge P1IE |= CAP_BIT; // interrupt enable // flip pin to input, capacitor will begin discharging P1DIR &= ~CAP_BIT; // set to input } int main(void) { uint32_t led_timer = 0; // timed latch for LED cpu_init(); // setup LED pins P1DIR |= LED_BIT; // All LED pins as outputs P1OUT &= ~LED_BIT; // Turn off LED // setup switch interrupt P1DIR &= ~SWITCH_BIT; // as input P1IES |= 0x01; // interrupt on falling edge P1IE |= SWITCH_BIT; // interrupt enable // start measuring discharge time start_measuring(); _BIS_SR(GIE); while(1) { if (!measuring) { // test discharge time to see if it looks like a trigger if (isTrigger(rc_discharge_time)) { P1OUT |= LED_BIT; // turn on LED led_timer = sys_ticks; // record current time } start_measuring(); // measure again } // if 0.5s has elapsed since trigger, turn off LED if (led_timer != 0 && sys_ticks > led_timer + (TICKS_PER_SEC/2)) { P1OUT &= ~LED_BIT; // turn off LED led_timer = 0; // clear timer } } }
  2. To me .. These two have provided the best information so far: 1. http://mspsci.blogspot.com/2010/07/tuto ... arted.html 2. http://glitovsky.com/blog/?p=85
  3. ender

    header files in CCS

    Thanks, that resolved that issue...but however, I am still not being to build the project. I have made some trivial changes to the code to make it for CCS friendly: #include "msp430G2211.h" #include #include #include /****************************************************/ #define SWITCH_BIT BIT3 // Launchpad switch on P1.3 #define LED_BIT BIT0 // Launchpad LED on P1.0 #define CAP_BIT BIT7 // RC circuit on P1.7 /****************************************************/ // WDT Timer providing a system tick #define TICKS_PER_SEC (1000/32) // Time to sample background noise level #define SAMPLING_PERIOD (TICKS_PER_SEC * 1) /****************************************************/ typedef enum { TRIGGER_RECALIBRATE, // start sampling background noise level TRIGGER_SAMPLING, // sampling background noise TRIGGER_RUNNING // running normally } state_t; static state_t state = TRIGGER_RECALIBRATE; // trigger state static uint32_t min_sample; // low noise value static uint32_t max_sample; // high noise value static uint32_t sampling_timeout; // tick counter for stopping sampling (SAMPLING_PERIOD) /****************************************************/ static volatile uint32_t sys_ticks = 0; // global tick counter static volatile uint32_t rc_discharge_time = 0; // last discharge time static volatile bool measuring = false; // is discharge being measured /****************************************************/ static void cpu_init(void) { // configure watchdog timer as 32ms interval timer IFG1 &=~WDTIFG; IE1 &=~WDTIE; WDTCTL = WDTPW + WDTHOLD; WDTCTL = WDT_MDLY_32; IE1 |= WDTIE; // configure system clock BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz } // Watchdog interval timer #pragma vector = WDT_VECTOR __interrupt void WDT_ISR(void) { sys_ticks++; } // Port1 ISR #pragma vector = PORT1_VECTOR __interrupt void P1_ISR(void) { uint32_t tar = TAR; // store TAR as early as possible if((P1IFG & CAP_BIT) == CAP_BIT) // cap discharged { rc_discharge_time = tar - rc_discharge_time; measuring = false; P1IE &= ~CAP_BIT; // interrupt disable } else if((P1IFG & SWITCH_BIT) == SWITCH_BIT) // switch pressed { state = TRIGGER_RECALIBRATE; } P1IFG = 0x00; // clear interrupt flags } // wait a short time (for cap to charge) void wait(void) { volatile int i; for(i=0;i<32;i++); } // test if an RC discharge time looks like a trigger or not static bool isTrigger(uint32_t sample) { switch(state) { case TRIGGER_RECALIBRATE: // Sample background noise for SAMPLING_PERIOD sampling_timeout = sys_ticks + SAMPLING_PERIOD; min_sample = 0xFFFFFFFF; max_sample = 0x00000000; state = TRIGGER_SAMPLING; // DROP THROUGH case TRIGGER_SAMPLING: if (sample < min_sample) min_sample = sample-1; if (sample > max_sample) max_sample = sample+1; if (sys_ticks >= sampling_timeout) // sampling time over state = TRIGGER_RUNNING; break; case TRIGGER_RUNNING: if (sample < min_sample) state = TRIGGER_RECALIBRATE; // the environment has changed, recalibrate else { if (sample > max_sample) return true; } break; } return false; } // Begin measuring RC discharge time static void start_measuring(void) { measuring = true; // SMCLK continuous TACTL = TASSEL_2 | MC_2; TACCR0 = 0x00; // drive capacitor high, charge it up P1DIR |= CAP_BIT; P1OUT |= CAP_BIT; wait(); // wait for cap to charge // store start count TAR = 0; rc_discharge_time = TAR; // interrupt when capacitor drops below pin's "high" voltage P1IES |= CAP_BIT; // interrupt on hi to lo edge P1IE |= CAP_BIT; // interrupt enable // flip pin to input, capacitor will begin discharging P1DIR &= ~CAP_BIT; // set to input } int main(void) { uint32_t led_timer = 0; // timed latch for LED cpu_init(); // setup LED pins P1DIR |= LED_BIT; // All LED pins as outputs P1OUT &= ~LED_BIT; // Turn off LED // setup switch interrupt P1DIR &= ~SWITCH_BIT; // as input P1IES |= 0x01; // interrupt on falling edge P1IE |= SWITCH_BIT; // interrupt enable // start measuring discharge time start_measuring(); eint(); while(1) { if (!measuring) { // test discharge time to see if it looks like a trigger if (isTrigger(rc_discharge_time)) { P1OUT |= LED_BIT; // turn on LED led_timer = sys_ticks; // record current time } start_measuring(); // measure again } // if 0.5s has elapsed since trigger, turn off LED if (led_timer != 0 && sys_ticks > led_timer + (TICKS_PER_SEC/2)) { P1OUT &= ~LED_BIT; // turn off LED led_timer = 0; // clear timer } } } However, I still get errors while trying to build it : I get ... **** Build of configuration Default for project capacitive_touch **** C:\Program Files\Texas Instruments\ccsv4\utils\gmake\gmake -k all 'Building target: capacitive_touch.out' 'Invoking: Linker' "C:/Program Files/Texas Instruments/ccsv4/tools/compiler/msp430/bin/cl430" -vmsp -g --define=__MSP430G2211__ --diag_warning=225 --printf_support=minimal -z -m"capacitive_touch.map" --stack_size=50 --heap_size=0 --warn_sections -i"C:/Program Files/Texas Instruments/ccsv4/msp430/include" -i"C:/Program Files/Texas Instruments/ccsv4/tools/compiler/msp430/lib" -i"C:/Program Files/Texas Instruments/ccsv4/tools/compiler/msp430/include" --reread_libs --rom_model -o "capacitive_touch.out" "./touch.obj" -l"libc.a" "../lnk_msp430g2211.cmd" undefined first referenced symbol in file --------- ---------------- eint ./touch.obj error: unresolved symbols remain error: errors encountered during linking; "capacitive_touch.out" not built >> Compilation failure gmake: *** [capacitive_touch.out] Error 1 gmake: Target `all' not remade because of errors. Build complete for project capacitive_touch Anyone has any suggestions?
  4. ender

    header files in CCS

    Hey all, I was trying to compile Joby's capacitive sensing code on CCS: http://blog.hodgepig.org/2010/09/16/launchpad-capacitive-sensing/ It seems like CCS does not support basic header files like io.h, how do I change the code for CCS?
  5. ender

    Hello from Dallas

    Yes, it is Ender Wiggin from Ender's game indeed Thanks guys, I am glad to be here.
  6. ender

    Talking to the Internet

    thanks mate! I need to look at SPI and I2C explorers
  7. ender

    Talking to the Internet

    There has been many projects where people used Arduino to link the internet and the physical world. A few years back, Jamie Matthews made a Gmail notifier, and used the pySerial class to get gmail and arduino talking! Here's the link: http://www.j4mie.org/2008/02/15/how-to-make-a-physical-gmail-notifier/ and more recently, Make Magazine used the Arduino Ethernet shield: http://blog.makezine.com/archive/2010/12/snail_mail_push_alerts.html Is there any Launchpad based or any msp430 based project where the chip was made to talk to a webserver?
  8. ender

    Hello from Dallas

    Hello folks, I have been checking this site for a while now but never registered. The tutorials or the links to them, I have found here have been more helpful than books on MSP430. Good job guys!
×