This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

measuring pulse width

how do i measure a pulse width using the pca in high-speed output mode?

not quite sure what registers i need to read when the interrupt is triggered.

i am using a 8051f023 chip.

  • i have that pdf and i understand that i need to capture the rising and falling edge.

    but i dont understand the value of what registers i need to capture.

    i have an example program of a 16-bit pwm going and while debugging, it goes into the isr on the rising and falling edge, but i dont know what register value to capture.

    the configurations code is as follows:

    PCA0MD = 0x02; 	// disable CF interrupt
    					// PCA time base = SYSCLK / 4
    
    	PCA0CPL0 = (0xff & PWM); 		// initialize PCA compare value
    	PCA0CPH0 = (0xff & (PWM >> 8));
    	PCA0CPM0 = 0x4d; 				// CCM0 in High Speed output mode
    	EIE1 |= 0x08; 					// enable PCA interrupt
    	EA = 1; 						// Enable global interrupts
    	PCA0CN = 0x40; 					// enable PCA counter
    

    the isr code is as follows :

    void PCA_ISR (void) interrupt 9
    {
    	if (CCF0) {
    		CCF0 = 0; // clear compare indicator
    		if (PWM_OUT) { // process rising edge
    			PCA0CPL0 = (0xff & PWM); // set next match to PWM
    			PCA0CPH0 = (0xff & (PWM >> 8));
    		} else { // process falling edge
    			PCA0CPL0 = 0; // set next match to zero
    			PCA0CPH0 = 0;
    		}
    	} else if (CCF1) { // handle other PCA interrupt
    		CCF1 = 0; // sources
    	} else if (CCF2) {
    		CCF2 = 0;
    	} else if (CCF3) {
    		CCF3 = 0;
    	} else if (CCF4) {
    		CCF4 = 0;
    	} else if (CF) {
    		CF = 0;
    	}
    }