Can somebody help?


+ Reply to Thread
Results 1 to 4 of 4

Thread: Can somebody help?68 days old

  1. #1
    Prolific Poster shantanu@india's Avatar
    Join Date
    Feb 2007
    Posts
    1,705
    Thumbs Up
    Received: 7
    Given: 21
    Total Downloaded
    827.23 MB

    0 Not allowed!

    Default Can somebody help?

    Hi,
    Posting my friends code(who is a registered user but yet to join the forum!!).

    He's doing a project with 16F866 where the LCD gets refreshed @ 5 seconds by the timer1 interrupt.
    His code is quite well commented!!
    For some reason , the interrupts stop after a couple of runs.
    I don't have a device to test....& I could not find any major fault in the code.

    Any help would be appreciated.
    Thanks & stay safe.....the crisis shall be over soon.

    Here is the code:

    Code:
    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings
    
    
    Device = 16F886
    
    
    Config1 FOSC_INTRC_NOCLKOUT, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_ON, CPD_OFF, BOREN_ON, IESO_OFF, FCMEN_OFF, LVP_OFF, DEBUG_OFF
    Config2 BOR4V_BOR21V, WRT_OFF
            OSCCON = 100111     '7-unimplemented, 6,5,4-110 for 4MHz, 3-0 for internal oscillator, 2-1 HFINTOSC is stable,
                                   '1-1 LFINTOSC is stable, 0-1 internal oscillator is selected for system clock.
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
            Declare  Xtal = 4                         '4MHZ internal
            Declare   Reminders 0
            Declare   Warnings 0
            Declare Optimiser_Level = 3                 ' Full optimisation
            Declare   Dead_Code_Remove = On               ' Remove redundant ASM mnemonics
    ' Initialize 16X2 LCD for 4 line interface       
            Declare LCD_Type 0
            Declare LCD_DTPin PORTC.0
            Declare LCD_RSPin PORTC.4
            Declare LCD_ENPin PORTC.5
            Declare LCD_Interface 4
            Declare LCD_Lines 2        
            Declare SHOW_SYSTEM_VARIABLES = True
    
    
    '        Declare Float_Display_Type = Fast '********added 6/3/2020****************
    '--------------------------------------------------------------------------------
    
    
     'variables
     Dim    BPF           As Byte System
     Dim    timer1        As TMR1L.Word 'timer1 addresses the 16bit TMR1 as a Word Variable 
     Dim    lcd_updtCount   As Byte      'Counter to reinitialize and update LCD every 3sec
     Dim    lcd_updt        As Byte       'LCD update Bit
     Dim    adval         As Word         'A to D value temporary storage register 
     Dim    loadcurr      As Float       'Floating point variable used for rolling average load current calculation
     Dim    loadcurr_r      As Float       'Floating point variable used for rolling average load current calculation 
     Dim    loadcurr_y      As Float       'Floating point variable used for rolling average load current calculation
     Dim    loadcurr_b      As Float       'Floating point variable used for rolling average load current calculation
     Dim    spanvalr       As Word         'for storing A To D value corresponding to Span
     Dim    spanr          As Word         'for storing span current reading 
     Dim    spanvaly       As Word         'for storing A To D value corresponding to Span
     Dim    spany          As Word         'for storing span current reading
     Dim    spanvalb       As Word         'for storing A To D value corresponding to Span
     Dim    spanb          As Word         'for storing span current reading
     Dim    zeroval       As Word         'For storing A To D value corresponding To Zero
     Dim    address       As Byte         'Stores starting address of EEPROM to be accessed
     Dim    varwrd        As Word         'General Word variable used only for Programming mode
     Dim    flt           As Float        'General floating point variable
     Dim    fltr          As Float 
     Dim    flty          As Float
     Dim    fltb          As Float
     Dim    i             As Byte         'General Byte variable
     Dim    Rvolt         As Word 
     Dim    Yvolt         As Word
     Dim    Bvolt         As Word
    
    
    '*************************************************************
    'hardware details
    Symbol  trip_led     PORTB.5        ' Output
    Reminders =0
    Warnings=0  
    '******************************************************************************
     GoTo    main            'jump over to main loop                          
    '******************************************************************************
    
    
    
    
    
    
    '***********INTERRUPT ROUTINES used for O/L sensing delay (30 sec) - prevents spurious overloads**********
    '***********and reinitialization of LCD and also program mode*********************************************
    On_Hardware_Interrupt GoTo check_cause
    'Int_Sub_Start----------
    check_cause:                                    '@0.5 secs
    Context Save            
                    T1CON   = 110000    'Stop Timer
                    Clear PIR1.0          'Timer1 overflow interrupt flag            
    'it will count from 3035 to FFFF. time required per count = (8/1000000)sec.
    'Total countdown period is (65535-3035)X8/1000000 = 0.5 sec
                    timer1=3035
                                      
    'LCD periodic reinitialization routine : Interval = 0.5sec X 10 = 5 sec
                       Inc lcd_updtCount
                    If lcd_updtCount > 10 Then
                        lcd_updtCount = 0
                        lcd_updt = 100  
                        Clear BPF.0 
                        Clear trip_led                                 'Clear LED
                       ' DelayMS   100
                    EndIf
                T1CON   = 110001         'Start Timer
                                    
    Context Restore 
    'Int_Sub_End----------- 
    '*************End of Interrupt Subroutine****************************************
    '********************************************************************************            
      
    main:   
      
    '******Initialization*************************************************************  
    '**********Set Port I/O mode******************************************************  
              Clear                       'reset all the RAMs of the PIC mocrocontroller.
              TRISA=111111              '1-Input , 0-Output
              TRISB=011111
              TRISC=000000
              ANSEL=011111             'ANSEL CLR for digital I/O , PORTA.0 in Analog Input 
              ANSELH=001111
    '***********Set Analog to Digital converter on Porta.0**********************
              ADCON0=000001  'ADON-1..Enable ADC, CHS 0,1,2,3,4 = 0 - To read A To D On channel A0, 
              ADCON1=000000  'ADFM=1 - Rt Justified result, AtoD conversion clock is dedicated 500KHz oscillator,ADNREF=0-Vref'-'=Vss,ADPREF=00 for Vref'+'=Vdd         
    '**********Setting Timer1 Interrupt******************************************
              timer1=3035          '                
              T1CON   = 110001          
    ;load T1CON to start timer, T1CKPS1:T1CKPS0:=11 for TMR1 precaler 1:8,
    ;T1OSCEN=0 for low power oscillator OFF, T1SYNC=1 for Do not synchronize external clock input,
    ;TMR1CS1&TMR1CS0=0 for Instruction clock (i.e.FOSC/4), TMR1ON=1&TMR1GE=0 Enables Timer1,  overrun period 1s 0.05 secs 
    '**********Set-up Interrupt***************************************************                                      
              PIR1.0=0                   'Clear Timer1 overflow flag
              PIE1=000001             'unmask TMR1 interrupt, TMR1IE=1 - Enable timer1 overflow int 
              INTCON=000000              'enable timer interrupt GIE=1 - Global Int Enabled, *******************
                                         'PEIE=1 - Timer1 interrupt enabled
               Cls                        
               Print At 1,1,"ULTRATECH ACCL" 
               DelayMS 3000 
    '*************End of Initialization*******************************************
    '*****************************************************************************           
     
               
    '***************************************************************************** 
    '***Upon using microprocessor for 1st time, store initial values in EEPROM****          
    '**********Set EEPROM lock bit in address 11**********************************
            EECON1=000100                'Enable EEPROM write
            varwrd = ERead 11      
              If varwrd = 33 Then 
                GoTo start
              Else
                address = 11
                zeroval = 33 
    'EWrite command takes 10ms per byte. But ERead command is instantaneous.
                EWrite address , [zeroval]  
    '**********************Store Initial span current in EEPROM adress 4-5,8-9,10-11 as 10 Amps*******
    '********Store 1023 as initial corrosponding to span current in EEPROM adress 2-3,12-13,14-15 ****** 
                 varwrd = 512          
                 address = 2
                 EWrite address , [varwrd]          
                 address = 12
                 EWrite address , [varwrd]         
                 address = 14
                 EWrite address , [varwrd] 
                 varwrd = 10
                 address = 4 
                 EWrite address , [varwrd]
                 address = 8 
                 EWrite address , [varwrd]
                 address = 10 
                 EWrite address , [varwrd]
                EndIf     
                EECON1=000000                'Disable EEPROM write
    '************End of storing EEPROM initial values********************************            
    '********************************************************************************
    start:       
    Do
        
        'Toggle trip_led                                 'toggle LED **********************************          
        spanvalr = ERead 2   'analog hex data corresponding to set span value of current*********************
        spanr = ERead 4      'set span current X 10
        adval = ADIn 9
        flt = ( adval / spanvalr ) * spanr
        loadcurr_r = loadcurr_r * 0.3
        loadcurr_r = loadcurr_r + ( flt * 0.7 )
        spanvaly = ERead 12   'analog hex data corresponding to set span value of current***********************
        spany = ERead 8      'set span current X 10
        adval = ADIn 10
        flt = ( adval / spanvaly ) * spany
        loadcurr_y = loadcurr_y * 0.3
        loadcurr_y = loadcurr_y + ( flt * 0.7 )
        spanvalb = ERead 14   'analog hex data corresponding to set span value of current*************************
        spanb = ERead 10      'set span current X 10
        adval = ADIn 11
        flt = ( adval / spanvalb ) * spanb
        loadcurr_b = loadcurr_b * 0.3
        loadcurr_b = loadcurr_b + ( flt * 0.7 )
        
                   
                   adval = ADIn 3   ' R-Phase
                   flt = (adval * 1000) / (1023 * 2.5)
                   fltr = fltr * 0.3
                   fltr = fltr + ( flt * 0.7 )
                   Rvolt = fltr 
           
                   adval = ADIn 4   ' Y-Phase
                   flt = (adval * 1000) / (1023 * 2.5)
                   flty = flty * 0.3
                   flty = flty + ( flt * 0.7 )
                   Yvolt = flty
         
                   adval = ADIn 8   ' B-Phase
                   flt = (adval * 1000) / (1023 * 2.5)
                   fltb = fltb * 0.3
                   fltb = fltb + ( flt * 0.7 )
                   Bvolt = fltb
                   
                   Select lcd_updt
                   Case 100
                        Clear lcd_updt
                        Set trip_led                                 'Set LED 
                        Cls           
                        Print At 1,1,"M   " , Dec0 loadcurr_r  ,"-", Dec0 loadcurr_y,"-", Dec0 loadcurr_b," A  "
                        Print At 2,1,"R",Dec0 Rvolt," Y",Dec0 Yvolt," B",Dec0 Bvolt," V"
                   EndSelect
    Loop
    Shantanu

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,588
    Thumbs Up
    Received: 339
    Given: 161
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: Can somebody help?

    Try resetting the Timer1 interrupt flag after the code has finished within the interrupt handler
    Last edited by top204; 21st March 2020 at 11:42.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    192
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Can somebody help?

    I'd suggest to avoid routine calls in ISR. Rather put a flag and the main loop will take care to absolve the routine as soon as time is available.

    So as you want to refresh your LCD, just flag the occurrence and in main loop there might be a flag check, a flag clearance and performing the wanted routine. This way won't affect other ISR urgency, which are not stopped by a routine call.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Prolific Poster shantanu@india's Avatar
    Join Date
    Feb 2007
    Posts
    1,705
    Thumbs Up
    Received: 7
    Given: 21
    Total Downloaded
    827.23 MB

    0 Not allowed!

    Default Re: Can somebody help?

    Sorry for posting late.....thanks for the two responses.
    The problem lay in using the Optimizer with a 16F device.......it is not recommended!!
    Without Optimizer it compiles to a perfectly executable code.
    Shantanu

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts