Other Parts Discussed in Thread: HALCOGEN
王工您好:
我想问一下:
uint32 pwmPeriod = (hetRAM->Instruction[(cap << 1U) + 26U].Data) >> 7U;
和
uint32 pwmPeriod = (hetRAM->Instruction[(pwm << 1U) + 42U].Data + 128U) >> 7U;
1)有什么区别?
2)为什么第二行代码中要+128?
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.
王工您好:
我想问一下:
uint32 pwmPeriod = (hetRAM->Instruction[(cap << 1U) + 26U].Data) >> 7U;
和
uint32 pwmPeriod = (hetRAM->Instruction[(pwm << 1U) + 42U].Data + 128U) >> 7U;
1)有什么区别?
2)为什么第二行代码中要+128?
Hi Mingxi,
In the HALCoGen generated HET code,
uint32 pwmPeriod = (hetRAM->Instruction[(cap << 1U) + 26U].Data) >> 7U;
the 26th instruction is: PCNT which is used to capture the period of input signal 0
uint32 pwmPeriod = (hetRAM->Instruction[(pwm << 1U) + 42U].Data + 128U) >> 7U;
the 42th instruction is: MOV64 which is to update the period of PWM0 which is used by instruction #2 DJZ (remote address).
Now consider the data field of the MOV64 instruction:
This data field is made up or a 7-bit high-resolution data field and a 25-bit loop-resolution data field. This HALCoGen example does not use the high-resolution capability, so the "HR Data" field is not used. This is why the updated data value is shifted by 7 and then an offset of 128 is added (2^7 = 128).
王工:
1) 如果我想捕获PWM脉冲的周期period ,应该使用PCNT 还是MOV64 指令?
2)为什么代码2需要先加128再shifted by 7?而不是直接
uint32 pwmPeriod = (hetRAM->Instruction[(pwm << 1U) + 42U].Data) >> 7U;
1) 如果我想捕获PWM脉冲的周期period ,应该使用PCNT 还是MOV64 指令?
PCNT
2)为什么代码2需要先加128再shifted by 7?而不是直接
The DJZ instruction is used to generate PWM period, the 25-bit data in DJZ is decremented each time the DJZ instruction is executed until the counter reaches 0. So the period is data+1.
The DJZ Data field is updated by the instruction 42 (MOV64).