Software PWM


Closed Thread
Results 1 to 2 of 2

Thread: Software PWM

  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Thumbs up Software PWM

    I have generated Software PWM of 20Khz by the help of Timer1 and it is working fine but the problem which i am facing now is that ,the main body is executing just one time only. I have attached the source code as well so please read my source code and please tell me what the hell is happening in code that main body has been executed just one time.

    device=16f876a
    xtal=20
    DECLARE CCP1_PIN PORTc.2
    PIE1 = $01 'Enable TMR1 overflow interrupt
    INTCON=%11010000 'Enable Global Interrupt,Peripheral and External Interrupts
    all_digital=true
    ON_INTERRUPT GOTO SENSOR_INT
    dim TIMER1 as tmr1l.word
    DIM A AS WORD
    dim B as word
    Symbol T1CKPS0 = T1CON.4 ' Timer1 Input Clock Prescale Select bits
    Symbol T1CKPS1 = T1CON.5 ' Timer1 Input Clock Prescale Select bits
    syMbol TMR1ON = T1CON.0 ' START OR STOP TIMER1
    SYMBOL FTMR1 = PIr1.0 ' TIMER1 OVERFLOW FLAG

    T1CKPS0=0 'PRE SCALAR SET TO 8
    T1CKPS1=0 '
    TIMER1=65335'485 'TIMER OFFSET FOR TIME DELAY=100ms
    low portc.4
    low porta.3
    TMR1ON=0'1
    ftmr1=0
    B=1
    Pie1.1=0 'when this value=0 then main body execute and if it is=1 then main execute ONLY ONE TIME
    hpwm 1,200,20000
    GOTO MAIN

    '************************************************* *******
    main:
    toggle porta.3
    HIGH 7

    INC B
    for a=1 to 65535
    NOP
    nop
    nop
    nop
    nop
    next

    for a=1 to 65535
    NOP
    nop
    nop
    nop
    nop
    next

    goto main

    '**********************START ISR( INTERRUPT SERVICE ROUTINE )*****************
    SENSOR_INT:
    if pir1.1=1 then
    TIMER1=65335'485
    HIGH PORTC.4
    TMR1ON=1
    PIR1.1=0
    ENDIF

    IF FTMR1=1 THEN
    LOW PORTC.4
    FTMR1=0
    ENDIF
    retfie fast
    'tmr1on=0
    'timer1=65410
    'toggle portc.4
    'ftmr1=0
    'tmr1on=1
    'CONTEXT RESTORE
    '************************END ISR( INTERRUPT SERVICE ROUTINE)*****************

    Also if i have change the value of PIE1.1=1 to PIE1.1=0 then software pwm stops and main body executes normally.

    I hope someone can help me.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    toggle porta.3
    HIGH 7
    PORTA.3 is analog.
    http://www.picbasic.co.uk/forum/showthread.php?t=561

    And what is "7" ??
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Darrel's Multiple Software PWM
    By passion1 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 15th October 2013, 15:21
  2. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 11:49
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  4. Variable PWM on 2 Channels using software.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2006, 01:34
  5. Software PWM Problems
    By surfer0815 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th November 2005, 13:53

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