This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RE: NHET maximum HR clock

I'm using the HET to generate 4 square wave having fixed frequency and variable duty. The frequency must be in the order of 400KHz and the duty resolution should be the less as possible (at least 1% but 2% can be accepted.

I can do this with 5 instruction in the HET code:

L00 CNT { next=L01,reg=A,max=99};
L01 MCMP { next=L02,hr_lr=LOW,en_pin_action=ON,pin=1,order=REG_GE_DATA,action=PULSEHI,reg=A,data=50};
L02 MCMP { next=L03,hr_lr=LOW,en_pin_action=ON,pin=15,order=REG_GE_DATA,action=PULSEHI,reg=A,data=50};
L03 MCMP { next=L04,hr_lr=LOW,en_pin_action=ON,pin=13,order=REG_GE_DATA,action=PULSEHI,reg=A,data=50};
L04 MCMP { next=L00,hr_lr=LOW,en_pin_action=ON,pin=5,order=REG_GE_DATA,action=PULSEHI,reg=A,data=50};

Modifyng the "data" field of the four MCMP I can modify the dutys.
The "max" field in the CNT intruction gives my duty resolution.

The output frequency is then VCKL2 / (8*100) where 8 is the cycle count of a single execution and 100 is my duty resolution (the number of execution required for a single square wave).

Raising the VCLK2 to 200MHz I can generate a ~378KHz wave with ~1.5% duty resolution, wich is acceptable for my application.

Can you imagine a shorter code to do this?
  • Matteo,

    I split the thread because the forum wasn't showing me a reply button on the previous thread for some reason.
    Not sure if it is because there was a suggested answer ... I'll need to find out what that's all about.

    Anyway - this is where the hr_lr=HIGH option comes in. This will give you the ability to set your duty cycle to 10ns (100MHz / vclk2 assuming hr divider is /1). 10ns is 100MHz, and 100MHz/400KHz is 250x so you'll be better than 0.5% resolution.
  • Hi Matteo,


    Check the following instructions. The first one is a normal instruction(also this will be the smallest duty possible using a normal instruction).The second instruction is an HR instruction with higher resolution(around half).


    L01 MCMP { next=L02,hr_lr=LOW,en_pin_action=ON,pin=1,order=REG_GE_DATA,action=PULSEHI,reg=A,data=1};
    L01 MCMP { next=L02,hr_lr=HIGH,en_pin_action=ON,pin=1,order=REG_GE_DATA,action=PULSEHI,reg=A,data=0,hr_data=0x40};
    Just replace the L01 instruction in your program with the HR instruction above and see if your requirement is met. Please check the TRM for more info on HR instruction.

    Thanks and Regards,

    Vineeth

  • Hi Matteo,

     

    Any update on this? Were you able to try the suggestions?

     

    Thanks and Regards,

    Vineeth

     

    PS: Please expect delays in forum responses due to the holiday season.

     

  • Hi,

    thank you both for the suggestions.I've seen the post just now because of the split.

    I'm going to test it today and send you a reply asap.

    Matteo

  • BTW: I need to replace only the L01 intruction or all the 4 MCMP lines?
  • If I understand correctly the hr_lr=HIGH the hr_data can be set to add a "fractional" delay added to the loop resolution.

    So if
    L01 MCMP { next=L02,hr_lr=HIGH,en_pin_action=ON,pin=1,order=REG_GE_DATA,action=PULSEHI,reg=A,data=50,hr_data=0x00};
    gives a 50% duty and
    L01 MCMP { next=L02,hr_lr=HIGH,en_pin_action=ON,pin=1,order=REG_GE_DATA,action=PULSEHI,reg=A,data=51,hr_data=0x00};
    gives a 51% duty, than
    L01 MCMP { next=L02,hr_lr=HIGH,en_pin_action=ON,pin=1,order=REG_GE_DATA,action=PULSEHI,reg=A,data=51,hr_data=0x02};
    will give a 51.5% duty.

    Right?
    Which is the range of hr_data?
  • Another question: Actually to modify the duty crom inside the C code I'm using this instruction:

    hetRAM2->Instruction[pwm + 1U].Data = data<<7;

    where pwm is 0 to 3 and data is 0:100

    which instruction can I use to modify the hr_data?
  • BTW: I need to replace only the L01 intruction or all the 4 MCMP lines?

    Just try it for L01 to see if it works. Then you can replace the others.


    Thanks and Regards,

    Vineeth

  •  

    Hi Matteo,

     

    If I understand correctly the hr_lr=HIGH the hr_data can be set to add a "fractional" delay added to the loop resolution.

    Yes. Your understanding is right. It adds a controlled delay to the output which is a fraction of the LRP.

     

    Which is the range of hr_data?

    The HR_data length depends on the LRP value(the range is 0-7 bits). The higher the LRP value the higher the HR resolution possible. You can refer to the TRM to understand this better(N2HET Module > Time Base > The 7-Bit HR Data Field). Here is a table from this section of the TRM.

    Note that the HR data field ignores the LSB as the length decreases. For example, when you assign hr_data=2, 1 will be written to D[1] and 0 to D[0]. But these bits will be ignored if ‘lr’ is less than 64. This means HR data field will be read as zero if ‘lr’ is less than 64. If ‘lr’ is equal to 64, it will be read as 1. If ‘lr’ is 128, then it will be correctly read as 2. Take this into consideration when you assign hr_data.

     

    Thanks and Regards,

    Vineeth

  • which instruction can I use to modify the hr_data?

     

    You can use the same instruction as below.

    hetRAM2->Instruction[pwm + 1U].Data = ((data<<7) | hr_data);

    Thanks and Regards,

    Vineeth