Problem with Timer Interrupt, PortB5-7 gets disabled


Closed Thread
Results 1 to 2 of 2
  1. #1

    Exclamation Problem with Timer Interrupt, PortB5-7 gets disabled

    Dear fellows, I'm trying to implement a timer which would get enabled on a specific action perfor a specific task ones the time is reached.

    I've achieved the timer thing using interrupts and breaking it down furthur and keeping a check on it. But achieving so i've came accross a number of problems

    1. Serin/Serout data started to messup...so used disable/enable before and after to run serial communication smoothly...

    2. Data read using names symbols on PortB failed so again disable/enable and used directly like PORTB instead of variable...this solved problem with Porb.0-Portb.4

    3. Now the actual problem being: I'm unable to deal with my inputs at Portb.5-Portb.7...

    I'm using 18F452 with a 4MHz XTAL

    The code for my interrupt and all is:


    '''''''''''''''''''''DEFINING and ENABLING INTERRUPT'''''''''''''''
    T0CON = %11000111
    INTCON = %00100000

    On Interrupt GoTo SwitchOff

    GoTo ProgramInitializationCont

    Disable
    SwitchOff:

    If CountIntTimer < TimerInSMS Then
    CountIntTimer = CountIntTimer + 1
    INTCON.2 = 0
    ElseIf CountIntTimer = TimerInSMS Then
    CountIntTimer = CountIntTimer + 1
    Power = 1 'Power Off
    Else
    Resume
    EndIf
    Resume
    Enable

    ''''''''''''''''''''''DEFINING and ENABLING INTERRUPT FINISHED'''''''''''''''


    TimeInSMS = 100

    ProgramInitializationCont:

    If PortA.0 = 1 then
    CountIntTimer = 0
    INTCON.2 = 0
    endif
    if PortB.7 = 1 then 'I'M NOT ABLE TO READ PORTB.5-7
    'Some other action
    endif

    end

    ''''''''''''''''''END OF CODE'''''''''''''''''''''''''''''''''

    An urgent solution in timers implementation and PortB reuse would be appreciated

    Best Regards
    JD

    PS: Although the code functions well on the OshonSoft PIC18 Simulator but am NOT ABLE TO READ MY PORTB IN PHYSICAL
    Last edited by jamshid.dastur; - 6th April 2010 at 18:53. Reason: forgot to mention simulation results

  2. #2


    Did you find this post helpful? Yes | No

    Lightbulb Made the timer work

    Instead of using the interrupts and blocking my port and all... i inserted the counter section into my main loops and making it count as it was in the interrupt, and without even enabling or disabling everything works fine and as had to... the section for timer now is


    timerin =1333333 ' The value depends on the program length, for my program length this value represents 1Minute or 60Seconds

    Main:

    'TIMER ROUTINE
    If TimerOn = 1 Then
    CountIntTimer = CountIntTimer + 1
    If CountIntTimer = TimerIn Then
    Power = 1 'Power Off
    TimerOn = 0
    EndIf
    EndIf

    if PortB.0 = 1 Then
    countinttimer = 0
    power = 0
    endif

    goto main

    end

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts