12F683 and DT Instant Interrupts


Closed Thread
Results 1 to 27 of 27

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    GOTO MAIN 'is this dangerous ?
    Suicidal!

    You will only get one interrupt that way, untill power is cycled or the GIE bit is set manually.

    If you need to trigger processes in the main loop, you can set a Flag in the handler. Once it returns from the handler, the main loop can execute the required task where it can be interrupted again.

    On 12F's and 16F's, you should NEVER gosub from the handler. There just aren't enough stack levels.
    DT

  2. #2
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    "Suicidal" I like it Darrel :-)
    That word doesn't get used in code discussion much I'm sure...
    OK, I just hit 'undo' on my code several times to stop myself needing to go slash my wrists ;-)

    Flag. OK, if I understand correct I should set a flag variable in the int handler, then put my main code into a tight loop checking for it, then jump to my PPM output code when true, then back to the tight loop after clearing the flag...

    There are a heap of ways to make a tight loop (If-then, While-wend, repeat-until). What would be the tightest (fastest) ? ASM ?

    Martin

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mr.sneezy View Post
    There are a heap of ways to make a tight loop (If-then, While-wend, repeat-until). What would be the tightest (fastest) ? ASM ?
    Anything that requires precise timing should be done in the handler, preferably in an ASM handler.

    When it returns to the Main loop with a Flag set, the process it triggers should be able to do it, "whenever it gets around to it". There may be several things going on, and there's no guarantee when it will be processed.

    If you're reading servo pulses, then the entire process of measuring the pulse should be done with the interrupts, and I don't mean sitting in a PULSIN statement in the handler. On the rising edge, start a timer. On the falling edge, stop the timer and collect the reading. Each time leaving the handler until the next condition occurs. Once you have a reading, then set a flag to let the main loop know to process the data. Now it has all the time in-between pulses to work on all those error rates, jitter etc and display them on the LCD at it's leisure.
    DT

  4. #4
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,
    In this part of the project (maybe the only part) I'm making the pulses, eight in a row for eight RC servo channels, of varying periods, rather than reading them. The TMR1 interrupt is just keeping the overall frame timing right.
    Looking it now I think a tight loop reading the roll-over flag of the counter then doing the pulse train code would have worked just as well. I guess I thought that a real timer interrupt would minimise jitter in the total frame length.
    Never mind, I'll carry on with the interrupt method now that I've started it.

    I'd still like to see Alains code though.... Alain ?

    Martin

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


    Did you find this post helpful? Yes | No

    Talking You've asked for it ... do not cry, now !!!

    Hi, Martin

    Darrel will love it, for sure !!! ( Lol ...)

    Code:
    '*****************************************************************************
    'FRAMEGEN.BAS
    '*****************************************************************************
    '
    ' Générateur de Trame R/C Graupner/Multiplex sur 12F675
    '
    ' 4,7,8 ou 9 Canaux - Neutre 1.5 ms
    '
    ' Oscillateur interne 4 Mhz
    '
    ' Trames déclenchées par interruptions TMR0 : PS = 1/128 Pl = 80
    '
    ' Sortie sur GPIO.5
    ' Choix 4,7,8 ou 9 voies sur GPIO.3 et 4
    
    '*****************************************************************************
    '*****************************************************************************
    '
    @    __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _BODEN_ON
    
    
    DEFINE OSC 4
    DEFINE OSCCAL_1K 1
    DEFINE INTHAND _Marker
    
    ADCON0		= 0
    ANSEL		= 0
    CMCON		= 7
    
    OPTION_REG	= %10000110     'Disable Pull-Ups - PSA = 128
    INTCON		= %00100000		'TMR0 interrupt
    PIE1		= 0
    PIR1 		= 0
    
    '*****************************************************************************
    ' Constantes
    
    Mark 	CON 400
    Reload 	CON 80
    Neutral CON 1500
    GR		CON 8
    MPX		CON 9
    
    '*****************************************************************************
    ' Variables
    
    
    PROGRAM		var byte
    PROGRAMOLD	var byte
    
    FRAME4		var bit
    FRAME7		var bit
    FRAME8		var bit		
    
    CLEAR
    
    '*****************************************************************************
    ' I/Os
    
    GPIO 		=%00100000	'GPIO.5 = 1 at startup
    TRISIO 		=%00011000  'set GPIO3 GPIO4 as input GPIO.5 as Output
    
    '*****************************************************************************
    
    GOTO INIT
    
    '*****************************************************************************
    '*****************************************************************************
    Marker: ' Interruption - Génération de la trame
    
    TMR0 = Reload
    
    GPIO.5 	= 0
    PAUSEUS	Mark
    
    GPIO.5 	= 1				' Voie 1
    PAUSEUS 696
    
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 	= 1				' Voie 2
    PAUSEUS 796
    
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 	= 1				' Voie 3
    PAUSEUS 896
    
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 	= 1				' Voie 4
    PAUSEUS 992
    
    IF FRAME4 THEN Selection
    
    @ NOP
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 	= 1				' Voie 5 - 1500µS
    PAUSEUS 1096
    
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 	= 1				' Voie 6
    PAUSEUS 1196
    
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 	= 1				' Voie 7
    PAUSEUS 1290
    
    IF FRAME7 THEN Selection
    
    @ NOP
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 	= 1				' Voie 8
    PAUSEUS 1392
    
    IF FRAME8 THEN Selection
    
    @	NOP
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 	= 1				' Voie 9
    PAUSEUS 1496
    
    Selection:
    
    GPIO.5 = 0
    PAUSEUS Mark
    
    GPIO.5 = 1
    
    '*****************************************************************************
    'Lecture des Jumpers
    
    PROGRAM = GPIO & %00011000
    
    IF PROGRAMOLD <> PROGRAM THEN INIT
    
    '*****************************************************************************
    Start: 'Fin d'Interruption
    
    INTCON.2 = 0
    INTCON.7 = 1
    
    '*****************************************************************************
    CYCLE: 'Boucle de fonctionnement
    
    WHILE 1
    WEND
    
    '*****************************************************************************
    INIT: 'Lecture des Jumpers
    
    PROGRAM = GPIO & %00011000
    
    SELECT CASE Program
    
    	CASE 24
    	
    		FRAME4 = 1 : FRAME7 = 0 : FRAME8 = 0
    		
    	CASE 16
    	
    		FRAME4 = 0 : FRAME7 = 1 : FRAME8 = 0
    		
    	CASE 8
    	
    		FRAME4 = 0 : FRAME7 = 0 : FRAME8 = 1
    		
    	CASE ELSE
    	
    		FRAME4 = 0 : FRAME7 = 0 : FRAME8 = 0
    		
    END SELECT
    
    PROGRAMOLD = PROGRAM
    
    GOTO Start
    
    END
    If you want to have variable pulse length... just inc or dec the PAUSEUS value before the "START" Label


    And ... if you find something strange ... it is NOT an error !!!

    ( I told you Darrel would love it ....)

    Alain
    Last edited by Acetronics2; - 13th November 2008 at 14:45.
    ************************************************** ***********************
    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
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Love comes in many forms ...

    I'm still looking for the one that applies here.

    Ummm, I found something strange ...
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Wink I should had bet 50$ !!!

    Quote Originally Posted by Darrel Taylor View Post
    Love comes in many forms ...

    I'm still looking for the one that applies here.

    Ummm, I found something strange ...
    <br>
    Hi, Darrel,

    Really ???

    I'm so surprised ... Something missing, may be ???

    Regards
    Alain
    Last edited by Acetronics2; - 13th November 2008 at 11:21.
    ************************************************** ***********************
    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 " !!!
    *****************************************

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14

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