Pulse-Division type PWM ?

Hello,

Is RX231 MCU support Pulse-Division type PWM ?

It's from MCU Renesas H8/38076RF.

Thank you

Parents
  • Hello dear iamno3, thank you for posting on the Renesas community. 

    The topic of "Pulse-Division type PWM" is specific to the device that you were using. that  H8/38076RF has a 14-bit unit dedicated to Generate PWM waveform and the pulse division feature is provided to multiply the PWM frequency by 4 and decrease the amount of RC filter on PWM signal which can be used as DAC unit in that MCU. 

    But in newer devices, it's prevalent to have a much more flexible Timer/Counter unit that can handle PWM generation easily.

    In the figure you shared, the original PWM signal has been divided by 4 both in high/low periods, which ends up with a PWM signal with the same duty cycle but 4x frequency. 

    You can easily change the configuration of your timer unit in RX231 to achieve this by software. both MTU and TMR units are capable of doing so in RX231 MCU. If you're coming from the H8 series, check out the below document which is the migration guide from H8 to RX231 MCU specific for timer and PWM topic :

    https://www.renesas.com/us/en/document/apn/h8h8s-rx-mcus-h8s-rx-migration-guide-timer-rev100

    I hope you find it useful. 
    Kind regards, 
    Hossein. 

    If this or any other user's response answers your concern, kindly verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    en-support.renesas.com/.../

  • Dear Hossein,

    Thank you for your reply. So you mean that pin 74 PWM1 can be replace by TIOCA pin on RX231 ?

    That pin (74 PWM1) is generating chime tone.

Reply Children
  • Yes, if its purpose is to generate sound, you can easily implement its function with the DAC unit in RX231 MCU.
     but DAC doesn't need to be filtered like what PWM needs and is much more convenient.  

    To play a sound or tone using DAC, you just need to convert your audio to PCM 8-bit mono format, with a decent sampling rate like 16Khz or higher.  then convert the file to an array of bytes to be used as DAC input data. 

    then the DAC conversion should be triggered at the same rate as the sample rate of the audio. which can be obtained by a timer interrupt. 
     
    I hope you find it useful. if you need help regarding that, don't hesitate to ask. 

    If this or any other user's response answers your concern, kindly verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    en-support.renesas.com/.../

  • Hello Hossein,

    Thank you for your explanation about DAC. I use original source code from H8 MCU they don't use audio file but using base 1 hz it's look like this then they use formula to generate PWM data then output to pin 74. (TBLDT_NUM = 13021)

    The formula :

    1st note

    2nd note

    3rd note

    4th note

    add all note

    Initial value of TXDT_CNTR is 32767. It's look like txdata is value of counter to determine the duty cycle but I'm not sure.

    Out to PWM pin 74

    I want to porting that code to rx231. I'm sorry I cannot share complete source code.

    But I just want to know possiblilty to apply that code to rx231.

    Thank you

  • Hi iamno3, thank you for providing the code snippets, 
     Yes, it's possible to port the code to RX231. 

    The sound is somehow generated and eventually, the final value is passed to the PWM 14-bit unit of the H8. Regardless of the way the sound is generated, we want to generate an analog voltage at a sample time (which I believe is 13Khz in your case), as I can see the 'PWDR1' Register gets updated in each timer interrupt callback. 

    To port the code for RX231, you'll need to substitute the  'PWDR1' register with 'DA.DADR0' which holds the 12-bit data of the DAC channel 0 in the RX231. 
    but you need to divide the value by 4 to transform the 14-bit value to 12-bit. and initialize and start the DAC unit before using the DAC. 

    for example, the code above should be transferred to the code below, and you'll get the same result on the DAC pin. 

    if (flg_txdtin){
    	DA.DADR0 = (uint16_t)((txdtbf / 4) & 0x0FFFU); //Set the DAC channel 0 value
    	flg_txdtin = FLG_OFF;
    }

    If this or any other user's response answers your concern, kindly verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    en-support.renesas.com/.../


     

  • Hello Hossein,

    Sorry for late reply just got back from long holiday.

    Thank you for your explanation. I will try your implementation.

    And will get back when it works.