Jump to content
43oh

oPossum

Members
  • Content Count

    925
  • Joined

  • Last visited

  • Days Won

    103

Posts posted by oPossum

  1. 
    

    #pragma vector = TIMER0_A0_VECTOR

    __interrupt void Timer0_A0 (void)              // Timer0 A0 interrupt service routine

    {

        static const uint8_t steps[8] = {

    #if 0   // Full step

            BIT0 | BIT1,

            BIT0 | BIT1,

                   BIT1 | BIT2,

                   BIT1 | BIT2,

                          BIT2 | BIT4,

                          BIT2 | BIT4                               

            BIT0 |               BIT4,

            BIT0 |               BIT4

    #else   // Half step

            BIT0 | BIT1,

                   BIT1,

                   BIT1 | BIT2,

                          BIT2,

                          BIT2 | BIT4,

                                 BIT4,

            BIT0 |               BIT4,

            BIT0

    #endif

        };

        static unsigned step = 0;

        

        P1OUT = (P1OUT & ~(BIT0 | BIT1 | BIT2 | BIT4)) | steps[7 & step++];

    }

     

  2. There are 3k3 pullup resistor to 5V. So there will be about 300 microamps current flow thru each of two of the ESD protection diodes in the MSP430. This will usually not cause problems as long as there is something on the MCU's supply rail to sink this current. If the MSP430 is running at 1MHz or more and not sleeping, then it will use that current. Adding 6k8 pulldown resistors to SDA and SCL would reduce the voltage to about 3.3V and prevent current flow thru the ESD diodes.

  3. If you have a module like this...

     

    post-229-0-31145800-1374044583_thumb.jpg

     

    and it is unreliable or not working at all, here is a possible fix.

     

    - Remove battery

    - Remove D1, R6 and R4

    - Solder jumper wire in place of R6

    - Inspect crystal soldering - fix if necessary

    - Replace battery

     

    The module should now work properly. It requires 5V power, but will work with 3.3V logic.

     

    The DS1307 can be replaced with the newer pin compatible DS1338 for operation from 1.8V to 5V, or the TI BQ32000 for 3.3V (only) operation.

     

    ---

     

    The battery backup circuit on these modules is of poor design. D1 and R5 provide a charging current to the CR2032 coin cell. Lithium primary cells such as the CRxxxx series should not be (re)charged. Removing D1 fixes this.

     

    R4 & R6 create a voltage divider between the battery and the DS1307. This raises the source impedance (spec sheet warns against this) and increases the current draw from the battery. The voltage divider was necessary because the battery voltage would float at about 4.2V volts due to the D1/R5 circuit! That would keep the DS1307 disabled if present on the Vbat pin. Replacing R6 with a jumper allows the full battery voltage to Vbat.

  4. Using timer overflow interrupt instead of timer CCR0 interrupt

    #include <msp430.h>
     
    #pragma vector = TIMER0_A1_VECTOR                   // Timer A overflow (TAIFG) interrupt
    __interrupt void timer0_a1_isr(void)                //
    {
        switch(TA0IV) {                                 // TA0IV must be read to reset interrupt
            case 0x0A:                                  // 0x0A == TAIFG (see SLAU144 12.3.5)
                P1OUT ^= BIT5;
                break;
        }
    }
     
    void main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;                       // Disable watchdog reset
        DCOCTL = 0;                                     // Run at 8 MHz
        BCSCTL1 = CALBC1_8MHZ;                          //
        DCOCTL = CALDCO_8MHZ;                           //
        
        P1OUT = 0;                                      // Setup GPIO
        P1DIR = BIT5;                                   //
        
        TA0CCR0 = (8000000UL / 8 / 100) - 1;            // 100 Hz (10 ms)
        TA0CTL = TASSEL_2 | ID_3 | MC_1 | TAIE;         // Timer A config: SMCLK, /8, count up, overflow interrupt enabled
        
        _enable_interrupts();                           // Enable interrupts
        
        for(;;                                        // For-ever
    }
    
  5. 
    

     

    #include <msp430.h>

     

    #pragma vector = TIMER0_A0_VECTOR                   // Timer A CCR0 interrupt

    __interrupt void timer0_a0_isr(void)                //

    {

        P1OUT ^= BIT5;

    }

     

    void main(void)

    {

        WDTCTL = WDTPW | WDTHOLD;                       // Disable watchdog reset

        DCOCTL = 0;                                     // Run at 8 MHz

        BCSCTL1 = CALBC1_8MHZ;                          //

        DCOCTL = CALDCO_8MHZ;                           //

        

        P1OUT = 0;                                      // Setup GPIO

        P1DIR = BIT5;                                   //

        

        TA0CCR0 = (8000000UL / 8 / 100) - 1;            // 100 Hz (10 ms)

        TA0CCTL0 = CCIE;                               // Enable CCR0 interrupt

        TA0CTL = TASSEL_2 | ID_3 | MC_1;                // Timer A config: SMCLK, /8, count up

        

        _enable_interrupts();                           // Enable interrupts

        

        for(;;);                                        // For-ever

    }

     

  6. It is a very reasonable design. Be aware the that voltage being switched must be about one volt higher than the microcontrollers's supply voltage. So if you are running a MSP430 at 3.3V, you could switch a 5V or higher rail, but not the 3.3V. Also be aware that if the higher voltage supply is absent then the microcontoller's output may be overloaded.

     

    R1 can be calculated with this formula:  R1 = (Vcc - 0.7) * 10 /  I

     

    So for a microcontroller running at 3.6V and a 100 mA load...

    R1 = (3.6V - 0.7) * 10 /  0.1 = 290 ohms (use 270 or 330)

     

    There will be some small leakage current thru Q2 when it is off. This can be reduced will a resistor between the base and emitter. Using the same value as R1 is fine.

     

     

    The circuit as show with D1 is potentially unstable. There is a high gain uncompensated feedback loop that could become unstable with a reactive (capacitive and/or inductive) load.

  7.  

    Code drawback:

    -Apparently the MPS430G2553 GPIO falling edge interrupts can't detect short pulses

     

    It can detect pulses a few 10s of nanoseconds wide. Ultrasonic modules will typically disable the received pulse detection while transmitting and for a short time after. This prevents false triggering from the outbound chirp. So the close range limitation is probably due to an intentional feature of the ultrasonic module. Easy to check with a dual channel DSO.

  8. Running at a higher clock will allow you to spend less time in active mode which is what gives you the lowest power consumption.

     

    That is usually not true due to I2R losses in the power source. Running at the lowest practical clock gives the highest capacity utilization and thus the longest battery life.

  9. 
    

    in main() remove this line: IE2 |= (UCA0RXIE | UCA0TXIE);  // Enable RX and TX interrupts

     

     

    #pragma vector=USCIAB0TX_VECTOR

    __interrupt void usciab0tx_isr (void)

    {

        if(serial_bp && *serial_bp) {

            UCA0TXBUF = *serial_bp++;

        } else {

            IE2 &= ~UCA0TXIE;

        }

    }

     

    void serial_out (char *p)

    {

    while(IE2 & UCA0TXIE);

        serial_bp = p;              // set global pointer

        IE2 |= UCA0TXIE;            // start things going!

    }

     

×
×
  • Create New...