2003-07-23 01:56 AM
2003-07-22 02:15 AM
Hi!!
I am using ST72F521R9T3 and I try to test input capture with St7 lib. The program works as follow: I make a Analog to Digital conversion with a potentiometer, the result is displayed on leds on port D. I inject a signal (0-5V with a frequency of 10Hz) on Timer A ICAP1 pin (PF6) so as to see if the input capture is working... When I inject the signal on PF6 the microcontroller crash!! The value displayed on the led doesn't change when I turn the potentiometer. Here is my code. Does someone see a mistake?? void main (void) { PADDR = 0x00; PAOR = 0x0F; PCDDR = 0x00; PCOR = 0x00; PFDDR=0x9F; // Timer A ICAP1 & 2 as input PFOR=0x00; // Floating inputs PDDR = 0x00; PDDDR = 0xFF; PDOR = 0xFF; PDDR=0xFF; PDDR=0x00; TIMERA_Init (TIMER_FCPU_ ; ITC_Init (); EnableInterrupts; /* Clear I bit in CC reg */ TIMERA_IT_Enable(TIMER_ICAP_IT_ENABLE); /* Enable capture interrupt */ TIMERA_ICAP_Mode(TIMER_ICAP_1,TIMER_EDGE_1); /*Detect rising edge at ICAP1 pin*/ ADC_Enable(); ADC_Select_Channel(13); for(; { while(ADC_Test_Conversn_Complete()!=1) ; PDDR=ADC_Conversn_Read(); } } pragma CODE_SEG DEFAULT pragma TRAP_PROC SAVE_REGS void interrupt 8 TIMERA_IT_Routine(void) { unsigned int CAP2_Value; unsigned char i,Temp; int i1=0; int i2=0; if(TACSR & 0x10) /* if(TIMERA_Status_Flag(TIMER_FLAG_ICF1)==TRUE) Call to Check ICF2 */ { Temp = TACSR; /* Clear ICF2 */ Temp = TAIC2LR; /* TIMERA_Clear_Flag(TIMER_FLAG_ICF2); Call to clear ICF2 */ /* call to get capture value and also clear ICF2 */ CAP2_Value = TIMERA_ICAP_Getvalue(TIMER_ICAP_2); for(i1=0;i1<=200;i1++){ PDDR=0x01; for(i2=0;i2 PDDR=PDDR< } } } } Thanks for answering. Best regards. Junior.2003-07-22 04:43 PM
Try to first initilize the input capture registers and then enable all interrupts.
2003-07-23 01:56 AM
Thank for your help, Ranjeet... but the problem persist.
First I thought it was a problem of interrupts management, because the program crashed only when i inject the 0-5V signal... So I've decided to see if the microcontroller is able to detect the signal edge on the pin. So I've decided to disable interrupts, and I just check if the micrcontroller see a falling edge on PF6. I've added a 10k pull-up resistor on PF6 (because PF6 is configured as floating input), and I inject a 0-5V signal on this pin. I've changed my code as follows: void TIMERA (void) ; void main (void) { // Configures port D as output PDDDR = 0xFF; PDOR = 0xFF; PDDR = 0x00; // Configures PF6 as floating input PFDDR = 0xBF; PFOR = 0x00; PFDR = 0x00; TACR1=0x00; //detect a falling edge on PF6=ICAP1 TACR2=0x00; ADC_Select_Channel (13) ; ADC_Enable( ) ; for( ; ; ) { if(TACSR & 0x80==0x80){ TIMERA( ) ; //If the microcontroller detect a falling edge on PF6, then call TIMERA function } // Waits for the end of the conversion while( ADC_Test_Conversn_Complete()== 0 ) ; // Reads the A/D value and writes it on the LEDs PDDR = ADC_Conversn_Read( ) ; } } #pragma CODE_SEG DEFAULT // TIMERA Function void TIMERA (void) { volatile unsigned char Temp; int i2=0; int i1=0; Temp = TACSR; Temp = TAIC1LR; // Display a value on the leds, just to see if the program run to TIMERA function for( i1=0;i1 PDDR=0x01; for(i2=0;i2 PDDR=PDDR< } } } The Program never runs to the TIMERA function, I can't see anything on the leds Can someone help me?