0

I'm new to this field of microcontroller and i need you quick help with a new project of mine.

I'm using MSP430F5131. I will explain a little about the project : My main goal is to generate a 1 pulse per second using a 12.8MHz external oscillator. I already have a printed PCB for that project which means i got to understand what the previous designer had done and implement it into my CCS program in order to program my micro controller. i am still new to this whole microcontroller world and im eager to know more , although im short in time.

I have attached an electrical wiring of the PCB to help you understand a little bit more about the project.

A little explanation of the electrical wiring: An external toggle switch (from connector J6 "Internal/External Selection") switch between an external 1pps (From an external GPS) or internal 1pps (by the msp430). if we choose an internal mode then (input P2.2) a '1' (or '0' if its an active low mode which is an active low mode) sends from PJ.3 (ouput) to U4 and a 1 pulse per second gets out of P2.4 output to connectors J8 and J9 (same pulse different connectors).

I can Switch signals to ON/BAD/OFF by using an external toggle switch(pins 1,2 of J3 connector) or a descrete (pin 3 of J3 connector). if i toggle the switch to on mode it sends '1'(or '0' if its an active low mode which is an active low mode) through P1.6 to U5 ( And Gate) and enables the pulse it also sends '1' through PJ.0 to U6 and converts the pulse from TTL to RS422 (differetial). The descrete switching option switches the pulse (ON/OFF) the same as the external toggle switch. This is refers to PULSE 1 , i need to implement the same thing for PULSE 2.

although im still not sure what RST/NMI/SBWTDIO and TEST/SBWTCK are wired for , are these for downloading the program into the msp? im also not sure about the PJ.2 pin (FUNCTIONALITY DISABLE).

I know its a lot to read but im really short in time about this project and i dont have much time to study everything. so i would be very glad if you could read the code and help me implement the functions into the code.

here's the code i would like to know if i have done this:

#include <msp430.h>
#include <intrinsics.h>




volatile unsigned int timerCount = 0; //defines the millisecond counter
volatile unsigned int normalPulse1=0; //defines another flag to indicates when 1 second has passed for normal pulse1
volatile unsigned int badPulse1=0;//defines another flag to indicates when 1 second has passed for bad pulse1
volatile unsigned int normalPulse2=0; //defines another flag to indicates when 1 second has passed for normal pulse2
volatile unsigned int badPulse2=0;//defines another flag to indicates when 1 second has passed for bad pulse2

