R32C111 Timer A3 Issue

Hy everybody,

I am using a R2C111 (64pins) for quite a long time and facing today an issue with the Timer A3

I am trying to decrement this timer with a 2 Mhz clock generated from the F2n divider.

It is working fine when the value in TA3 is higher or equal to 10 generating a frequency of 1Mhz

but when setting this value to 5 for instance, the frequency is still at 1Mhz.

Is there a limitation which prevent from generating more then 1 Mhz with the timers?

Thks for your usual help,

Jean-Pierre

 

Parents
  • How do you generate the output signal?

    I use the TA3 output function and toggle the port directly from the timer.

    I run TA3 directly on f1.

    There I can output up to 15MHz with my hardware.

    If you generate the output in an interrupt routine I think you see the limits in processor response to the interrupt + delays between CPU clock and peripheral clock.

  • I was using TA3 output signal generation just to check the output frequency and it seems to be ok. Now I am using 8 Mhz Main clock as input, divide by 8 with f2n (n=4) fot TA3 input clock. My purpose is now to measure a signal from 1 to 300 Hz, this signal cause an interrupt which start this A3 timer à 1 Mhz, next interrupt input is used to read the timer and determine the frequency but it appears that values read in the TA3 register are totally wrong and completely different from one to another although the generated input signal is perfectly stable and accurate as shown on the oscilloscope

  • First question is why don't you simply use a timer B for this? Using Timer B pulse width measurement you get the result with only one interrupt, better accuracy and much less effort.

    What do you mean when you say values are completely different?

    Using interrupts at measurement start and measurement stop you have varying delays both at measurement start and measurement stop. The cause is that an interrupt is not executed immediately when it occures, but only when the actually executed instruction is finished and, if you don't enable interrupt nesting or the priority of your interrupt is to low, when an actually running interrupt routine is finished.

    When you use timer count start/stop by software please make sure to write the count start value again when you restart the timer. Otherwise the timer may simply to count from where you stopped it.

    The best solution if you use timer A would be to use timer A3 as free running timer, and read the timer value at every interrupt. Then the difference between 2 timer values is your pulse width value.

    For better accuracy you could also use timer A3 interrupt as trigger for the DMA to transfer the count value to a variable and use the DMA interrupt to start the calculation.

  • In order to get the accucary I am looking for, I need a 32 bits register to measure the pulse, this is why I'm not using timer B but instead Timers A3&A4 cascaded.

    The values are totally different means two consecutive measurements with a stable input frequency give results with a big difference (over 10%)

    Here is the code used by the interrupt routine triggered by the input frequency with an int level of 7:

    RPM_int:

           bclr    ta3s                                      ; Stop RPM counter

           bclr    ta4s

           mov.w      ta3,rpm_lsb                  ; Save RPM_lsb

           mov.w      ta4,rpm_msb               ; Save RPM_msb

           mov.w      #0FFFFH,ta3                ; Reset RPM Primary   counter

           mov.w      #0FFFFH,ta4                ; Reset RPM Secondary counter

           bset        ta4s

           bset        ta3s                                 ; Restart RPM counter

    reit

    The timers A3 & A4 were initialiazed as follows:

    ;***************************************************************

    ;    Init Timer TA3 / RPM 1st timer register (bits 0-15)

    ;***************************************************************

    Init_timerA_3:

                mov.w      #0FFFFH,ta3

                mov.b       #00H,ta3mr               ; Timer mode freq = f1 = 8 Mhz

                mov.b       #0,ta3ic                      ; No interrupt            

    rts

    ;***************************************************************

    ;    Init Timer TA4 / RPM 2nd timer register (bits 16-31)

    ;***************************************************************

    Init_timerA_4:

               mov.w       #0FFFFH,ta4

               mov.b       #001H,ta4mr      ; Event mode no input frequence

               bset         ta4tgh                    ; Select A3 overflow

              mov.b       #0,ta4ic                 ; No Interrupt

    rts

  • Is there anyone having experienced these issues while trying to measure frequencies ?

  • Hi Frank,

    Did you find anything wrong is the code supplied above ?

  • I think the code looks fine (although I have not tried it yet).

    It could be that you have problems with the debugger. I think the debugger firmware may delay response to the interrupt routine causing the big difference in the timer values.

    BR

    Frank

  • It sounds to be a good idea to try without the debugger, I will set a session with 'program flash' option in the emularor setting windows.

    By the way I was always wandering if this option'program flash' completely remove any debugger code or is there another option in HEW IDE

    to be used to make sure only my program is up and running in the microprocessor? I am always using the debug session in Hew but may be should

    use release session instead, pls advise.

  • The option "Program Flash" programs only your application code to the target.

    When you select "Program Flash" in the Emulator Setting dialog you will note that you cannot input any addresses in the Firmware tab any more.

    And when you download your code you will see that the complete memory is written from your application.

  • Sorry for late reply but I had to take some vacations, My software is now working fine and frequence meter is great.

    I am wandering if there is an option in HEW to lock the file in read only mode in order to avoid errors when a file is completed.

    I am using Windows file attributes but it's a little bit heavy to manipulate  

Reply
  • Sorry for late reply but I had to take some vacations, My software is now working fine and frequence meter is great.

    I am wandering if there is an option in HEW to lock the file in read only mode in order to avoid errors when a file is completed.

    I am using Windows file attributes but it's a little bit heavy to manipulate  

Children
No Data