On Fri, Oct 19, 2012 at 5:40 PM, Oliver Seitz <[email protected]> wrote:

>
> Between now and a fix you might experiment with the procedure
> pwm1_set_percent_dutycycle() in stead of the procedures for 'absolute'
> settings.
>
> This is a good hint. And I would like to add: Always set the frequency
> first, and the duty cycle afterwards. Also, if you're changing the
> frequency,
> always set the duty cycle again (in percent).
>

like this:
-- start settings
pwm_max_resolution(1)
pwm_set_frequency
var byte PWMH_duty = 40
pwm1_set_dutycycle_highres(PWMH_duty)
pwm1_off()
-- end settings

where pwm_set_frequency has been modified as follows:

procedure pwm_set_frequency is
 const dword freq = 12000
   _pr2_shadow_plus1 = word(target_clock / freq) / 4

   T2CON = 0b0000_0000                          -- zero pre/postscaler,
disable Timer2
   if ((_pr2_shadow_plus1 > 0)  &               -- freq not too high and
       (_pr2_shadow_plus1 <= 4096)) then        -- freq not too low

      if (_pr2_shadow_plus1 <= 256) then
         T2CON_T2CKPS = 0b00                    -- set Timer2 prescaler 1:1
      elsif (_pr2_shadow_plus1 <= 1024) then
         _pr2_shadow_plus1 = _pr2_shadow_plus1 / 4
         T2CON_T2CKPS = 0b01                    -- 1:4
      else
         _pr2_shadow_plus1 = _pr2_shadow_plus1 / 16
         T2CON_T2CKPS = 0b10                    -- 1:16
      end if
      PR2 = byte(_pr2_shadow_plus1 - 1)         -- set PR2
      T2CON_TMR2ON = TRUE                       -- enable Timer2

   end if

end procedure

Vasile

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to