int main(void) {


    WDTCTL = WDTPW | WDTHOLD;                   // Stop watchdog timer
    P2OUT &= ~(BIT4);                           //preload 1pps to '0'


    // set I/O pins directions
    P1DIR |=BIT6+BIT7;                      //set p1.x to 11000000
    P2DIR |=BIT4;                          // Set P2.4 to output direction
    PJDIR |=BIT0+BIT1+BIT3;                // set pj.x output 0000 1011
    P2SEL |= BIT4;                         //select the option of using TD0.0 in pin 2.4
    P2IES |= BIT4;                         // high -> low is selected with IES.x = 1.
    P2IFG &= ~(BIT4);                      // To prevent an immediate interrupt, clear the flag for
                                          // P1.3 before enabling the interrupt.
    P2IE |= BIT4;                          // Enable interrupts for P2.4

    // Configure XT1 (external oscillator)
    PJSEL |= BIT4+BIT5;                     // port select for xt1
    UCSCTL6 &= ~(XT1OFF);                   //xt1 is on
    UCSCTL3 = 0;                            // FLL REFERENCE CLOCK REFERENCE = XT1

    // configure TD0.0 to output of 1 pulse per second
    TD0CTL0 |=MC_1+ID_3+TDSSEL_0+TDIE+CNTL_0+TDCLR;                //defining timer d TD0.0 (P2.4)
    TD0CCR0=1600-1;                          // setting TAR count up value 1600 (12.8MHz / 8 = 1.6MHz , 1.6MHz / 1600 = 1000 Hz) when 1000 is passed means 1 second has passed as well
    TD0CCTL0 |= CCIE;                        //ENABLES CCIFG INTERUPT ON CCR0


    __enable_interrupt();


    for(;;){                      // main loop (looping forever)



        //   EXTERNAL / INTERNAL SELECTION BY SW4

        if ((P2IN & BIT2)==0){         //  INTERNAL MODE
            PJOUT |=BIT3;              // sends '1' from pj.3 output to the multiplexer U4 (uses the internal 1pps)

            //PULSE 1 : DESCRETE ON/OFF AND SWITCH ON/BAD/OFF

                     if ((P2IN & BIT0)==0 || (P1IN & BIT0)==0) {        //NORMAL SIGNAL OF 1PPS checks if descrete source is on or 1pps sw pulse 1 is on
                         P1OUT |= BIT6;                                     //ENABLES PULSE BY THE 'AND' GATE
                         PJOUT |= BIT0;                                 //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
                          if(normalPulse1==1){                       //checks if normalPulse1 is on from the ISR
                            normalPulse1 =0;                           // sets normalPulse1 to 0 again so the ISR will generate the pulse 
                            P2OUT ^=BIT4;                            //generates 1pps out of p2.4
                         }

                     }

                     else {
                         P1OUT |= ~(BIT6);                              //DISABLES PULSE BY SENDING A '0' TO THE AND GATE
                     }

                     if ((P1IN & BIT2)==0)  {                           //PULSE 1 BAD SIGNAL checks if the 1pps sw bad pulse is on
                          P1OUT |= BIT6;                                    //ENABLES PULSE BY THE 'AND' GATE
                          PJOUT |= BIT0;                                    //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
                            if(badPulse1==1){                             //checks if badPulse1 is on from the ISR
                              badPulse1=0;                                // sets badPulse1 to 0 again so the ISR will generate the pulse
                              P2OUT ^=BIT4;                            //generates 1pps out of p2.4

                            }
                     }

                     //PULSE 2 : DESCRETE ON/OFF AND SWITCH ON/BAD/OFF


                     if ((P2IN & BIT1)==0 || (P1IN & BIT0)==0){         //NORMAL SIGNAL OF 1PPS checks if descrete source is on or 1pps sw pulse 2 is on
                         P1OUT |= BIT7;                                     //ENABLES PULSE BY THE 'AND' GATE
                         PJOUT |= BIT1;                                 //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
                            if(normalPulse2==1){
                                normalPulse2=0;                             // sets normalPulse2 to 0 again so the ISR will generate the pulse
                                P2OUT ^=BIT4;                            //generates 1pps out of p2.4

                            }


                     }



                     else {
                         P1OUT |= ~(BIT7);                                  //DISABLES PULSE BY SENDING A '0' TO THE AND GATE
                     }

                     if ((P1IN & BIT3)==0){                             //PULSE 2 BAD SIGNAL 
                          P1OUT |= BIT6;                                    //ENABLES PULSE BY THE 'AND' GATE
                          PJOUT |= BIT0;                                    //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
                            if(badPulse2==1){
                                badPulse2=0;                                // sets badPulse2 to 0 again so the ISR will generate the pulse
                                P2OUT ^=BIT4;                            //generates 1pps out of p2.4
                            }
                     }


                     }

        else {                                                              //EXTERNAL MODE
            PJOUT |= ~(BIT3);            //sends '0' from pj.3 output to the multimplexer U4 (uses the external 1pps)
            P1OUT |= BIT6;                  // ENABLES PULSE 1
            P1OUT |= BIT7;              //ENABLES PULSE 2
            PJOUT |= BIT0;              //ENABLES RS422 DIFF OUTPUT FOR PULSE 1
            PJOUT |= BIT1;              // ENABLES RS422 DIFF OUTPUT FOR PULSE 2
                }
        }
}

    return 0;

                    //ISR FOR TIMERD0.0 - NORMAL PULSE 1 AND 2

                    #pragma vector = TIMER0_D0_VECTOR               //GENERATES 1PPS EVERY 1s for normal pulse
                   __interrupt void TIMER0_D0 (void){
                       if (++timerCount > 500) {                        // checks if the incrementation of timerCount reaches 500 (means 1 second has passed)
                                           timerCount = 0;             // resets the millisecond counter to 0
                                           normalPulse1 = 1;             //once it reaches 1000 (1 second) normalPulse1 will be 1 
                                           normalPulse2=1;              //once it reaches 1000 (1 second) normalPulse2 will be 1 
                                           }
                                           P2IFG &= ~(BIT4);           // clears the flAG
                     }


                    //ISR FOR TIMERD0.0 - BAD PULSE 1 AND 2

                    #pragma vector = TIMER0_D0_VECTOR               //GENERATES 1pulse EVERY 2s (0.5Hz) for bad pulse
                   __interrupt void TIMER0_D0 (void){
                       if (++timerCount > 1000) {                           // checks if the incrementation of timerCount reaches 1000 (means 2 second has passed)
                                            timerCount = 0;             // resets the millisecond counter to 0
                                            badPulse1=1;                    // once it reaches 2000( 2 seconds) the badPulse1 will be 1.
                                            badPulse2=1;                    // once it reaches 2000( 2 seconds) the badPulse2 will be 1.
                                           }
                                           P2IFG &= ~(BIT4);           // clears the flAG
Weather Vane
  • 33,872
  • 7
  • 36
  • 56
  • 2
    I don't see any wiring. Nor what your actual problem is. – CL. Dec 15 '16 at 14:26
  • not here to debug your code for you. you want one pps from a 12.8Mhz clock assuming it is accurate you need to count to 12.8 million. which is 0xc35000 so you could prescale with a divide by 4096 and count to 0xc35 or divide by 256 and count to 0xc350. Need to remember the minus one in there. If you want a timer to do something every 10 ticks you really count from 0 to 9 then roll over the timer at the end of the 9 count. With a prescaler you have to figure out how to get that right. I would do this without interrupts first, get it working then add the interrupts. – old_timer Dec 17 '16 at 09:38
  • You could have your timer count to 4096 and look for 0xC35 rollovers. Or I see you are doing it thinking in decimal 8000 rollovers of a timer that rolls over every 1600 counts. – old_timer Dec 17 '16 at 09:41
  • I have compiled this code and no errors have found : – Omer Dagan Dec 27 '16 at 14:24

0 Answers0