problem with PWM


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2007
    Posts
    8

    Angry problem with PWM

    Hi i made a connection computer-->rs232-->pic16f876. it works fine. then i connected an h-bridge and a dc motor to my pic. it works fine. with 1 it moves counterclockwise with 2 clockwise and with 0 it rests.my program

    INCLUDE "MODEDEFS.BAS"

    B0 VAR WORD
    B1 VAR WORD
    Pause 500
    SerOut2 PORTC.6,84,["Hi!",13,10]

    start:

    SerIn2 PORTC.7,84,[DEC B0]
    IF(B0==1) Then
    Low PORTC.1
    High PORTC.2
    EndIF

    IF(B0==0) Then
    Low PORTC.1
    Low PORTC.2
    EndIF


    IF(B0==2) Then
    Low PORTC.2
    High PORTC.1
    EndIF

    GoTo start
    End


    I have to problems:
    first i want to put some different levels of speed.
    so i wrote the following program but it works as the first program!with numbers 3 and 4 i can't see reduce in speed.

    INCLUDE "MODEDEFS.BAS"

    B0 VAR WORD
    B1 VAR WORD
    Pause 500
    SerOut2 PORTC.6,84,["Hi!",13,10]

    start:

    SerIn2 PORTC.7,84,[DEC B0]
    IF(B0==1) Then
    Low PORTC.1
    High PORTC.2
    EndIF

    IF(B0==0) Then
    Low PORTC.1
    Low PORTC.2
    EndIF


    IF(B0==2) Then
    Low PORTC.2
    High PORTC.1
    EndIF

    IF (B0==3) Then
    Low PORTC.2
    PWM PORTC.1,128,10
    EndIF


    IF (B0==4) Then
    Low PORTC.2
    PWM PORTC.1,64,10
    EndIF




    GoTo start

    End


    SECONDLY i want the motor dc to run in the speed i say until a new press from my keyboard.do i need harware pwms? i need 4 (=2 motors). is there a pic with 4 pwms?
    Thanx in advance

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    PWM is a 'blocking' command, synchronous, one-at-a-time...
    While a PWM command is executing, nothing else can run. PWM is software driven, bit-banged, etc.

    HPWM on the other hand is hardware driven. Set the registers and it runs without further program intervention, aside from changing the frequency and/or duty cycle.

  3. #3
    Join Date
    Mar 2007
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    thanx skimax!

    with further investigation i have made a hardware pwm that sets in the background!
    here is the code if anyone needs it

    INCLUDE "MODEDEFS.BAS"


    ' ** Declare Variables **



    Pause 500


    start:

    IF PORTB.7=1 Then

    TRISC.2 = 0 ' Enable PORTC.2 (CCP1) as output for PWM
    T2CON = %00000100 ' Set the Prescaler for 1:1, and turn on TMR2
    PR2 = 255 ' See above calculation for the output period



    CCPR1L = 128 ' MSB of the 10-bit duty value
    CCP1CON.2 = 1 ' Turn on PWM Module one,
    CCP1CON.3 = 1 ' by setting bits 2 and 3 of CCP1CON

    EndIF


    IF PORTB.7=0 Then
    CCPR1L = 0
    CCP1CON.2 = 1 ' Turn on PWM Module one,
    CCP1CON.3 = 1 ' by setting bits 2 and 3 of CCP1CON
    High PORTB.6
    EndIF

    GoTo start







    End

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mimmmis View Post
    thanx skimax!

    with further investigation i have made a hardware pwm that sets in the background!
    here is the code if anyone needs it
    Or you could just use the HPWM command...

Similar Threads

  1. Low freq PWM problem
    By ultiblade in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 17th February 2010, 07:09
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. PWM Problem
    By cihhan in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th June 2008, 18:43
  4. Problem with PWM using 16F688
    By electrocomp in forum General
    Replies: 9
    Last Post: - 1st December 2007, 14:14
  5. PWM problem CCP2 port
    By NL2TTL in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 19th September 2006, 23:34

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