I am using the Interval Timer to create delay functions (eg, delay_ms(), delay_us()) since e2studio does not appear to provide these for you, but I am running into some strange behavior. Currently I am simply toggling a pin with a specified delay in between. In the file r_cg_timer_user.c - tried to upload but did not see any confirmation of upload - I simply provided different values for TDR00 and then looked at the result on the oscilloscope. Plotting these on Excel, I came up with the equation relating TDR value with period - a linear function as one would expect. ********************************************************************** /NOTE: This will not work below 25us. In place of this one can use NOP() statements. Minumum delay is 4us void Delay_us(unsigned short dly){ unsigned short temp; //In case timer was started R_TAU0_Channel0_Stop(); //Commenting out line below results in different behavior of output, even though result in temp not directly used. temp = (unsigned short)((7.9755 * (float)dly) - 193.18); //derived empirically from plotting points in Excel //Select CKM0 - Frequency is 8MHz for an 8MHz Sysclk (125nsec period) TMR00 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_COMBINATION_SLAVE | _0000_TAU_TRIGGER_SOFTWARE | _0000_TAU_MODE_INTERVAL_TIMER | _0000_TAU_START_INT_UNUSED; //TDR00 = temp; TDR00 = 604; TO0 &= ~_0001_TAU_CH0_OUTPUT_VALUE_1; TOE0 &= ~_0001_TAU_CH0_OUTPUT_ENABLE; //Start Clock and then Wait for INTTM00 to go high R_TAU0_Channel0_Start(); while(!TMIF00); //TMIF00 is interrupt flag corresponding to INTTM00 interrupt vector TMIF00 = 0; //reset flag to zero R_TAU0_Channel0_Stop(); }//end Delay_us() ********************************************************************** Using the constant 604 (ie., TDR00 = 604;) with no equation specified, I get 100us delay on the oscilloscope. Once I introduce the equation: temp = (unsigned short)((7.9755 * (float)dly) - 193.18); //derived empirically from plotting points in Excel (even if I don't set TDR00 equal to it directly or to temp indirectly, but still point to the original 604), I no longer get 100us delay but something in the neighborhood of 350us of delay. The fact that the equation also produces 604 is moot since I am not even equating TDR00 to temp at this time. I used the Code Generator to generate the appropriate clock signals. Seems like a memory corruption issue, though I don't know how to verify this. This program is very minimal. I am using the 100-pin RL78/G14 demo kit (YRDKRL78G14)
↧