Freescale 16-bit MCU (Part 9) - ECT module test

Publisher:AmpouleLatest update time:2021-03-22 Source: eefocusKeywords:Freescale Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

        1. ECT module introduction

        The enhanced capture timer module (ECT) of the XEP100 microcontroller is a timer module developed by adding some functions on the basis of the standard timer module (TIM). ECT is particularly suitable for the application of automobile ABS, ESP and other systems. The ECT module includes a 16-bit programmable counter. ECT has multiple functions, the most important of which are: input capture (IC), output comparison (OC), pulse accumulation (PAI) and modulus down counting (MDC). This article mainly studies the most commonly used input capture and output comparison functions. The figure below is the functional block diagram of the ECT module.

       The ECT module has 8 input capture and output compare channels. When a channel is set to input, it has input capture function. The input capture function can measure some characteristics of the input pulse signal. It can measure the period, duty cycle and frequency of the pulse.


        The input capture channel consists of 4 buffered channels IC0~IC3 and 4 unbuffered channels IC4~IC7. The functions of these two parts are to capture the moment when external events occur, but the buffered channel has a holding register TCnH in addition to the IC/OC register TCn. In addition, a delay counter is set at the entrance to improve the anti-interference ability. The unbuffered channel has no holding register and no delay counter.


        The following figure is a block diagram of the input capture function. When the ECT module is enabled, a clock will keep counting. This clock is called TCNT, which is the "16-bit master clock" in the figure. TCNT starts counting from $0000 and increases by 1 for each ECT clock cycle. After adding to $FFFF, TCNT is reset to $0000. The pulse signal is input from the microcontroller pin, and the signal is input to the ECT module after passing through the edge detector and delay counter. When a valid edge (rising edge or falling edge) is detected, the ECT module captures the value of TCNT into the input capture register TCn, and the value of TCNT captured by the previous pulse edge will be saved in TCnH. The programmer can calculate the time interval between the two edges, that is, the pulse period, by reading the values ​​captured by two adjacent edges and calculating the difference between the two values.

        When the channel is set to output, the channel has an output comparison function. The output comparison function is generally used for precise timing and can also be used to generate PWM signals. When used, first write a value to the output comparison register TCn. When the value of TCNT is equal to the value of TCn, an output comparison event can be generated, and the flag bit CnF is set to 1. If the interrupt function is enabled, an interrupt can be triggered. The corresponding program can be executed in the interrupt program.


        2. ECT output comparison test

        The resources in this article include the test code for the output comparison and input capture functions of the ECT module. In this experiment, we will study the output comparison function of ECT. The following code is the initialization of the ECT module.


void initialize_ect(void){

  ECT_TSCR1_TFFCA = 1; // Timer flag clear quickly

  ECT_TSCR1_TEN = 1; // Timer enable bit. 1 = Allow the timer to work normally; 0 = Disable the main timer (including the counter)

  ECT_TIOS = 0xff; //Specify all channels as output comparison mode

  ECT_TCTL1 = 0x00; // The last four channels are set as timers disconnected from the output pins

  ECT_TCTL2 = 0x00; // The first four channels are set as timers disconnected from the output pins

  ECT_DLYCT = 0x00; // Delay control function disabled

  ECT_ICOVW = 0x00; // The corresponding register is allowed to be overwritten; NOVWx = 1, the corresponding register is not allowed to be overwritten

  ECT_ICSYS = 0x00; // Disable IC and PAC holding registers

  ECT_TIE = 0x00; // Disable all channel timing interrupts

  ECT_TSCR2 = 0x07; // Pre-scaling coefficient pr2-pr0: 111,, clock cycle is 4us,

  ECT_TFLG1 = 0xff; // Clear each IC/OC interrupt flag

  ECT_TFLG2 = 0xff; // Clear the free timer interrupt flag

}


        Detailed comments have been added to the code. You can analyze the code based on the comments and chip manual. The main function of this function is to enable the ECT module, set all channels to output comparison function, and disconnect all channels from the IO pins. Set the period of the ECT counter TCNT to 4us. Disable all channel interrupts.


        The main function of the program is shown below.


void main(void) {

  DisableInterrupts;

  INIT_PLL();

  INIT_LED();

  initialize_ect();

  EnableInterrupts;

 

  for(;;) 

  {

    ECT_TFLG1_C0F = 1; // Clear the flag

    ECT_TC0 = ECT_TCNT + 31250; //Set the output comparison time to 0.125s

    while(ECT_TFLG1_C0F == 0); //Wait until an output comparison event occurs

    ECT_TFLG1_C0F = 1; // Clear the flag

    ECT_TC0 = ECT_TCNT + 31250; //Set the output comparison time to 0.125s

    while(ECT_TFLG1_C0F == 0); //Wait until an output comparison event occurs

    ECT_TFLG1_C0F = 1; // Clear the flag

    ECT_TC0 = ECT_TCNT + 31250; //Set the output comparison time to 0.125s

    while(ECT_TFLG1_C0F == 0); //Wait until an output comparison event occurs

    ECT_TFLG1_C0F = 1; // Clear the flag

    ECT_TC0 = ECT_TCNT + 31250; //Set the output comparison time to 0.125s

    while(ECT_TFLG1_C0F == 0); //Wait until an output comparison event occurs

    LEDCPU = ~LEDCPU; //Reverse light status

  } 

}


        In the main loop of the main function, ECT_TC0 = ECT_TCNT + 31250; is used for timing. Since the period of TCNT is 4us, the timing time is 4us*31250=0.125s. When the time is reached, the flag ECT_TFLG1_C0F is set to 1, and then the timing is restarted until the end of 4 cycles, that is, 0.5s is timed, and the LED's on and off state is changed. The final effect is equivalent to the LED flashing at a frequency of 1Hz. Download the program to the microcontroller and run it, and you can see the corresponding phenomenon.


        3. ECT input capture test

       Input capture is used to measure the characteristics of pulse signals. In order to generate a pulse signal, we use the PWM module of the microcontroller to generate a PWM pulse signal. The code is as follows.


