This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello ,
I'm using MSP430F5131 micro-controller .
I'm using an external oscillator of 12.8MHz which connected to pins PJ.4 and PJ.5 and defined P2.4 ( with timer : TD0.0) as my 1 pulse per second output.
I would like to generate a 1 pulse per second using this external oscillator through P2.4 . In addition to this 1 PPS i got a toggle switch that toggles between a "normal" 1 pulse per second and a "bad" pulse of 0.5 second.
First of all i would like to know how to write a proper code of 1PPS and then i would like to implement both of the pulses ("normal" and "bad") into the code.
I have written a code of a 1PPS , i'm not sure if i have written it correctly :
TD0CCR0=49999; // setting TAR count up value -1
TD0CCTL0=CCIE; //enabling interuption
TD0CTL0 =MC_1|ID_3|IDEX_3|TDSSEL_0|TDCLR; //defining timer d TD0.0 (P2.4)
__enable _interrupt ();
for(;;){
if ((P1IN & BIT2)==0) { //ACTIVE LOW
#pragma vector = TIMERD0_VECTOR //GENERATES 1PPS EVERY 1s
__interrupt void TD0_ISR (void){
P2OUT ^=BIT4;//TOGGLE THE 1PPS PULSE ('1' - '0' )
}
}
}
Thanks in advance.
seems like an easier way to poll an IFG instead of those interupts , i have encountered this code :
#include <io430x11x1.h> // Specific device // Pins for LEDs #define LED1 BIT3 #define LED2 BIT4 void main (void) { WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer P2OUT = ˜LED1; // Preload LED1 on , LED2 off P2DIR = LED1|LED2; // Set pins for LED1 ,2 to output TACTL = MC_2|ID_3|TASSEL_2|TACLR; // Set up and start Timer A // Continuous up mode , divide clock by 8, clock from SMCLK , clear timer for (;;) { // Loop forever while (TACTL_bit.TAIFG == 0) { // Wait for overflow } // doing nothing TACTL_bit.TAIFG = 0; // Clear overflow flag P2OUT ˆ= LED1|LED2; // Toggle LEDs } // Back around infinite loop }
seems like this code is similar to what i need (without using a ISR), although im not familiar to this function :
TACTL_bit.TAIFG
and how could i generate a pulse of 1us within a period of 1 second (Tperiod = 1 second)? How could i use that IFG flag exactly at that time without using the ISR function?
thanks
**Attention** This is a public forum