BasicMicro - Forums

www.basicmicro.com
It is currently Sat Feb 04, 2012 6:02 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: interrupt-on-change syntax ain't there
PostPosted: Mon Oct 26, 2009 4:16 pm 
Offline
Citizen

Joined: Sat Oct 17, 2009 1:49 pm
Posts: 19
Me again. No syntax in the manual for using the interrupt-on-change. According to the PIC manual, BTW, these are available on P4-P7 and NOT on P0,1,2,3 although P0 is the external interrupt. The Nano28 says all of B port may be used this way.

The following fails:
oninterrupt rbint, xint where xint is the place to go.
enable rbint

Gives a compile error
"symbol not pereviously defined [_INTSTATEH]"

There is simply no info in the manual for this interrupt (or many of the others either), and not a clue as to where the pin number has to go (P4 for example). There's no info as to how to set the direction of the change, either, except for the external (P0) interrupt.

I'm pretty tired of trying to use this manual for anything that the chip might be truly useful for. I can run a damn LED with a simple switch. A pointer to the PIC data sheet is fine for function, but does not tell me anything about what's in the compiler! I have now invested some bucks and a lot of time in this chip trying to use crippled documentation.
Maybe Basic Micro ought to get it together...
Don the Disgruntled


Top
 Profile  
 
 Post subject: Re: interrupt-on-change syntax ain't there
PostPosted: Mon Oct 26, 2009 5:40 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Yep, that's Basic Migraine for yuh.
I typed this code into my Studio _14:
Code:
oninterrupt rbint, xint
enable rbint
   ; insert code body here

disable  ; kills all interrupts
xint  ; label for interrupt handler
    ;insert handler code here
resume  ; return to spot where interrupt happened in main code

And this compiled fine. Are you using Studio 1.0.0.14? If not, get it. It's in the Download Section. If so, check your syntax and spelling again. If all that fails to rectify things, delete Studio and reinstall it.

The Nano is based on the PIC16F886. The manual was originally for the PIC16F876. There is a world of difference, which I am not going into here. Go here for the data sheet and check out page 223 in the PDF for the particulars:
http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf
The new processor allows you to do this on-change interrupt on any PortB pin, B0 - B7, which is the Nano's P0 - P7. I can only think using RBINT as done with Studio now looks at all 8 pins at once, but I haven't used it in Studio, so can't say for sure. This is great if you're dedicating PortB to keypad or switch work only. When you do the RESUME at the end of the interrupt handler, the entire register holding these bits is reset. So, you'll have to check each bit of interest in that register, or save the entire register for later investigation, before using the RESUME.

Once you get this to compile OK, come back and tell me exactly what you want to do with these interrupts. I'll contact the programmer and see if he can supply a code example for your particular project.
Later!

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: interrupt-on-change syntax ain't there
PostPosted: Tue Oct 27, 2009 11:07 am 
Offline
Citizen

Joined: Sat Oct 17, 2009 1:49 pm
Posts: 19
Hi again Ken:
My code compiled OK with the .14 studio. I had .10 going. Look and feel changed...
The data sheets show quite a difference as you say! I'll have to look at the whole byte, I'm afraid; the diagram showing the internal logic to generate the interrupt is quite clear.
I have a couple of q's now, what's the compiler command to set the change direction?
Does the compiler interrupt routine include a status and register save?
Will setting some portb as outputs remove them from the int chain? If so do I have to reset directions after a read and parse associated with an interrupt?

The interrupts are needed for two processes; reading two optical encoders, and an unconditional stop of running pwm's, this last will be on the ext interrupt, rb0, but that does not seem right with the 886 chip (boy is there a difference!).

