PWM fluctuates on PIC18252


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringo332 View Post
    DEFINE OSC 20
    DEFINE LOADER_USED 1 ;bootloader
    main

    x var byte
    counter var byte

    TRISB.1 = 0
    TRISa.2 = 0
    TRISB.2 = 0
    high porta.2
    low portb.2
    pwm portb.1,150,200
    counter = counter + 1

    if counter > 127 then 'if counter is less than 128 turn led on
    low porta.2 'if counter if greater than 127 turn led off
    else
    high porta.2
    endif

    goto main
    end
    Quote Originally Posted by gringo332 View Post
    Thanks for the replies! I will look into it and let yall know what happens. Only thing is I don't remember this being a problem when I ran this same code on a 16f876.
    If I was going to do the same thing and use the 'software' PWM command, I might change your original code to what I put above, or maybe use a word value instead of a byte and change the cutoff point to 32767, or reset the counter if it hits 100, or 10000, or whatever.

  2. #2
    Join Date
    Mar 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Wink Problem found

    I see what was causing the motor to rev up. If you loop the PWM signal but if there is a PAUSE (i.e flashing an LED) before looping back this causes it to act this way. I think the motor responds this way when it is turned off. But if you loop back quickly the Pulse seems continuous with no hiccups. Yall are right, that I will probably have to use hardware PWM because I would be taking input from Infrared and doing some calculations before looping back.

    Thanks for the suggestion again guys!

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. PWM: Vernacular/Function (Newbee)
    By TerryN in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd July 2008, 16:58
  4. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 00:26

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