PWM Problem


Closed Thread
Results 1 to 2 of 2

Thread: PWM Problem

  1. #1
    Join Date
    Jun 2008
    Posts
    2

    Default PWM Problem

    Hi everyone,

    I am new to Pic and PicBasicPro, but I have to finish this project as soon as possible. I am trying to use 2 PWM outputs using a Pic16F877. altough it works in Proteus, unfortunately I could not make it work in a real design (To be honest I also have a problem in proteus simulator: after 4.30V it goes back to 4V and stops there, doesnt go higher). If you can give me any idea on my problem, I would really be appreciative. The code is below:

    '************************************************* ********
    adcon1 = 2

    trise = 0

    trisa = %11111

    trisb = %00010110
    input portb.4
    input portb.1
    input portb.2
    mode var portb.4
    plus var portb.1
    minus var portb.2

    TRISC = %11111001 ' PORTC are input lines except C1,C2 is HPWM output

    ' Define pwm parameters
    DEFINE CCP1_REG PORTC 'HPWM PORTC.1
    DEFINE CCP2_REG PORTC 'HPWM PORTC.2
    DEFINE CCP1_BIT 2 'CCP1 PİNİ PORTC.2
    DEFINE CCP2_BIT 1 'CCP1 PİNİ PORTC.1
    DEFINE HPWM1_TIMER 1 'Hpwm 2 timer select
    DEFINE HPWM2_TIMER 1 'Hpwm 3 timer select
    'DEFINE OSC 4 '4MHZ'LİK OSİLATÖR

    Define ADCIN parameters
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    ' Define LCD parameters
    DEFINE LCD_DREG PORTD ' I/O port with LCD. (Defining LCD data port)
    DEFINE LCD_DBIT 4 ' When using a 4 bit data bus, (0 or 4) designate beginning of data bits.
    DEFINE LCD_RSREG PORTD ' Defining LCD's register port.
    DEFINE LCD_RSBIT 2 ' Register select pin.
    DEFINE LCD_EREG PORTD ' Defining LCD's enable port.
    DEFINE LCD_EBIT 3 ' Defining LCD's enable pin.
    DEFINE LCD_BITS 4 ' Defining LCD has 4-bit data bus
    DEFINE LCD_LINES 2 ' LCD has two charecter lines

    out1 var byte
    out2 var byte
    out1 = 0
    out2 = 0

    out1plus var byte
    out1minus var byte
    out2plus var byte
    out2minus var byte

    out1plus = 0
    out1minus = 0
    out2plus = 0
    out2minus = 0

    new1 var word
    new2 var word
    old1 var word
    old2 var word

    old1 = 0
    old2 = 0

    lcdout $fe, 1, "Welcome to"
    lcdout $fe, $c0, "application"
    pause 3500

    loop:


    adcin 0, new1
    adcin 1, new2

    if (old1 <> new1 and old2 <> new2) then
    lcdout $fe, 2
    lcdout $fe, 1, "Input 1 => ", DEC (new1*100)/51
    lcdout $fe, $c0, "Input 2 => ", DEC (new2*100)/51
    endif
    old1 = new1
    old2 = new2

    if (mode == 0) then

    if (plus == 1 ) then '
    out1plus = out1plus + 1
    else
    if (minus == 1 ) then '
    out1minus = out1minus + 1
    endif
    endif
    else
    if (plus == 1 ) then '
    out2plus = out2plus + 1
    else
    if (minus == 1) then '
    out2minus = out2minus + 1
    endif
    endif
    endif

    if (out1plus >= 10 ) then
    if (out1<255) then
    out1 = out1 + 1
    endif
    out1plus = 0
    endif

    if (out2plus >= 10 ) then
    if (out2<255) then
    out2 = out2 + 1
    endif
    out2plus = 0
    endif

    if (out1minus >= 10 ) then
    if (out1>0) then
    out1 = out1 - 1
    endif
    out1minus = 0
    endif

    if (out2minus >= 10 ) then
    if (out2>0) then
    out2 = out2 - 1
    endif
    out2minus = 0
    endif


    HPWM 1, out1, 10000
    HPWM 2, out2, 10000

    goto loop

    end
    '************************************************* ********

  2. #2
    Join Date
    Jun 2008
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Sorry

    Sorry if I bothered you, bcs it was about our circuit. Somehow there was an short circuit that drove us crazy

    Thank you very much

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. problem with PWM
    By mimmmis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th September 2008, 13:36
  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 : 1

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