12F683 and DT Instant Interrupts


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    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 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 " !!!
    *****************************************

  2. #2
    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

  3. #3
    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 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 " !!!
    *****************************************

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    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.

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


    Did you find this post helpful? Yes | No

    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 Acetronics2; - 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 " !!!
    *****************************************

  6. #6
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    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: 772
    Last Post: - 17th February 2016, 23: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