CWrite and ISR


+ Reply to Thread
Results 1 to 4 of 4

Thread: CWrite and ISR52 days old

  1. #1
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,529
    Thumbs Up
    Received: 75
    Given: 33
    Total Downloaded
    6.56 GB

    0 Not allowed!

    Default CWrite and ISR

    I am struggling to make work CWrite and Interrupt together.

    If I comment out: -

    Code:
    On_Interrupt Isr            ' Where to go on an Interrupt
    flash data is being written, but if I uncomment it flash data using CWrite is not being written.

    As per the data sheet, I am disabling interrupts before a write, however, this is not helping.

    What am I doing wrong please.

    Code:
    Device = 12F1572
    
    Xtal = 4
    
    OSCCON = %01101010
    
    '==================================================================================================
    '*********************
    '* Declare variables *
    '*********************
    
    Dim Array[16] As Word Heap = 0' Create a 16 Word array
    
    Dim Hz      As Byte = 0     ' Variable used to hold Hz counter in ISR
    
    '==================================================================================================
    '*************************************
    '* Declare various compiler commands *
    '*************************************
    '>>>Declares<<<
    
    Declare Optimiser_Level = 0 
    
    '==================================================================================================
    '*****************************************
    ' Set Input / Output ports and registers *
    '*****************************************
    '>>>Analog, comparators etc..<<<
    
    CM1CON0 = %00000000     ' Turn OFF comparators
    
    WPUA    = %00000000     ' Turn OFF weak pull-up
    ODCONA  = %00000000     ' PORT pin operates as standard push-pull drive
    
    ADCON0  = %00000000     ' Disable analog on startup and select analog pins
    ADCON1  = %10110011     ' Select FRC and right justify analog result
    ADCON2  = %00000000     ' 
    
    ANSELA  = %00000000     ' Set analog / digital ports
    
    TRISA   = %00100000     ' Configure PORTA I/O
    
    INLVLA  = %00000000     ' TTL inputs is used for PORT reads and Interrupt-On-Change
    
    IOCAP   = %00000000     ' Interrupt-On-Change is disabled; Positive edge trigger
    IOCAN   = %00000000     ' Interrupt-On-Change is disables; Negative edge trigger
    
    '==================================================================================================
    '******************
    ' DECLARE SYMBOLS *
    '******************
    '>>>Symbols and aliases<<<
    
    
    Symbol IOCIF = INTCON.0     ' Interrupt-On-Change flag bit
    Symbol INTF  = INTCON.1     ' External Interrupt flag bit
    Symbol T0IF  = INTCON.2     ' TMR0 Overflow Interrupt flag bit
    Symbol IOCIE = INTCON.3     ' Interrupt-On_Change enable bit
    Symbol INTE  = INTCON.4     ' External Interrupt enable bit
    Symbol T0IE  = INTCON.5     ' TMR0 Overflow Interrupt Enable
    Symbol PEIE  = INTCON.6     ' Peripheral Interrupt Enabe
    Symbol GIE   = INTCON.7     ' Global Interrupt Enable
    
    INTCON = %00000000          ' INTCON initial set
    
    '--------------------------------------------------------------------------------------------------
    
    Symbol PS0   = OPTION_REG.0 ' Prescaler Rate Select
    Symbol PS1   = OPTION_REG.1 ' Prescaler Rate Select
    Symbol PS2   = OPTION_REG.2 ' Prescaler Rate Select
    Symbol PSA   = OPTION_REG.3 ' Prescaler Assignment
    Symbol T0SE  = OPTION_REG.4 ' TMR0 Source Edge Select bit
    Symbol T0CS  = OPTION_REG.5 ' TMR0 Clock Source Select bit
    Symbol INTEDG = OPTION_REG.6' Interrupt Edge Select bit
    Symbol GPPU  = OPTION_REG.7 ' GPIO Pull-up Enable bit
    
    ' TMR1
    Symbol TMR1ON  = T1CON.0    ' Stop timer 1
    Symbol TMR1CS  = T1CON.1    ' Internal clock (FOSC/4)
    Symbol T1SYNC  = T1CON.2    ' Do not synchronize external clock Input
    Symbol T1OSCEN = T1CON.3    ' LP Oscillator Enable Control Bit
    Symbol T1CKPS0 = T1CON.4    ' 1:1 Prescale value
    Symbol T1CKPS1 = T1CON.5    ' 1:1 Prescale value
    Symbol TMR1GE  = T1CON.6    ' Timer1 Gate Enable bit
    Symbol Unused  = T1CON.7    ' Unimplemented
    
    '--------------------------------------------------------------------------------------------------
    
    On_Interrupt Isr            ' Where to go on an Interrupt
    
    GoTo Over_ISR               ' Jump over ISR
    
    '==================================================================================================  
    '*********************
    '* INTERRUPT ROUTINE *
    '*********************
    '>>>Interrupt routine<<<
    
    Isr:                        ' Interrupt Service Routine
    Context Save                ' Save registers before continue ISR
    TMR0 = 100                  ' Load an offset of 100 for TMR0 for a 100Hz interrupt
    
    Inc Hz                      ' Increase Hz
    
    '--------------------------------------------------------------------------------------------------
    
    If Hz = 100 Then
        Hz = 0
        Toggle LATA.2
    EndIf
    
    Context Restore             ' END OF INTERRUPT ROUTINE
    
    '__________________________________________________________________________________________________
    
    '==================================================================================================
    '**********************************
    '* Over Interrupt Service Routine *
    '**********************************
    '>>>Over ISR<<<
                                       
    'Below is the prescaler setting you chose....
    
    Over_ISR:
    
    While GIE = 1 : GIE = 0 : Wend ' Disable interrupts before setting prescaler
    
    PS0  = 1                    ' \                                                  
    PS1  = 0                    '  \ Set the prescaler rate to 1:64                                                
    PS2  = 1                    '  /                                                
    PSA  = 0                    ' /                                                  
    TMR0 = 100                  ' Load an offset of 100 for TMR0 for a 100Hz interrupt
    
    GPPU = 1                    ' Disable internal pull-up
    T0CS = 0                    ' Set the clock source for internal oscillator
    T0IF = 0                    ' Clear the interrupt flag
    'T0IE = 1                    ' Enable tmr0 interrupt
    PEIE = 1                    ' Enable Peripheral interrupts
    ' GIE  = 1                    ' Enable Global interrupts
    
    DelayMS 250                 ' Stabilize PIC at startup
                        
    GoSub Erase_RAM
    
    DelayMS 250
    
    GIE  = 1                    ' Enable Global interrupts
    LATA = 0
    
    '==================================================================================================
    '*************
    '* Main loop *
    '*************
    '>>>Main routine<<<
    
    Main:                       ' Main label
    
    DelayMS 500
    
    LATA.0 = 1
    
    DelayMS 500
    
    LATA.0 = 0
                              
    GoTo Main                  ' Repeat Main loop
                                     
    '==================================================================================================
    '***********************
    '* Erase to RAM memory *
    '***********************
    
    Erase_RAM:
    
    While GIE = 1 : GIE = 0 : Wend ' Disable interrupts before setting prescaler
    
    CErase $07F0        ' Erase a block of 16 words in flash memory
    
    ' Write the bytes to flash memory
    
    CWrite $07F0,[277,320,330,340,350,360,370,380,338,339,340,341,342,343,344,345] 
    
    Return                  
    
    '==================================================================================================
    '*******************************
    '* Internal Fuse Configuration *
    '*******************************
    '>>>Int. Fuse configuration<<<
    
    '--------------------------------------------------------------------------------------------------
    '**** Added by Fuse Configurator ****
    ' Use the Fuses Tab to change these settings
    
    Declare Reminders Off
    @ CONFIG_REQ = 0 ; Override Compiler's configuration settings
    Asm-
    __Config _Config1, 0x39A4 ;FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & BOREN_OFF & CLKOUTEN_OFF
    __Config _Config2, 0x1CFF ;WRT_OFF & PLLEN_OFF & STVREN_OFF & BORV_LO & LPBOREN_OFF & LVP_OFF
    Endasm-
    Declare Reminders On
    
    '**** End of Fuse Configurator Settings ****
    '--------------------------------------------------------------------------------------------------
    Regards

    Joseph

  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,513
    Thumbs Up
    Received: 318
    Given: 152
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: CWrite and ISR

    The Cwrite and CErase library routines can automatically disable/re-enable the ISR when one is intiated with the On_Hardware_Interrupt directive. Just as I did with the Ewrite and ERead command routines, but if it works without interrupts enabled, disabling the GIE bit of the INTCON SFR will also do the trick because that is what the library routines do. I'll re-check the interrupt checking code in the library routines, but they seem to be OK at first looks.

    Try the new Declare: Declare MemWrite_Int_Control = On, this will auto disable/enable interrupts in the CWrite/CErase library routines. I haven't added this to the manuals yet because it has not been 100% tested.

    The code within the compiler's library routines to do this task is:

    Code:
    if((Global_tInterruptsUsed == true) && (Global_tMemWrite_InterruptControl_Required == true)) // Are interrupts being used in the program and the declare stating it's valid?
    {                                                                       // Yes. So...
        PutMnemonic "    movlb " << (AddressOf("INTCON") >> 7) << endl;     // Point to RAM bank for the INTCON SFR
        PutMnemonic "    movf INTCON,w" << endl;                            // Load the contents of INTCON into WREG
        PutMnemonic "    movwf PP0" << endl;                                // Save it into PP0
        PutMnemonic "    bcf INTCON,7" << endl << endl;                     // Clear the GIE bit to disable interrupts before we carry out the write or erase task
    }
    See how it makes a copy of the GIE bit, then disables the interrupts, but only if interrupts are used and the declare is used in the program. It then restores the interrupt with:

    Code:
    if((Global_tInterruptsUsed == true) && (Global_tMemWrite_InterruptControl_Required == true)) // Are interrupts being used in the program and the declare stating it's valid?
    {                                                                       // Yes. So...
        PutMnemonic "    btfsc PP0,7" << endl;                              // Was bit-7 of INTCON set? i.e. interrupts actually enabled  
        PutMnemonic "    bsf INTCON,7" << endl;                             // Yes. So Set the GIE bit and re-enable interrupts
    }
    The newer PIC micros have a rather stupid mechanism for writing to flash memory, and are not a scratch on what the older devices were. They were so simple to use and it was just like writing to eeprom. I tried some routines in the Isis simulator but they seem to have forgotten that the device is capable of being written, because it simply does not work in the Isis simulator with the 12F1572 device. I even tried the official C library from Microchip in Isis just to make sure it wasn't me who made the mistake, but it still didn't work. I've ordered a sample 12F1572 device and will need to wait for it to arrive before I can do more testing. This illustrates my point that I try to get over to users..... "Never Fully Trust a Simulation", always use a real device when testing code.

    The Isis simulator actually seems to be getting worse at simulating and this is what happens when too many different devices are supported. "Quantity Not Quality" is, sadly, the call of today's markets, as Microchip has proven many times over, as well as, virtually, every other company!!!
    Last edited by top204; 7th February 2020 at 12:26.

  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
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,529
    Thumbs Up
    Received: 75
    Given: 33
    Total Downloaded
    6.56 GB

    0 Not allowed!

    Default Re: CWrite and ISR

    Thanks Les for your reply,

    However, it still not working. As you see from my code I made multiple instances to disable the interrupt before I erase and write to the flash memory.

    However as I said in my first post, commenting out: -

    Code:
    On_Interrupt goto Isr       ' Where to go on an Interrupt
    will write to the flash memory. I tried to see the ASM but is something that I cannot follow, but I can see that interrupts are being turned off.

    Could be nothing to do with interrupts , I see a lot of bank switching but as I said, unable to verify what is going on.

    Waiting for when you receive your devices.

    Thank you
    Regards

    Joseph

  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 joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,529
    Thumbs Up
    Received: 75
    Given: 33
    Total Downloaded
    6.56 GB

    0 Not allowed!

    Default Re: CWrite and ISR

    Les,

    Have you received the samples for the 12F1572 please? Perhaps I get around this problem.
    Regards

    Joseph

  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)

     

Similar Threads

  1. Is Isr EndIsr current?
    By normnet in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 31st March 2018, 17:43
  2. Coming out of an ISR
    By johngb in forum Proton 24
    Replies: 7
    Last Post: 24th November 2017, 07:33
  3. Isr#s and Proc's
    By johngb in forum Proton 24
    Replies: 10
    Last Post: 25th February 2017, 09:41
  4. [SOLVED !] ISR messing up RSIN
    By theguru in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 7th December 2009, 15:37
  5. jumping from ISR to......
    By galaxy in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 11th March 2007, 15:11

Posting Permissions

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