void init_pwm(void) 

 {

  PWMCTL_CON01= 1; //Connect channel 0, 1 to 16-bit PWM

  PWMPOL_PPOL1= 1; //The polarity of channel 01 is high level valid

  PWMPRCLK = 0x55; //The division factor of A clock and B clock is 32, and the frequency is 1MHz

  PWMSCLA = 100; //SA clock frequency is 5KHz

  PWMSCLB = 100; //SB clock frequency is 5KHz

  PWMCLK = 0x02; //Channel 01 uses SA clock as the clock source

  PWMCAE = 0x00; //Pulse mode is left-aligned mode

  PWMPER01 = 500; //The period of channel 01 is 10Hz 

  PWMDTY01 = 250; //The duty cycle of channel 01 is 50%  

  PWME_PWME1 = 1; // Enable channel 01

 }


        This code sets the PWM signal to 10Hz and a duty cycle of 50%. For an explanation of this code, please refer to the article "Freescale 16-bit Microcontroller (VIII) - PWM Module Test".


        The next step is to set up the ECT module. The code is as follows


void initialize_ect(void){

  ECT_TSCR1_TFFCA = 1; // Timer flag clear quickly

  ECT_TSCR1_TEN = 1; // Timer enable bit. 1 = Allow the timer to work normally; 0 = Disable the main timer (including the counter)

  ECT_TIOS = 0xfe; //Specify all channels as output comparison mode

  ECT_TCTL4 = 0x01; // Set channel 0 to capture rising edge mode

  ECT_DLYCT = 0x00; // Delay control function disabled

  ECT_ICOVW = 0x00; // The corresponding register is allowed to be overwritten; NOVWx = 1, the corresponding register is not allowed to be overwritten

  ECT_ICSYS = 0x00; // Disable IC and PAC holding registers

  ECT_TIE = 0x01; // Enable channel 0 interrupt

  ECT_TSCR2 = 0x07; // Pre-scaling coefficient pr2-pr0: 111,, clock cycle is 4us,

  ECT_TFLG1 = 0xff; // Clear each IC/OC interrupt flag

  ECT_TFLG2 = 0xff; // Clear the free timer interrupt flag

}


        This setting is quite different from the output comparison. Channel 0 is set as input function, and is set to capture rising edge, and the interrupt function of channel 0 is enabled. Other settings are consistent with the output comparison.


        In this program, the interrupt method is used to process the input capture time, and the interrupt service function is shown below.


interrupt void capture(void) 

{

 if(ECT_TFLG1_C0F == 1)

   ECT_TFLG1_C0F = 1;

 time1 = time2;

 time2 = ECT_TC0;

 delaytime = time2-time1;

 LEDCPU = ~LEDCPU;

}


        When the rising edge of the external input pulse is captured, an interrupt is triggered. In the interrupt, the flag is first cleared, and then the count value captured by TC0 is read. Finally, the time interval between adjacent rising edges is calculated and saved in the delaytime variable.


       Connect the PWM output pin of the microcontroller to the channel 0 pin of the ECT, and download the program to the microcontroller and run it. The value of delaytime can be seen in the debugging interface, as shown below.

        It can be seen that the value of delaytime is 25000, which is the clock number of TCNT. The period of TCNT is 4us, so it can be calculated that the time interval between two rising edges is 4us*25000 = 0.1s, that is, the frequency of the pulse is 10Hz.


Keywords:Freescale Reference address:Freescale 16-bit MCU (Part 9) - ECT module test

Previous article:Freescale 16-bit MCU (10) - PIT module test
Next article:Freescale 16-bit MCU (VIII) - PWM module test

Recommended ReadingLatest update time:2024-11-16 14:36

Freescale intelligent car steering gear and speed measurement control design and implementation
Abstract: The "Freescale" Cup National College Student Smart Car Competition requires the car model to drive "stable", "accurate" and "fast". By optimizing the installation of the servo in the smart car system and using the Hall sensor to control the speed measurement, the car model can adapt to the new track on dif
[Industrial Control]
Freescale intelligent car steering gear and speed measurement control design and implementation
Highlights from Freescale Technology Forum: Making the World Smarter
At this year's Freescale Technology Forum (FTF), in addition to traditional leading applications such as communications and automotive electronics, the company also demonstrated a variety of emerging technologies and solutions, including multimedia processors , sensors , and medical electronics
[Industrial Control]
Highlights from Freescale Technology Forum: Making the World Smarter
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号