AnsweredAssumed Answered

HC908QT2, how to adjust the PWM duty cycle for TCH0 or TCH1

Question asked by xiaolaba on Aug 1, 2012
Latest reply on Aug 2, 2012 by xiaolaba

We have code snippet following, it works for fix frequency generation, both TCH0 and TCH1 are following this square wave output and 50% duty cycle has been achieved.

However, have been working on code tweaking and aims for change duty cycle on TCH1, according to HC08 TIM reference manual, loading up (TCH0H:TCH0L) with 0x0080, it was 50% duty cycle, so other value will be expected for different duty cycle, but sorry, aka, it is not working as expected but always 50%.

my HC08 TIM manual was downloaded here,

http://midnightdesignsolutions.com/hc908/manuals/TIM08%20Timer%20Interface%20Module%20Reference%20Manual%20%28tim08r1%29.pdf

 

would you please help

 

thanks

xiaolaba.

 

;;; ****************************************************************************************************************************;;; PTA0/TCH0 output frequency, AN2475, orginal code, test done;;; PTA0 output 156KHZ, inject to LPF;;; Test output, ;;; ****************************************************************************************************************************;;;;;;;;;;;;; original code, working;              mov    #InitpwmH,TCH0H           ;#InitpwmH = 0;              mov    #InitpwmL,TCH0L           ;#InitpwmL = $80, initial value for output compare (50%), test done               mov    #$20,TCH0H               mov    #$80,TCH0L ;initial value for output compare (no change ,still 50% ?? why);              mov    #TSC0_setting,TSC0   ;enable buffered PWM in channel 0 (PTA0/TCH0), TCH1 will not be active               mov    #%0011010,TSC0       ;unbuffered PWM in channel 0 (pin PTA0/TCH0), then TCH1 could output frequency too;TSCx_setting: equ    %00101010            ;TSCx Initial Value;                      ||||||||     (TIM Channel Status and Control Register);                      |||||||+-CHxMAX  - 0 Channel x Maximum Duty Cycle bit;                      ||||||+--TOVx    - 1 Channel x toggle on overflow;                      |||||+---ELSxA   - 0 |;                      ||||+----ELSxB   - 1 |;                      |||+-----MSxA    - 0 |;                      ||+------MSxB    - 1 |-> Config TIM as buffered PWM, 0 unbuffered PWM;                      |+-------CHxIE   - 0 disable Channel-X CPU interrupt;                      +--------CHxF    - 0 No input capture or output compare;;; PTA1/TCH1 output 156KHZ (TCH0 must be unbeffered PWM mode);;; QT4 has one timer only, frequency must be follow TCH0, so 35% duty cycle is a must to maintian output level witout overdrive;;; but how ?;;; 2012-07-20, how to enable PWM on TCH1, asked for help & solution;;; ****************************************************************************************************************************;;; https://community.freescale.com/thread/115800;;; For unbuffered PWM operation on TIM channel 1, you will need the following channel initialisation -;;;          mov    #%00011010,TSC1  ; Clear Ch1 output on compare, PTA1/TCH1;;; ****************************************************************************************************************************             mov    #$20,TCH1H             mov    #$80,TCH1L          ;initial value for output compare no change, (still 50% ?? why)             mov    #%00011010,TSC1     ; unbuffered PWM in channel 1 (pin PTA1/TCH1), then TCH1 could output frequency too

Outcomes