PWM generation with PIC16F628


Results 1 to 5 of 5

Threaded View

  1. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    now I'm no programmer and I might be laying myself bare for everyone to laugh at, but this is how I'd likely approach it...

    (disclaimer...there maybe some syntax errors, but you get the methodology blah blah)

    Code:
    begin:
    
    ADCIN 1,pot_sample
    
    if pot_sample = 127 then
    fwd_pwm = 0 & rev_pwm = 0
    hpwm 1,fwd_pwm,20000
    hpwm 2,rev_pwm,20000
    goto begin
    endif
    
    if pot_sample >127 then
    rev_pwm = 0
    fwd_pwm =255-pot_sample x 2
    hpwm 2,rev_pwm,20000
    hpwm 1,fwd_pwm,20000
    goto begin
    endif
    
    
    if pot_sample<127 then
    fwd_pwm = 0
    rev_pwm =127-pot_sample x 2
    hpwm 1,fwd_pwm,20000
    hpwm 2,rev_pwm,20000
    goto begin
    endif
    
    pause 20
    goto begin
    I'm sure to those who really are programmers, then the above is inelegant, but I'm a kludger & therefore go with what I can grasp...not elegancy!

    the above assumes 8 bit AtoD which obviously gives 256 levels & therefore a level of 127 becomes your zero point & your duty cycle changes in steps of 2 up to 256 for each direction. But like I say....what do I know?!!!
    Last edited by HankMcSpank; - 15th July 2010 at 21:15.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts