PWM fluctuates on PIC18252


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2007
    Posts
    7

    Question PWM fluctuates on PIC18252

    Hey guys, I am using PWM on a motor and I have an LED that flashes after I send the pulse to the motor. When ever the LED flashes the motor revs up really fast. If I disable the LED or leave it on all the time there is no problem, eg. the motor gives a constant speed. Any Idea why this might be?

    Thanks , heres my code

    DEFINE OSC 20
    DEFINE LOADER_USED 1 ;bootloader
    main

    x var byte
    TRISB.1 = 0
    TRISa.2 = 0
    TRISB.2 = 0
    high porta.2
    low portb.2
    pwm portb.1,150,200

    low porta.2
    pause 500

    goto main
    end

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hey Gringo

    Well, you will have to use a Hardware PWM instead. Have a look to HPWM.

    It runs in background and whatever else your code do... it shouldn't affect the PWM signal.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringo332 View Post
    pwm portb.1,150,200
    The PWM command in PBP is a 'software' command... Program execution basically stops and that point and the only thing going on is the PWM command. If you need 'real' PWM, you have to use the hardware PWM module, or maybe software/interrupt driven PWM.

  4. #4
    Join Date
    Mar 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Smile thanks

    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.

  5. #5
    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.

  6. #6
    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