The nano is intended as an rs232 low level controller for my 16 foot radiotelescope, and if I can get it to work on mine, for a 76 foot dish in Ontario, Canada (see sbrac.org). My dish uses 1/2 horse motors on each axis, and the big one has 5 horse motors. In both cases, I don't want to horse around (could not resist) even though there are hardwired limit switches. The interrupts are needed to read the shaft angle encoders, which are not absolute because of cost. I can't afford to miss any counts, hence the interrupts. Reading one ch of a quadrature encoder and sensing the value of the other will suffice, as the movement is slow. But the implementation has to be rock solid, especially in the case of the bigger dish. It's as important as not crashing your CNC mill into the work!
OTH, we're on the usual amateur shoestring, what else is new?
Appreciate your comments!

BTW, been looking at the Atmel implementations on Arduino. There are 3 ints available there.
I also have the option of an rs232 encoder reader, the Ek altaz.
Don


Top
 Profile  
 
 Post subject: Re: interrupt-on-change syntax ain't there
PostPosted: Thu Oct 29, 2009 12:12 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
I contacted the programmer about your questions. His response:
Quote:
We need to know how many pulses per second he expects to get from the encoders. Anything over 100 is probably too many for basic interrupts. In that case he needs to use the israsm{} block and write an assembly interrupt handler. He needs to enable the on change interrupts for the pins he will be using by setting the appropriate register bits(see the 886 datasheet). He will also need to enable the GIE bit and probably the PEIE bit in INTCON. He will not be using the oninterrupt command to the enable or disable commands. Those are only for basic interrupts. His israsm code needs to clear the onchange interrupt flag and then process the pin states. I suggest he only enable the onchange on one of the two encoder I/Os. Then when the interrupt triggers he checks the state of the second pin to determine if he is moving forwards or backwards. Note that the israsm handles entry and exit from the interrupt. All he has to do is clear his interrupt flag(s) and then processes his inputs. No retfie is required.

A "Basic Interrupt" is where the compiler inserts code between commands to check and see if an interrupt happened while it was away handling a token. You can now insert small chunks of assembler code in the usual BASIC commands to get past this limitation and handle chores up to 30 times faster. "israsm" means Interrupt Service Routine ASM (assembly), which implements the damn-fast inline assembly code specifically to handle interrupts. The nutty part is, the ISRASM part has yet to be properly explained anywhere here or in documentation. This is where you go to lynxmotion.com's forum section for Atom/Pro and do a search on ISRASM, where IIRC there is quite a bit on this. I leave the rest of the gobble-de-gook to you to figure out.
Have a nice project. Later.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: interrupt-on-change syntax ain't there
PostPosted: Mon Feb 08, 2010 1:17 pm 
Offline
Citizen

Joined: Mon Feb 01, 2010 9:40 pm
Posts: 43
Quote:
The new processor allows you to do this on-change interrupt on any PortB pin, B0 - B7, which is the Nano's P0 - P7.

Speaking of which, is there any (non|semi)?-official description of the mapping between PIC16F886 pins and Nano pins? How do you know that P0-7 are actually port B?


Top
 Profile  
 
 Post subject: Re: interrupt-on-change syntax ain't there
PostPosted: Mon Feb 08, 2010 3:24 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Hello Rita. To do mapping you:
1. Download the data sheet from BMicro for the Nano in question.
2. Download the data sheet from Microchip for the PIC in question.
3. You make a map based on what BMicro says is a P# based on pin position versus MChip's register callout for each pin.
To do this you need to know which PIC is used for which Nano:
Nano18 is PIC16F88
Nano28 is PIC16F886
Nano40 is PIC16F887

Here are the pinouts according to MChip:
Attachment:
16F88.JPG
16F88.JPG [ 30.86 KiB | Viewed 2678 times ]
Attachment:
16F886.JPG
16F886.JPG [ 50.36 KiB | Viewed 2678 times ]
Attachment:
16F887.JPG
16F887.JPG [ 67.97 KiB | Viewed 2678 times ]

This is all you need to make your own maps and determine which functions/features are available.
So now you know P0, AKA RB0, is pin 6 of the Nano18, pin21 of the Nano28, and pin 33 of the Nano40.
Take care.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO