Hi everyone,
i'm trying to write a small HET program to generate PWM with centered duty cycle to its period. Currently I'm simulating my code with the HET IDE. I've achieved a working program while using only low resolution with the following code:
L00 CNT { next=L01,reg=A,irq=OFF,max=10,data=0}; L01 ECMP { next=L02,hr_lr=LOW,en_pin_action=ON,cond_addr=L00,pin=0,action=SET,reg=A,data=4}; L02 ECMP { next=L00,hr_lr=LOW,en_pin_action=ON,cond_addr=L00,pin=0,action=CLEAR,reg=A,data=6};
This generates PWM with 20% duty cycle centered to the period.
Now, if I want to use high resolution to set duty cycle in smaller steps I tried the following code:
L00 CNT { next=L01,reg=A,irq=OFF,max=10,data=0}; L01 ECMP { next=L02,hr_lr=HIGH,en_pin_action=ON,cond_addr=L00,pin=0,action=SET,reg=A,data=3,hr_data=64}; L02 ECMP { next=L00,hr_lr=HIGH,en_pin_action=ON,cond_addr=L00,pin=0,action=CLEAR,reg=A,data=6,hr_data=64};
If I understand correctly, this should generate PWM with 30% duty cycle. But actually the pin is set high correctly after 3 and a half loops, but never ever cleared to low again. It stays high forever.
I've played a little bit with different settings but didn't find any solutions or hint.
Another point I don't understand is the hr_data=64 command. My prescalers are HR = 1 and LR = 32 and if I look at the simulation I get 32 HR loops in one LR loop. But then, why do I have to write hr_data=64 for a half loop resolution? When I write this value to the instruction, the actual Data HR field in the memory is filled correctly with 16 (half a loop). Where is the conversion happening?
I'd be really happy if someone could explain me what I am doing wrong.
Greetings,
Steffen