RZ A1 M- PWM waveform genration using timers

Hello everyone!

-->Why is it that TGRA and TGRB cannot take values given to them directly? For eg:

If I declare   mtu.TGRA=0xabcd; 

                   mtu.TGRB=0x6754;

It doesnt take value. When I pass it as argument through a function or use pointers then only it take values whereas for other registers like TMDR,TCR,TSR if I declare

                   mtu.TCR=0x89;

                   mtu.TSR=0x12;  Then e2studio takes values.

Also, noticed that TGRA,TGRB are 16 bit registers and rest TCR,TSR,TMDR are 8 bit. How to write values directly in 16 bit register? Is that even possible? 

I need to generate PWM waveform using timers of RZ A1 M, required for backlight control in HMI. Kindly guide. Thank you.

  • You can use this as an example.
    github.com/.../pwm-rza1.c
  • In reply to Chris:

    Hello Chris. Thanks for the reference code. I have already written a code but the problem in its execution is that the values of time period(i.e. TGRA) and duty cycle(i.e. TGRB) are not getting written in register while executio instead it shows default values only like TGRA= 0xffff and TGRB=0xffff. Where do you think can be the mistake? (NOTE: execution done in rz a1 m)
  • In reply to Rapunzel:

    Did you make sure the clock to the peripheral is on? By default, it is not connected (you cannot change any registers).

    Look at bit MSTP30 in Standby Control Register 3 (STBCR3)
    Module Stop 30
    When the MSTP30 bit is set to 1, the clock supply to the motor control
    PWM timer is halted.
    0: The motor control PWM timer runs.
    1: Clock supply to the motor control PWM timer is halted
  • In reply to Chris:

    Yeah,i checked the STBCR. The value stored was 0x00 and according to your suggestion I made it 0x01 to stop clock supply to motot control PWM timer.Still the situation is same values are not getting written to TGRA and TGRB.Rest all registers like TCR,TIORH,TSR,TMDR values are been written.

    What I have written in the code is as per mentioned in the flowchart of USERmanual. Its a very simple program.Firstly, as the flow diagram mentions to specify the TCR. I have done that then it specifies to mention TIOR(like TIORH and TIORL).Then specify time period and duty cycle using TGRA,TGRB. After that setting mode TMDR . Lastly, TSTR enabling. I have followed all steps still TGRA,TGRB not taking values. Rest all registers take values as specified in program.

    Also, the very first step is to stop the TSRT i.e. CST make zero or halt. That has been done.

  • In reply to Rapunzel:

    > The value stored was 0x00 and according to your suggestion I made it 0x01 to
    > stop clock supply to motot control PWM timer.

    No, want want a '0', not a '1'. If it is a '1', you cannot read/write any of the registers.

    Note that TGRA and TGRB are for the "Multi-function timer pulse unit 2". So you want bit MSTP33 of the Standby Control Register 3 (STBCR3). I mentioned MSTP30 before which is wrong.

    But, if you are seeing "FFFF", then it must be turned on (otherwise everything would just be 00s)

    > I have already written a code but the problem in its execution is that the values of time
    > period(i.e. TGRA) and duty > cycle(i.e. TGRB) are not getting written in register while executio
    > instead it shows default values only like TGRA= 0xffff and TGRB=0xffff.

    I was able to change those register without an issue.
    For example, address FCFF0308 is register TGRA_0.

    Below I am manually changing it in u-boot.

    => md.w FCFF0308
    fcff0308: ffff ffff ffff ffff 0000 0000 0000 0000 ................
    fcff0318: 0000 0000 0000 0000 ffff ffff 00c0 0000 ................
    fcff0328: 0000 0000 0000 0000 0000 0000 0000 0000 ................
    fcff0338: 0000 0000 0000 0000 0000 0000 0000 0000 ................
    fcff0348: 0000 0000 0000 0000 0000 0000 0000 0000 ................
    => mw.w FCFF0308 5555
    => md.w FCFF0308
    fcff0308: 5555 ffff ffff ffff 0000 0000 0000 0000 UU..............
    fcff0318: 0000 0000 0000 0000 ffff ffff 00c0 0000 ................
    fcff0328: 0000 0000 0000 0000 0000 0000 0000 0000 ................
    fcff0338: 0000 0000 0000 0000 0000 0000 0000 0000 ................
    fcff0348: 0000 0000 0000 0000 0000 0000 0000 0000 ................
  • In reply to Chris:

    ---->No, want want a '0', not a '1'. If it is a '1', you cannot read/write any of the registers.

    I got this point. I have kept it as 0 only.

    ----->But, if you are seeing "FFFF", then it must be turned on (otherwise everything would just be 00s)
    I am seeing TGRA as 0xffff and TGRB as 0xffff whereas I have kept TGRA as 0x20 and TGRB as 0x10 in the program.


    ------>Below I am manually changing it in u-boot.
    Problem is that when I am debugging and checking values of TGRA and TGRB in I/O register window (in e2 studio).I can change value from there manually by entering values from keyboard BUT I want it to take values of TGRA and TGRB from the program.

     
  • In reply to Chris:

    -->Why is it that TGRA and TGRB cannot take values given to them directly? For eg:

    If I declare mtu.TGRA=0xabcd;

    mtu.TGRB=0x6754;

    It doesnt take value. When I pass it as argument through a function or use pointers then only it take values whereas for other registers like TMDR,TCR,TSR if I declare

    mtu.TCR=0x89;

    mtu.TSR=0x12; Then e2studio takes values.

    Also, noticed that TGRA,TGRB are 16 bit registers and rest TCR,TSR,TMDR are 8 bit. How to write values directly in 16 bit register? Is that even possible?