Interrupt won't execute.


Results 1 to 24 of 24

Threaded View

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


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    Here it is for Everyone ...

    a running version with a 16F877a and EasyPic 5 .

    still something to debug with HSEROUT, probably a timing issue ...

    Code:
    '****************************************************************
    '*  Name    : AdcServo2 : the ultimate vibrator ...             *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 01/10/2008                                        *
    '*  Process.: 16F877a / EasyPic5                                *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************' 
    
    '******************************************************************************
    ' Config
     @ device HS_OSC , WDT_ON , PWRT_ON , BOD_ON , LVP_OFF , protect_OFF
    
    '******************************************************************************
    'Defines
    
    DEFINE OSC 8
    
    DEFINE INTHAND _MAINLOOP
    
    DEFINE HSER_TXSTA 20h       'SET THE TRANSMIT REGISTER TO TRANSMITTER ENABLED
    DEFINE HSER_BAUD 9600       '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 LCD_DREG PORTB               ' I/O port where LCD is connected
    DEFINE LCD_DBIT 0					' 0, 1, 2, 3
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4                  ' Register select pin
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5                   ' Enable pin
    DEFINE LCD_BITS 4                   ' 4-bit data bus
    DEFINE LCD_LINES 2                  ' LCD has 2 character lines
        
    '******************************************************************************
    ' Comparator Config  
    
    CMCON       = %00000111
    
    '******************************************************************************
    ' Adc Config
    
     ADCON0     = %11000001     'SET PORTA ANALOGUE AND RIGHT JUSTIFY THE RESULT
     ADCON1     = %10001110     
      
    '******************************************************************************
    ' TMR1 Config : Preset = 45543  - Prescaler 1 
    ' 
    T1CON       = %00000000          'SETS THE TIMER1 VALUES - PRESCALER = 1
    
    '******************************************************************************
    ' Interupts config
    
     INTCON     = %11000000         ' GIE + PIE
     PIE1       = %00000001         ' TMR1IE
     PIR1       = 0
     PIE2       = 0
     PIR2       = 0
     
    '******************************************************************************
    'Variables
    
    wsave       var byte $20   system   ' just to avoid a compilator error ...
    wsave1      var byte $a0   system
    wsave2      var byte $120  system
    wsave3      var byte $1a0  system
    
    ssave       var byte Bank0 system
    psave       var byte Bank0 system
    
    
    
    POSITION    VAR WORD        'POSITION OF SERVO1 1250 - 2500
    TEMP        var word
    PLOW        var word        'low part of the servo signal
    COUNTER     var word        'Timeout counter
    PRESET      var word
    
    Delay       var BYTE
    RUN         VAR BIT         'IS THE PROGRAM RUNNING
    
     
    '******************************************************************************
    'Aliases
    
    GIE         var INTCON.7
    PEIE        var INTCON.6 
    TMR1IE      var PIE1.0
    TMR1IF      var PIR1.0
    TMR1ON      var T1CON.0
    
    '******************************************************************************
    ' Variable presets
    
    
    RUN         = 0                     'TEMPORARY VARIABLE FOR SERVO RUNNING
    POSition    = 150                   ' Servo @ RestPositon.   
    counter     = 0                     ' timeout counter
    PRESET      = 25555
    TMR1H       = Preset.Highbyte       ' Must be initialized ...
    TMR1L       = Preset.Lowbyte
    
    '******************************************************************************
    ' Constants
    
    SELECTOR    CON 0                   'Assign selector ADC Input to AN0
    
    '******************************************************************************
    ' I/Os
    
    SERVO1      var PORTC.0             'OUTPUT PIN FOR SERVO1
    STARTSTOP   VAR PORTA.4             'INPUT PIN FOR PUSHBUTTON
    
    PORTA = %00010111
    PORTB = 0
    PORTC = 0
    PORTD = 0
    PORTE = 0
    
    TRISA = %00000011
    TRISB = 0
    TRISC = 0
    TRISD = 0
    TRISE = 0
    
    Pause 500
    LCDOUT $FE, 1        ' Clear display, cursor off
                   
    '******************************************************************************
    '******************************************************************************
    
    MAINLOOP: ' Here we start a cycle ...
    
    TMR1on      = 0                     ' Reload the timer ...
    TMR1H       = PRESET.Highbyte
    TMR1L       = PRESET.Lowbyte
    TMR1IF      = 0
    TMR1ON      = 1                     ' Restart the timer
    GIE         = 1                     ' Interrupts authorized
    
    IF run THEN                         ' Run Button has to be pushed for first move
    
    FINDPROGRAM:                        'SELECTS BETWEEN SEVERAL TYPES OF MOTION
    
        ADCIN Selector , TEMP          'READ CHANNEL 10 TO TEMP
        
        SELECT CASE TEMP
        
        	Case is <  250  
        	 	POSITION = 125
    
            Case is <= 366 
         		POSITION = 150
         		    
        	Case is <= 583
        	 	POSITION = 175
        	 	  
        	Case is <= 783
        		POSITION = 200
        		    
        	Case is <= 1000  
         		POSITION = 225
         		   
        	Case is >  1000  
         		POSITION = 250
         		
         End Select
        
        low servo1
        Pulsout Servo1, position
        
        PLOW = 20000-POSITION
        
            
        IF COUNTER.5 OR ! COUNTER THEN
            'HSEROUT ["HIGH =" , DEC POSITION, " LOW =", DEC PLOW, 10,10,13]
            LCDOUT $FE,2 ,"Position = ",dec position,"    ", $FE,$C0,"TEMP = ", dec TEMP,"     "                                       
        Endif
    else
    
         
        IF COUNTER.5 OR ! COUNTER THEN
            'HSEROUT ["Waiting for RUN", 10,10,13,"HIGH =" , DEC POSITION, " LOW =", DEC PLOW, 10,10,13]
            LCDOUT $FE,2 ,"Waiting for RUN", $FE,$C0,"Position = ", dec position
        ENDIF
    endif
    
    '******************************************************************************   
    TESTINPUTS:
    
    Delay = 0
    Button Startstop,1,255,0,Delay,0,jump    ' Button active LOW !!!
    
    IF RUN THEN COUNTER = counter + 1
    IF counter => 60000 then counter = 0 :goto jump
    
    stop                                     ' Stop here and wait for interrupt
                                                ' to launch a new cycle
    JUMP:
    WHILE STARTSTOP = 0 : wend  
    RUN = ~run
    stop                                     ' Stop here and wait for interrupt
                                                ' to launch a new cycle
    END
    enjoy ...

    Alain
    Last edited by Acetronics2; - 26th March 2010 at 15:55.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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