Hello!
I need to output IO signal or PWM immediately when the input IO signal changes. However, it is found that the response delay is severe, about 1.4-6ms。
simple.The code is as follows:
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P2DIR|=BIT5; // P2REN&=~BIT5; P2IES&=~BIT5; P2OUT&=~BIT5; P2IFG&=~BIT5; P2DIR&=~BIT5; //P2IE|=BIT5; //p3.0 trigger out P3DIR |= BIT0; //P3REN|=BIT0; while(1){ if(P2IN&BIT5) //p2.5: mcu-triggerIn { P3OUT|=BIT0; }else{ P3OUT&=~BIT0; } } }
or
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT //P2.5 interrupt P2DIR|=BIT5; // P2REN&=~BIT5; P2IES&=~BIT5; P2OUT&=~BIT5; P2IFG&=~BIT5; P2DIR&=~BIT5; //P2IE|=BIT5; //p3.0 trigger out P3DIR |= BIT0; //P3REN|=BIT0; _EINT(); __low_power_mode_1(); } //mcu-triggerin #pragma vector=PORT2_VECTOR __interrupt void Port_2(void) { P2IFG&=~(BIT5 | BIT4); if(P2IN&BIT5) //p2.5: mcu-triggerIn { P3OUT|=BIT0; P2IES|=BIT5; }else{ P3OUT&=~BIT0; P2IES&=~BIT5; } }
The logic levels of input and output ports are monitored externally, and the delay is found, and the delay time is related to the duty cycle of input level and long waiting time.
I think the possible reasons are:
1) The external input level changes and it is slow to update the internal pin register
2) The change from output IO to drive IO level is slow