Interrupt won't execute.


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re submitting code.

    Hey Ace, thanks for looking it over.

    As mentioned briefly above, when I cut and pasted my code, it seems a lot of the symbols didn't come across. I'll repost here:

    Code:
    define OSC 4
    ON INTERRUPT GOTO INTCODE
    
    
    DEFINE HSER_TXSTA 20h       'SET THE TRANSMIT REGISTER TO TRANSMITTER ENABLED
    DEFINE HSER_BAUD 2400       'SET BAUD RATE
                                'DEFINE ADCIN PARAMETERS
    Define ADC_BITS	10          'SET NUMBER OF BITS IN RESULT
    Define ADC_CLOCK 3          'SET CLOCK SOURCE (3=RC)
    Define ADC_SAMPLEUS 50	    'SET SAMPLEING TIME IN uS
    define LOADER_USED 1
    
    SELECTOR    VAR BYTE        'SELECTS PROGRAM TYPE
    TEMP        VAR WORD        'TEMPORY VARIABLE FOR ANY USE
    POSITION    VAR WORD        'POSITION OF SERVO1 1250 - 2500
    OFFWIDTH    VAR WORD        'HOW LONG THE PULSE NEEDS TO BE OFF FOR
    FREQ        VAR WORD        'FREQUENCY TO RUN THE SERVOS AT
    PICOSC      VAR BYTE BANK0  'TO STORE OSCILLATOR FREQUENCY IN
    PERIOD      VAR WORD        'TEMPORY VARIABLE TO DISPLAY THE PERIOD OF PULSE
    PRESCALER   VAR WORD        'STORES THE TIMER1 PRESCALER VALUE
    TMROFF      VAR WORD        'STORES THE TIME THAT THE SERVO1 PULSE WILL BE LOW
    RUN         VAR BIT         'IS THE PROGRAM RUNNING?
    
    ADCON1 = %10000010          'SET PORTA ANALOGUE AND RIGHT JUSTIFY THE RESULT
    
    SERVO1      var PORTA.0     'OUTPUT PIN FOR SERVO1
    PUSHBUTT    VAR PORTA.2     'INPUT PIN FOR PUSHBUTTON
    TRISB.4 = 1                 'INPUT FOR SELECTOR SWITCH PIN 13
    TRISA.0 = 0                 'MAKES PIN 19 AN OUTPUT FOR SERVO1
    TRISA.2 = 1                 'MAKES PIN 17 AN INPUT FOR PUSHBUTTON
    
    PRESCALER = 8               'DEFINES THE TIMER1 PRESCALER AS 1:8
    FREQ = 50                   'CONSTANT FREQUENCY FOR THE SERVOS
    RUN = 0                     'TEMPORARY VARIABLE FOR SERVO RUNNING
    
    T1CON  = %00110001          'ENABLE X,X,PRESCALER = 8,X,X,X,TMR1ON 
    INTCON     = %11001000      'ENABLE GIE,PEIE,x,x,GPIE,x,x,x
    GIE         var INTCON.7
    PEIE        var INTCON.6
    TMR1IE      var PIE1.0
    TMR1ON      var T1CON.0
    TMR1IE = 1                  '
    PEIE = 1                    'WHO KNOWS
    GIE = 1                     'WHAT ALL OF 
    PIR1.0 = 0                  'THESE DO, BUT IT 
    TMR1H = 0                   'DIDN'T START 
    TMR1L = 0                   'WITHOUT THEM.
    
    GOSUB GETOSC 
    
    MAINLOOP:
            IF PUSHBUTT = 1 THEN 
                HSEROUT ["HIGH.",13,10]
            ELSE 
                HSEROUT ["LOW",13,10]
            ENDIF
            GOSUB FINDPROGRAM
            GOSUB STARTPULSE
            'GOSUB STOPPULSE
    GOTO MAINLOOP
    
    FINDPROGRAM:                'SELECTS BETWEEN SEVERAL TYPES OF MOTION
        ADCIN 10, TEMP          'READ CHANNEL 10 TO TEMP
        IF TEMP <= 15000 THEN POSITION = 125                    'USES VOLTAGE DIVIDER TO
        IF TEMP > 15000 AND TEMP <= 22000 THEN POSITION = 150   'VARY THE VOLTAGE ON CH10.
        IF TEMP > 22000 AND TEMP <= 35000 THEN POSITION = 175   'THIS CONVERTS AND STORES
        IF TEMP > 35000 AND TEMP <= 47000 THEN POSITION = 200   'TO 'TEMP'.
        IF TEMP > 47000 AND TEMP <= 60000 THEN POSITION = 225   
        IF TEMP > 60000 THEN POSITION = 250
        GOSUB SETPULSE   
    RETURN
    
    DISABLE' INTERRUPT
    INTCODE:
        IF SERVO1 = 0 THEN
            HSEROUT ["FIRST IF - POSITION: ",DEC POSITION,10]
            TMR1H = ((65535 - POSITION)/256)            'EXTRACT HIGH BYTE INTO TIMER1
            TMR1L = ((65535 - POSITION)-(TMR1H*256))    'EXTRACT LOW BYTE
            HSEROUT ["HIGH: ", DEC TMR1H," LOW: ", DEC TMR1L,10]
            SERVO1 = 1
            HSEROUT ["SERVO1: ",DEC SERVO1,10,10]
        ENDIF
        
        IF SERVO1 = 1 THEN
            HSEROUT ["SECOND IF - TMROFF: ",DEC TMROFF,10]
            TMR1H = ((65535 - TMROFF)/256)              'EXTRACT HIGH BYTE INTO TIMER1
            TMR1L = ((65535 - TMROFF)-(TMR1H*256))      'EXTRACT LOW BYTE
            HSEROUT ["HIGH: ", DEC TMR1H," LOW: ", DEC TMR1L,10,10,13]
            SERVO1 = 0
            HSEROUT ["SERVO1: ",DEC SERVO1,10,10]
        ENDIF
        INTCON.0 = 0
        PIR1.0 = 0
    RESUME
    ENABLE' INTERRUPT
    
    SETPULSE:
        POSITION = POSITION MIN 250  'MIN POSITION LIMITED TO 0 DEGREES
        POSITION = POSITION MAX 125  'MAX POSITION LIMITED TO 180 DEGREES
        HSEROUT ["POSITION = ",DEC POSITION,10,13]
        TMROFF = (((((10000 / FREQ) * 10) / PRESCALER)*10) - POSITION)
        'HSEROUT ["TMROFF = ",DEC TMROFF,10,10]
        'PERIOD = TMROFF + POSITION
        'HSEROUT ["PERIOD = ",DEC PERIOD,10,10]
        
    RETURN
    
    STARTPULSE:
        HSEROUT ["PULSE STARTED",10,10]
        LOW SERVO1
        'GIE = 1             'GLOBAL INTERRUPT ENABLE
        'PEIE = 1            'PERIPHRIAL INTERRUPT ENABLE
        TMR1H = 255         'SETS TIMER1 TO 65535 
        TMR1L = 255         'NEXT TICK WILL INTERRUPT
        TMR1ON = 1
    RETURN
    
    STOPPULSE:
        HSEROUT ["PULSE STOPPED",10,10]
        LOW SERVO1
        PEIE =0
    RETURN
    
    GETOSC:
    
    asm
        ifdef OSC
           MOVE?CB   OSC, _PICOSC
        else
           MOVE?CB   4, _PICOSC
        endif
    endasm
    RETURN
    
    END
    I hope it worked this time, dunno what went wrong the first time.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Exclamation

    Sorry to insist, but " ON INTERRUPT " can't make things work nicely ...

    latency can be much over the positionning pulse length ...

    so, no hope this way ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Mar 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Ok.

    Fair enough Ace, I guess I'll have to nut out some ASM.

    IF you insist on using interrupts - that are not at all compulsory in such a project -
    Does this mean there's another way of doing this without interrupts?

    Bear in mind that I need to expand this to running two servos at once.

    your TMR1 calculations are false ( Where's the prescaler you've set to 8, gone ??? ),
    Are you saying that my timer1 calcs are wrong because I don't have a prescaler? All the calcs were done with the idea that if you multiplied them by 8 they would come out right.

    I thought T1CON = %00110001, would make the prescaler 8, have I done that wrong too?

    Sorry for all the mistakes, I'm just trying to figure it out.

  4. #4
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default We all know the answer .... again...

    If you have not looked at AND REJECTED the instant interupts that is made by DT (DT´s instant interupts) you should really look into that now.
    It is a way to solve all problems without even knowing how to spell to ASM.

    /me

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Thumbs down

    Hi, Jumper

    DT Basic Interrupts are wayyy too slow, here ... and overall their execution time is not predictable for timing corrections ...

    so, no joy nor !

    You do have to deal with ASM ... or write the program in pure PBP, without any interrupts ...

    Alain

    PS: and do not forget DT Bas ints consume a lot of RAM ...

    @ BB

    Does this mean there's another way of doing this without interrupts?

    Bear in mind that I need to expand this to running two servos at once.
    I alredy built a 4 channels fail-safe in pure PBP ... 4 Channels to read and 4 channels to output ... so, your project looks quite doable.
    Writing a neat timechart ... of course.
    Last edited by Acetronics2; - 25th March 2010 at 11:33.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Mar 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Unhappy One last question.

    alright Ace, I give in, you've got me in dispair with this project, I'll look for a totally different way.

    I alredy built a 4 channels fail-safe in pure PBP ... 4 Channels to read and 4 channels to output ... so, your project looks quite doable.
    Writing a neat timechart ... of course.
    Is this something you've released that I can learn from or even adapt?

    If I can't see the code, can you give me some hints about the way forward?

    I don't mind all the time charts in the world, but what's it for?

    I'll stop bothering you now, time for bed.

    Either way, thanks for the help, it's good to know when the idea you've got is impossible, that way you can move on; even if it is disheartening. Sniff...

    I'll check out DT's interrupts anyway - always learning.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Ok BB

    First of all ...

    explain with clear words what your device has to do :

    from which inputs (w/ details ) to which outputs ( w/details ) ...

    50% of the work is here ...

    Alain

    PS: and stop thinking " C " ... you must think " Basic " now ! ( ROFL)
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    DT Basic Interrupts are wayyy too slow, here ... and overall their execution time is not predictable for timing corrections ...
    Too Slow???
    For a Servo??? Get real.
    I've run 16 servo's simultaneously with DT_INTS.

    Timing not predictable??? What???
    It's extremely predictable. What are you talking about?

    PS: and do not forget DT Bas ints consume a lot of RAM ...
    oooo, ~50 bytes to have super easy interrupts, yeah too much RAM.

    Quote Originally Posted by bison_bloke
    alright Ace, I give in, you've got me in dispair with this project, I'll look for a totally different way.
    Don't listen to Alain.
    He's just being obstinate.
    DT

  9. #9
    Join Date
    Mar 2010
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Ok, let's see if we can make something of this mess...

    I've run 16 servo's simultaneously with DT_INTS.
    Does this mean there's code out there that I can directly adapt?

    Where would I find this?

    explain with clear words what your device has to do :

    from which inputs (w/ details ) to which outputs ( w/details ) ...
    I have two inputs: start/stop button and a 'selector switch' which I already have working with that if statement you see above.

    I have three outputs: two servos that I need to 'bounce' independently of each other. I need them to simulate the somewhat random movements that a passenger in a car would experience whilst driving. The third input is for vibration, this is just an unbalanced DC motor - np.

    I also want to run a countdown timer so that it gets turned of after 20mins.

    50% of the work is here ...
    So now that my project is exactly half done, which way do I head?

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