Author Topic: Banksel-out  (Read 1521 times)

0 Members and 1 Guest are viewing this topic.

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Banksel-out
« on: June 07, 2018, 01:31:22 pm »
I am using Timer1 to interrupt the main loop and take a reading.

I am wondering how the interrupt deals with banksel.

When an interrupt occurs and runs the interrupt code what if, when the interrupt occurred, bank1 was selected but the interrupt uses registers in bank0.

If I put a banksel in the interrupt routine to make it bank0, how do I know which to select at the end of the interrupt: this time it was bank1 in 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.
You can release yourself but the only way to go is down!
RJD
 

Online NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: Banksel-out
« Reply #1 on: June 07, 2018, 01:58:18 pm »
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.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Banksel-out
« Reply #2 on: June 07, 2018, 03:26:57 pm »
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?

You can release yourself but the only way to go is down!
RJD
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 825
Re: Banksel-out
« Reply #3 on: June 07, 2018, 04:15:12 pm »
datasheet section 8.5 and table 3-4
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: Banksel-out
« Reply #4 on: June 07, 2018, 04:17:00 pm »
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?


You need to use your bible more   - AKA the Microchip Datasheet !   :-DD

It might seem daunting but you will learn how to extract the bits of info you need, in time



 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Banksel-out
« Reply #5 on: June 07, 2018, 05:29:05 pm »
Oops! :-[

I had read that in the past as well! I saw shadow registers and 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.
You can release yourself but the only way to go is down!
RJD
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: Banksel-out
« Reply #6 on: June 07, 2018, 05:54:32 pm »
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.
« Last Edit: June 07, 2018, 06:04:09 pm by picandmix »
 

Online NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: Banksel-out
« Reply #7 on: June 07, 2018, 07:16:50 pm »
I had read that in the past as well! I saw shadow registers and instantly thought "that's for a future time when I'm better at this" and parked it! What a numpty I am.

May be the time has come when you became "better at this".
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Banksel-out
« Reply #8 on: June 08, 2018, 10:46:31 am »
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.
Thank you, will do.


Northguy: You're not wrong! You and the others on this site are helping me to make that happen, thank you.
You can release yourself but the only way to go is down!
RJD
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf