Jump to content


  • Content Count

  • Joined

  • Last visited

Posts posted by CPP_Technologist

  1. It could be some sort of noise problem, however it certainly didn't exist when I used this circuit with the arduino, (at 5V, so maybe S/N ratio was small enough or the arduino just has more hysteresis).   


    I think the version of Energia code I'm using may have a bug:


    I decided to break the circuit up and have one phototransistor trigger the rising edge interrupt pin and one phototransistor trigger the falling edge interrupt pin.  I've noticed that they both end up triggering their respective interrupts when I remove my finger from their light beam-- it seems that they are both triggering on the falling edge for some reason, even though I specified rising for one of them in the code.  


    I think I read something about rising not working somewhere, I'm going to see if I can find out where I read it.  




    The problem was a bug in the library Energia.h.  It specifies the wrong values for RISING and FALLING.  The solution was already discussed here:  (See post #6)



  2. Sorry this took so long, but my new code using the suggestions above still registers no difference in the time between the rising and falling edges of the pulse.  Even if I generate a very long pulse, like a second or so, the time between the rising and falling edges is shown as zero.  


    Extra Info:

    I am making these pulses by placing my finger between a phototransistor and a light source.  The phototransistor is running in "open collector" mode with a 1K resistor.  When my finger blocks the light source, I should see the phototransistor output go high, (because this is an inverting configuration) and I've verified that this occurs.  Pins 6 and 7 are both connected directly to the phototransistor output, so they should theoretically see a rising edge and then a falling edge, and the edges must necessarily occur at different times, so I can't see any hardware related reason this won't work.


    The only thing I can figure, at this point, is that the rising edge trigger is actually triggering on the falling edge, or vice versa, causing each interrupt to be executed at the same time (if that's even possible).  


     My new code is shown below:



    volatile unsigned long Time;
    volatile unsigned long Time1;
    volatile unsigned long Time2;
    volatile int flag1;
    volatile int flag2;
    void setup(){
      void loop(){
      if (flag1&&flag2){
      Serial.println("Difference is ");
      void CapturePulse1(){
      void CapturePulse2(){


    Any help is GREATLY appreciated.





    Just realized that RISING doesn't work.  Both Interrupts are indeed being triggered on the falling edge.  Anyone know how to fix this?

  3. I am trying to detect the width of a pulse signal (that should be anywhere from 1ms to 20ms wide) using two ISRs on the MSP430G2553.  One ISR is triggered by the rising edge, and the other by the falling edge.  The first ISR reads micros() and stores the value in a variable called Time1.  The second ISR reads micros() and stores the value in a variable called Time2.  The pulse width of the signal is equal to Time2-Time1.  


    The problem is, Time1 and Time2 always end up being equal, even though they are read in two different ISRs on two separate signal edges-- this should be impossible.  Anyone know how this is happening?  Does entering an ISR stop whatever micros() is referencing? 


    I've tried using millis() as well, but the problem persists.  


    I've used a similar code on the Arduino using "CHANGE" as the interrupt trigger and reading micros() for time1 or time2 depending on the status of a pin-- and that works-- so I'm assuming the launchpad must deal with micros() differently?


    Here is some code that demonstrates the problem on the launchpad:



    volatile unsigned long Time;
    volatile unsigned long Time1;
    volatile unsigned long Time2;
    void setup(){
      void loop(){}
      void CapturePulse1(){
      void CapturePulse2(){



  4. Hello All!


    I'm having trouble achieving I2C communication with Sparkfun's MPR121 I2C capacitive touch sensor breakout board.  


    I've used the breakout board (and code) many times before with the Arduino, but for some reason I can't get it to work with the MSP430G2553 and Energia.  


    I'm using an MPR121 library found at http://bildr.org/2011/05/mpr121_arduino/  to help with register configuration.


    My code compiles fine, but I'm trying to print the output from the touch sensor to the serial monitor and nothing is showing up, so I'm assuming the touch sensor isn't working.


    I know the serial monitor works fine; I ran the DigitalReadSerial example and I can see the output on the monitor.  


    I've connected the MPR121's SDA to pin 1.7 and the SCL to pin 1.6, and the IRQ (interrupt request) to pin 2.4.  The SDA and SCL both have 10K pull up resistors on the MPR121's breakout board.


    The MPR121 is connected to Vcc and GND on the launchpad.  


    Here is my code:



    #include <mpr121.h>
    #include <Wire.h>
    boolean touchStates[12]; //to keep track of the previous touch states
    void setup(){
     pinMode(P2_4, INPUT);  //  IRQ pin
     digitalWrite(P2_4, HIGH); //enable pullup resistor
    void loop(){
    void readTouchInputs0(){
      //read the touch state from the MPR121
      byte LSB0 = Wire.read();
      byte MSB0 = Wire.read();
      uint16_t touched = ((MSB0 << 8) | LSB0); //16bits that make up the touch states
      for (int i=0; i < 12; i++){ // Check what electrodes were pressed
       if(touched & (1<<i)){
        if(touchStates == 0){
         //pin i was just touched
         Serial.print("pin ");
         Serial.println(" was just touched");
        }else if(touchStates == 1){
         //pin i is still being touched
        touchStates = 1;   
        if(touchStates == 1){
         Serial.print("pin ");
         Serial.println(" is no longer being touched");
         //pin i is no longer being touched
        touchStates = 0;
    void mpr121_setup(void){
     set_register(0x5A, ELE_CFG, 0x00); 
     // Section A - Controls filtering when data is > baseline.
     set_register(0x5A, MHD_R, 0x01);
     set_register(0x5A, NHD_R, 0x01);
     set_register(0x5A, NCL_R, 0x00);
     set_register(0x5A, FDL_R, 0x00);
     // Section B - Controls filtering when data is < baseline.
     set_register(0x5A, MHD_F, 0x01);
     set_register(0x5A, NHD_F, 0x01);
     set_register(0x5A, NCL_F, 0xFF);
     set_register(0x5A, FDL_F, 0x02);
     // Section C - Sets touch and release thresholds for each electrode
     set_register(0x5A, ELE0_T, TOU_THRESH);
     set_register(0x5A, ELE0_R, REL_THRESH);
     set_register(0x5A, ELE1_T, TOU_THRESH);
     set_register(0x5A, ELE1_R, REL_THRESH);
     set_register(0x5A, ELE2_T, TOU_THRESH);
     set_register(0x5A, ELE2_R, REL_THRESH);
     set_register(0x5A, ELE3_T, TOU_THRESH);
     set_register(0x5A, ELE3_R, REL_THRESH);
     set_register(0x5A, ELE4_T, TOU_THRESH);
     set_register(0x5A, ELE4_R, REL_THRESH);
     set_register(0x5A, ELE5_T, TOU_THRESH);
     set_register(0x5A, ELE5_R, REL_THRESH);
     set_register(0x5A, ELE6_T, TOU_THRESH);
     set_register(0x5A, ELE6_R, REL_THRESH);
     set_register(0x5A, ELE7_T, TOU_THRESH);
     set_register(0x5A, ELE7_R, REL_THRESH);
     set_register(0x5A, ELE8_T, TOU_THRESH);
     set_register(0x5A, ELE8_R, REL_THRESH);
     set_register(0x5A, ELE9_T, TOU_THRESH);
     set_register(0x5A, ELE9_R, REL_THRESH);
     set_register(0x5A, ELE10_T, TOU_THRESH);
     set_register(0x5A, ELE10_R, REL_THRESH);
     set_register(0x5A, ELE11_T, TOU_THRESH);
     set_register(0x5A, ELE11_R, REL_THRESH);
     // Section D
     // Set the Filter Configuration
     // Set ESI2
     set_register(0x5A, FIL_CFG, 0x04);
     // Section E
     // Electrode Configuration
     // Set ELE_CFG to 0x00 to return to standby mode
     set_register(0x5A, ELE_CFG, 0x0C); // Enables all 12 Electrodes
     // Section F
     // Enable Auto Config and auto Reconfig
     /*set_register(0x5A, ATO_CFG0, 0x0B);
     set_register(0x5A, ATO_CFGU, 0xC9); // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V  set_register(0x5A, ATO_CFGL, 0x82); // LSL = 0.65*USL = 0x82 @3.3V
     set_register(0x5A, ATO_CFGT, 0xB5);*/ // Target = 0.9*USL = 0xB5 @3.3V
     set_register(0x5A, ELE_CFG, 0x0C);
    boolean checkInterrupt1(void){
     return digitalRead(P2_4);
    void set_register(int address, unsigned char r, unsigned char v){
  • Create New...