Banksel-out - Page 1
Forum section: electronics / general

author: PerranOak
author_rank: Frequent Contributor
timestamp: June 07, 2018, 01:31:22 pm
content: I am using Timer1 to interrupt the main loop and take a reading.I am wondering how the interrupt deals withbanksel.When an interrupt occurs and runs the interrupt code what if, when the interrupt occurred,bank1was selected but the interrupt uses registers inbank0.If I put abankselin the interrupt routine to make itbank0, how do I know which to select at the end of the interrupt: this time it wasbank1in the main loop when interrupted but next time it may not be.I can't find an answer to such a rambling question on the web or in datasheets(!)Cheers.

author: NorthGuy
author_rank: Super Contributor
timestamp: June 07, 2018, 01:58:18 pm
content: The bank selection is stored in PIC's registers. In older PICs this is usually RP bits in the STATUS register. In newer PICs there's a special BSR register.When you enter the interrupt, you save the corresponding register. Before leaving the interrupt, you restore it.Newer PICs (PIC16F1*, PIC18Fxx42) automatically store this (and other) registers when entering ISR. Therefore interrupts are processed much faster with them.

author: PerranOak
author_rank: Frequent Contributor
timestamp: June 07, 2018, 03:26:57 pm
content: Ah, I see, thank you for your answer.So, as I'm using a 16F1827, I don't have to save any such register and no matter what I do in the interrupt routine the pre-interrupt bank selection will be restored on returning from the interrupt?

author: cv007
author_rank: Frequent Contributor
timestamp: June 07, 2018, 04:15:12 pm
content: datasheet section 8.5 and table 3-4

author: picandmix
author_rank: Frequent Contributor
timestamp: June 07, 2018, 04:17:00 pm
content: Quote from: PerranOak on June 07, 2018, 03:26:57 pmYou need to use your bible more - AKA the Microchip Datasheet !It might seem daunting but you will learn how to extract the bits of info you need, in time

author: PerranOak
author_rank: Frequent Contributor
timestamp: June 07, 2018, 05:29:05 pm
content: Oops!I had read that in the past as well! I sawshadow registersand instantly thought "that's for a future time when I'm better at this" and parked it! What a numpty I am.Thank you for helping.

author: picandmix
author_rank: Frequent Contributor
timestamp: June 07, 2018, 05:54:32 pm
content: We have all been there, though Microchips datasheets are infamous !Don't forget , code in the ISR should be as short a possible so you do not miss other interrupts etc, plus avoid calls and gotos out of the ISR area.Rather than test and do complex work on the result in the ISR, do the test , then set a variable/FLAG according to the test result so it can be acted upon in the main code loop.The earlier 16F chips biggest problems are the small ram banks and program memory pages, some of the newer 16F and all the 18F chips like the 18F1320 have one large program memory area and large ram banks (256 bytes) so a lot easier to use with Assembly code.Which chip, just depends on what programmer you have, some of the newer ones need the Pk3.

author: NorthGuy
author_rank: Super Contributor
timestamp: June 07, 2018, 07:16:50 pm
content: Quote from: PerranOak on June 07, 2018, 05:29:05 pmMay be the time has come when you became "better at this".

author: PerranOak
author_rank: Frequent Contributor
timestamp: June 08, 2018, 10:46:31 am
content: Quote from: picandmix on June 07, 2018, 05:54:32 pmThank you, will do.Northguy: You're not wrong! You and the others on this site are helping me to make that happen, thank you.