+ Reply to Thread
Results 1 to 27 of 27
  1. #1
    Join Date
    Jan 2008
    Posts
    108

    Default 12F683 and DT Instant Interrupts

    I am trying to use Darrel Taylor's great Instant Interrupts (thank you!) on a 12F part. Originally, I was using a 12F635. I changed to a 12F683 after reading posts about doing this, because I was under the impression it would work O.K. However, I still get the following message when compiling:


    Hi, we are pleased to see that you are using our forum.

    We'd like you to become a member of our community. Membership is FREE, please REGISTER and view our forums without these annoying reminders!

    Once registered you may post on the forums, download from the file areas and use the WIKI without interruption.






    ERROR:Variable wsave2 position request 288 beyond RAM_END 191.

    Do I still need to comment out some lines?

    @ device pic12f683, INTRC_OSC_NOCLKOUT, WDT_OFF, MCLR_OFF, PROTECT_OFF

    OPTION_REG = %11000000
    OSCCON = %01100001
    TRISIO = %001100
    CMCON0 = %00000111
    ANSEL = 0
    CCP1CON = 0


    RATESW VAR BYTE

    HIGH GPIO.0
    HIGH GPIO.1
    HIGH GPIO.4
    HIGH GPIO.5
    pause 100

    RATESW = 0

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler INT_INT, _SWINT, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor

    INT_ENABLE INT_INT ; enable external (INT) interrupts
    ENDASM

    Main:

    if ratesw = 1 then Rate1
    if ratesw = 2 then rate2
    if ratesw = 3 then rate3
    if RATESW > 3 then RESET
    GOTO Main

    Rate1:

    while ratesw = 1
    LOW GPIO.0
    low GPIO.1
    pause 150
    high GPIO.0
    high GPIO.1
    low GPIO.4
    low GPIO.5
    PAUSE 150
    high GPIO.4
    high GPIO.5
    wend

    Rate2:

    while ratesw = 2
    LOW GPIO.0
    low GPIO.1
    pause 100
    high GPIO.0
    high GPIO.1
    low GPIO.4
    low GPIO.5
    PAUSE 100
    high GPIO.4
    high GPIO.5
    wend

    Rate3:

    while ratesw = 3
    LOW GPIO.0
    low GPIO.1
    pause 50
    high GPIO.0
    high GPIO.1
    low GPIO.4
    low GPIO.5
    PAUSE 50
    high GPIO.4
    high GPIO.5
    wend



    RESET:

    RATESW = 0
    GOTO Main

    GOTO Main

    '---[INT - interrupt handler]---------------------------------------------------
    SWINT:

    while GPIO.2 = 0:wend
    pause 100
    if GPIO.2 = 1 then
    RATESW = RATESW + 1
    endif

    @ INT_RETURN


    Thank you

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,896

    Default

    Yes, open DT_INTS-14.bas file.. and at the top, you'll discover...
    Code:
    ' --- IF any of these three lines cause an error ?? ---------------------------- 
    '       Comment them out to fix the problem ----
    ' -- It depends on which Chip you are using, as to which variables are needed --
    wsave1      var byte    $A0     SYSTEM      ' location for W if in bank1
    wsave2      var byte    $120    SYSTEM      ' location for W if in bank2
    wsave3      var byte    $1A0    SYSTEM      ' location for W if in bank3
    ' ------------------------------------------------------------------------------
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jan 2008
    Posts
    108

    Default

    Thank you for the reply. Unfortunately, I have all three lines commented out and now I get "Unable to fit wsave" .

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

    Default

    From that error, it looks like you're still compiling for the 12F635.

    If using MicroCode Studio, make sure the device dropdown box says 12F683.

    For the 683, you'll need both wsave and wsave1.

    Or you can use the alternate wsave location $70, and comment the other 3.
    <br>
    DT

  5. #5
    Join Date
    Jan 2008
    Posts
    108

    Default

    Thank you Darrel. Yes , the drop-down was incorrect. The program doesn't work, but that's because it's still Halloween!

  6. #6
    Join Date
    Nov 2008
    Posts
    96

    Default 12f683 messages too...

    I'm trying to get my head across the DT Interrupt code for a small new RC modeling project and I'm trying a test example first (the blinky LED) , compiling with MCS. I have 12f683 selected in MCS and MPASM being used.

    but I get an odd warning message from MCS thus :
    Warning[219] d:\pbp code\pbp\pbppic14.lib 336 : Invalid RAM location specified
    Warning[219] d:\pbp code\pbp\pbppic14.lib 892 : Invalid RAM location specified

    Anybody know why and if I should just disregard it ?

    I commented out the wsave lines as required (which led me here BTW)

    My code

    Code:
    LED1   VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    RBIF = GPIF
    RBIE = GPIE
    
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = $31                ; Prescaler = 8, TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    Main:
      PAUSE 1
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    My project is quite simple. A 22.5mS interrupt timer (TMR1 I guess) and toggle a few pins then wait for the next interrupt.
    Martin

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,935

    Default

    Try ...

    ;LED1 VAR PORTB.1

    LED1 VAR GPIO.1

    <br>
    DT

  8. #8
    Join Date
    Nov 2008
    Posts
    96

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Try ...

    ;LED1 VAR PORTB.1

    LED1 VAR GPIO.1

    <br>
    Yeah.... I forgot about port pins on the smaller PIC's (again).
    Ta, Martin

  9. #9
    Join Date
    Nov 2008
    Posts
    96

    Default Reload the TMR1H:TMR1L properly ?

    Now my code compiles fine thankyou, barring a overwriting previous address warning from my config settings (I understand why that is). But I have a small question regarding reloading the timer for anyone.

    Must I stop the timer while reloading it with a hex value of A823 in the interrupt handler code (which is all it needs to do) ?

    T1CON = %0
    TMR1H = $A8
    TMR1L = $23
    T1CON = %1

    Or can I ignore the stop-start safely. Given I can tweak the timer value by trial and error to get my 22.5mS @ 4Mhz ?

    The only examples I've dug out on the forum are using ASM code and I'm not strong on interpreting it.

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,935

    Default

    It's not absolutely required, unless the reload value is calculated.

    When you have a fixed value like that, you can be pretty sure the LowByte won't overflow before it loads the HighByte.

    However, you'll need to load the LowByte first, if you're not turning the timer off. And you'll also need to subtract 7 from the number you have, which is adjusted for a reload that does turn the timer off.
    <br>
    DT

  11. #11
    Join Date
    Nov 2008
    Posts
    96

    Default Elegent way to exit the handler and goto main code

    In my code I do a bunch of stuff then wait doing nothing for an interrupt some mS later, then when that happens I want to run my bunch of stuff again, forever and ever. Rather than return to where the interrupt occurred in my 'wait doing nothing'....

    I see the obvious way is to put my 'bunch of stuff code in the interrupt handler subroutine, but that makes the int handler routine very big and the 'main' code very small. Looks all wrong to me. Is that the way to do it or is there a proper way to get the int handler to go to my 'bunch of stuff' rather than return to where it was interrupted from ?

    Code:
    LED1   VAR  GPIO.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = $01                ; Prescaler = 1, TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    Main:
         Big bunch of stuff
    
    wait_here:
         pause 1
         Goto wait_here    'wait for an interrupt here
    (Return from Interrupt would hang here ?)
    
    GOTO Main    'should never happen
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
         
        T1CON = %0
        TMR1L = $23
        TMR1H = $A8
        T1CON = %1
        TOGGLE LED1    
    @ INT_RETURN

  12. #12
    Join Date
    May 2004
    Location
    Le Treport 76 FRANCE
    Posts
    3,339

    Talking The KISS way ...

    Hi, Mr Sneezy

    I do not know what's your final project ... BUT :

    Did you ever considered the R/C Framerate is an excellent timebase with 22.5 ms granularity ??? ( looks Graupner/JR remote ??? )

    No need for heavy interrupt implementing, then.

    just a simple idea ...

    Alain
    Last edited by Acetronics; - 12th November 2008 at 11:08.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  13. #13
    Join Date
    Nov 2008
    Posts
    96

    Default Generate PPM frames at 22.5mS rate

    Quote Originally Posted by Acetronics View Post
    Hi, Mr Sneezy

    I do not know what's your final project ... BUT :

    Alain
    but you're very very close Alain.....

    Except in my application I'm needing to generate an 8ch PPM pulse frame at 22.5mS rate from scratch.

    To cut to the chase what I want to do is build a simple RC TX radio eliminator so I can test prototype 2.4Ghz transmitter modules in the field (range tests etc etc) without needing a second person to wiggle the sticks on the radio (it uses Futaba compatible TX modules). I did the obvious thing and looked for existing projects but they all seem to decode PPM frames not create them...

    The app will change the PPM period for two channels (at least) slowly so the servos move at the RX end while I move away doing testing (sometimes Km's). The remaining channels will just be 1.5mS center position all the time.

    Sorry for the apparently newbie programming questions, I've actually written some quite large complex code in the past (way way past) but I do it so infrequently now I have to go back to basics at the start of a new project like a beginner. I never seem to do a similar project twice which doesn't help.

    I guess another way of asking my question is can I have a lot of code in the interrupt handler subroutine ? Or could that bugger up the interrupt code ?

    Thanks,
    Martin

  14. #14
    Join Date
    May 2004
    Location
    Le Treport 76 FRANCE
    Posts
    3,339

    Wink

    Hi, Martin

    I already have it here aboard a 12F675 ... just change repeating time to match the 22.5 ms ( was originally intended for a MPX frame ) lol !!!

    But do no want to tear your pleasure at all ... if it's your wish to discover interrupt charms !

    I' d recommand you to trim the first channel to 1.1 ms, the second to 1.2, third to 1.3 ... and so on. That will make later channel identification much easier.

    My application was static demo of boats without using RF ... ( Other Boats on "live show" at same time ... for the Warwick show !).

    Humouristically yours ...

    Alain
    Last edited by Acetronics; - 12th November 2008 at 13:25.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  15. #15
    Join Date
    May 2004
    Location
    Le Treport 76 FRANCE
    Posts
    3,339

    Default

    BTW ...

    I remember there's a non-PCM other solution ...

    PULSIN + some little lines can detect bad pulse duration ( = glitches = max. range) just place a servo in a preset position if glitches appear ( you can allow as much glitches as you want before entering " Fail safe" )

    Based on that ... you just take a receiver a batt and a servo, or your plane ... with you while the Tx keeps steady.

    I use it aboard a Glo Driver : Engine is slammed to idle, or cut, if too much glitches.

    Already saved many planes ... including scale championship ones !!!


    PCM have that feature ... so, just need to use it !!!

    My MC18 Transmitter also has a Servo-test feature ... that move automatically servos one after the other ...


    I didn't write it ... but why not use the coder's signal through the "Pupil's plug" ???
    Alain
    Last edited by Acetronics; - 12th November 2008 at 14:10.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  16. #16
    Join Date
    Nov 2008
    Posts
    96

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Martin

    I already have it here aboard a 12F675 ... just change repeating time to match the 22.5 ms ( was originally intended for a MPX frame ) lol !!!

    Alain
    Hi Alain,

    Yes thanks, if you have a code that does the same job I'd like to see it. I'll either try it out as you wrote it or use it for inspiration to finish mine. You could send it via a personal message or post it here. I have a couple of 12F675's in my bits box.

    Going on to your second reply, that is a good idea about the servo positions. To take it one step further I could have a PIC analysing the channel outputs over time and coming up with a sort of 'error rate' like we use on digital communications bearers here. Going all the way would have a PIC with LCD, displaying error rate (glitches/holds per minute ?) for each channel plus a summed figure. That way I can compare different 2.4Ghz receiver versions against a mathmatical benchmark...

    Oh boy, I'd better go do something else before this turns into a monster project !

    Martin

  17. #17
    Join Date
    Nov 2008
    Posts
    96

    Default Hanging the interrupt registers ?

    Getting back on topic with DT int code. Is it a bad thing to put GOTO's or GOSUB'S inside the interrupt handler ? Therefore maybe never seeing the @ INT_RETURN

    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:

    T1CON = %0
    TMR1L = $23
    TMR1H = $A8
    T1CON = %1
    TOGGLE LED1

    GOTO MAIN 'is this dangerous ?

    @ INT_RETURN

  18. #18
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,935

    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

  19. #19
    Join Date
    Nov 2008
    Posts
    96

    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

  20. #20
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,935

    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

  21. #21
    Join Date
    Nov 2008
    Posts
    96

    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

  22. #22
    Join Date
    May 2004
    Location
    Le Treport 76 FRANCE
    Posts
    3,339

    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 Acetronics; - 13th November 2008 at 15: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 " !!!
    *****************************************

  23. #23
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,935

    Default

    Love comes in many forms ...

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

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

  24. #24
    Join Date
    May 2004
    Location
    Le Treport 76 FRANCE
    Posts
    3,339

    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 Acetronics; - 13th November 2008 at 12: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 " !!!
    *****************************************

  25. #25
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,896

    Default

    1)French comments.
    2)No DT-int
    3)Mix ASM INT asm PBP... no context save/restore (even if probably not needed)
    DEFINE INTHAND _Marker
    '
    '
    '
    '
    Marker: ' Interruption - Génération de la trame

    Have i said rusty rusty KeyWee?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  26. #26
    Join Date
    May 2004
    Location
    Le Treport 76 FRANCE
    Posts
    3,339

    Talking Je me marre ...

    Hi, Steve

    I love this kind of programs ...

    Everybody looks for the failure ... and there's no failure.

    Just some "far from the manual" tricks ...

    Point 1 ) ... "Babelfish" it !!! as I didn't think one day it had to go out of my PC !!!
    Point 2 ) Why use DT interrupts ??? 1K prog memory and overall RAM will be MUCH too short ... ( Lol )
    Point 3 ) ABSOLUTELY Nothing to save here ... why loose time and hair ???

    Have a look to the produced .asm ... that's the important thing ... nooooooo ???

    Ha,ha ... maudit Français, hein ???

    best regards
    Alain
    Last edited by Acetronics; - 14th November 2008 at 13:06.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  27. #27
    Join Date
    Nov 2008
    Posts
    96

    Default First working draft

    I thought I might post my first working cut. It creates an 8ch PPM frame. The first two channels step in opposition to each other. The device allows me to run tests on manufacturers transmitter modules without using a real RC transmitter or operator.

    I enhanced it after this for different speeds and button control

    Code:
    '****************************************************************
    '*  Name    : 8ch PPM generator.BAS                                                                           
    '*  Author  : Martin S (mr.sneezy)                                                                               
    '*  Notice  : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS]                                     
    '*          : All Rights Reserved                                                                                    
    '*  Date    : 22/11/2008                                                                                            
    '*  Version : 1.0                                                                                                       
    '*  Notes   :   Code for PIC12F683, logic direction suits Futaba compatible TX modules         
    '*          :                                                                                                              
    '****************************************************************
    Define Osc 4
    
    ' Software Defines
    ' ----------------
            Temp_Var2 var word
            Servo_dir var byte      ' Store the servo going left or right direction flag 0 or 1
            Run_flag var byte       'Loop flag for triggering a PPM frame
    	PPM1_value  var Word	'variable for the value ch1 servo position pulse
    	PPM2_value  var Word	'variable for the value ch2 servo position pulse
    
            PPM_Out Var GPIO.0     'PPM drive for TX module is on this port pin
            LED1 Var GPIO.1         'Indicator LED is on this port pin
    
    
     ' Initialise Processor - check for each PIC type
    ' --------------------
        VRCON.7 = %0    'Comparator voltage reference OFF
        CMCON0 = %111    'Comparator inputs to OFF, all pins normal I/O
        ANSEL = 0        'Turn off all AD's 
          
    ' Set GPIO port pins as Input or Output
        TRISIO.0 = 0    'Input(0 = output, 1 = Input)
        TRISIO.1 = 0    '
        TRISIO.2 = 0    '
        TRISIO.3 = 1    '
        TRISIO.5 = 1    '
        TRISIO.6 = 1    '
        
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _my_handler,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
        T1CON = $1                ; TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
        Low LED1
        Low PPM_out
        PPM1_value = 500  'seed the center value of the servos
        PPM2_value = 500  'seed the center value of the servos
        Servo_dir = 0        'Set initial servo direction
        
    Main:
        While Run_flag = 0      'loop looking for trigger
            goto Main
        Wend
        
        Gosub Start_pulse   'start of a channel (or sync pulse)
        Gosub Channel_1     'channel 1 PPM period
        Gosub Start_pulse   'start of a channel
        Gosub Channel_2     'channel 2 PPM period
        Gosub Unused_ch     'a complete PPM channel pulse set, servo centered (1500uS)
        Gosub Unused_ch     '
        Gosub Unused_ch     '
        Gosub Unused_ch     '
        Gosub Unused_ch     '
        Gosub Unused_ch     '
        Gosub Start_pulse   'start of sync pulse
        
        If Servo_dir = 0 then  'do math while waiting for interrupt, plenty of time
            PPM1_value = PPM1_value + 5    'count upwards ch1 servo goes clockwise
        Else
            PPM1_value = PPM1_value - 5    'count downwards ch1 servo goes anti-clockwise
        Endif
        
        If PPM1_value = 1000  then    'detect servo limit CW
            Servo_dir = 1
        Endif
        
        If PPM1_value = 0  then     'detect servo limit CCW
            Servo_dir = 0
        Endif
        
        PPM2_value = 1000 - PPM1_value     'Ch2 servo moves opposite direction to servo Ch1
       
        Run_flag = 0               'clear the interrupt handlers trigger flag
      GOTO Main
    
     
    Start_pulse:
        high PPM_out 
        Pauseus 400         'channel start high period
        Low PPM_out 
        return
    
    Unused_ch:
        high PPM_out 
        Pauseus 400         'channel start high period
        Low PPM_out 
        Pauseus 1100         'Unused channel low period
        return
        
    Channel_1:
        Pauseus PPM1_value   'just leave channel low for X time
        Pauseus 600          'make up the minimum pulse to 1000uS
        return
             
    Channel_2:
        Pauseus PPM2_value   'just leave channel low for X time
        Pauseus 600          'make up the minimum pulse to 1000uS (start pluse + possition + this)
        return     
    
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    my_handler:
        
        T1CON = %0            'Stop timer 1
        TMR1L = $23           'Load for 22.5mS interrupts  
        TMR1H = $A8
        T1CON = %1            'Start timer1
        TOGGLE LED1
    
        Run_flag = 1
    
    @ INT_RETURN
    Last edited by mr.sneezy; - 22nd November 2008 at 13:56. Reason: Syntax

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 743
    Last Post: - 17th July 2014, 13:14

Members who have read this thread : 5

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