Do all interrupts goto PC 0x0004 and then i should check for which int occured?
what happens after an interrupt occurs?
where does program execution go?
i am using portB , interrupt on change feature.
although i could poll the int flag , i want to have the program execution goto an ISR after the interrupt.
i am using portB , interrupt on change feature.
although i could poll the int flag , i want to have the program execution goto an ISR after the interrupt.
If you use interrupts it jumps to 0x004, where you have to save registers, check what caused the interrupt, and respond accordingly - not forgetting to restore the registers afterwards!.
It's a question of enabling the interrupts or not, you can enable the 'feature' and NOT enable the interrupt, this requires polling the flag to see if it's been triggered.
You can check timer interrupts in my tutorials (which shows the stages required), and MicroChip have a number of application notes about interrupt on change on portb.
The stack is automatically saved (or more precisely the Program Counter is placed on the stack) and the GIE bit is automatically cleared and both are restored by the retfie. You have to manually save the W, Status, PCLATH and any other registers which are used in the ISR such as FSR.
For detail of how to save the context in interrupts, refer to section 12.11 of the 16F877 datasheet.
thanks all
i've got all applicable sheets in small piles on a large table , i'm not sure how anyone else does it (writes their programs),but it seems to work for me
i noticed this by looking at the register (memory) map, but they talk about in section 14.12
Since the upper 16 bytes of each bank are common in
the PIC16F876A/877A devices, temporary holding registers,
W_TEMP, STATUS_TEMP and PCLATH_TEMP,
should be placed in here. These 16 locations don’t
require banking and therefore, make it easier for context
save and restore.
Yes, the upper 16 bytes are very useful and for this reason the ISR save variables are normally placed there. You can "save" some of this area by only placing W_TEMP (or int_work in my case) in this area, the rest being anywhere in bank 0 (or any other bank).
Here's how,
Code:
interupt movwf int_work; has to be in common area
swapf STATUS,W; move status to W
bcf STATUS,RP0; switch
bcf STATUS,RP1; to bank zero.
movwf int_status; variables can be in non common area now.
movfw PCLATH
movwf int_pclath
clrf PCLATH
movfw FSR
movwf int_fsr
; ISR code
movfw int_pclath
movwf PCLATH
movfw int_fsr
movwf FSR
swapf int_status,W
movwf STATUS
swapf int_work,F
swapf int_work,W
retfie
hmm i did not know movfw = movf
i never tried using w in the movf instruction
say i wanted to service the PORTB int on change interrupt
after an interrupt occurs , say that the interrupt was not the one i was looking for or expecting.
what happens then?
INTCON <0> holds the flag bit RBIF when the interrupt that i am looking for occurs
mixed in with my seemingly fair grasp of what is going on are going to be some really dumb questions so bear with me
how do i test that the int i am looking for just happened?
It's just a 'macro' (or assembler instruction), it actually produces a 'movf xxx, w' line - there are a number of such 'instructions' as part of MPASM.
how do i test that the int i am looking for just happened?
Yes, that's what it's intended for - in the case of the tutorial it isn't really needed, as there's only a single interrupt source - but it's a good idea to include it anyway, and it's a good habit to get in to!.
Nigel
when you put the config word in there on the F877A
I would use the Load Configuration command , then increment up to 0x2007
and load again??
i am not too sure on this point?
or would simply having the pc point to the config 'area' and loading the new config word do ?
2.4.2.1 Load Configuration
After receiving this command, the program counter
(PC) will be set to 2000h. By then applying 16 cycles to
the clock pin, the chip will load 14 bits in a “data word,”
as described above, to be programmed into the configuration
memory. A description of the memory mapping
schemes of the program memory for normal operation
and configuration mode operation is shown in
Figure 2-1. After the configuration memory is entered,
the only way to get back to the user program memory
is to exit the Program/Verify Test mode by taking MCLR
low (VIL).
question
in the segment of code below right after MOVWF CCPR1L , i put movwf PORTD , and blinked some leds, lots of fun
but when i used PORTB it didnt work , why??
not only did it not work , the pwm stopped
what am i missing
Could it be that one of the port B pins is shorted somehow and therefore causing a brown out. Have you tried inserting a clrf PORTB (and movlw 0xff movwf PORTB) before the loop.
Could it be that one of the port B pins is shorted somehow and therefore causing a brown out. Have you tried inserting a clrf PORTB (and movlw 0xff movwf PORTB) before the loop.
could the LVP on RB3 somehow be messing it up?
i'm about to try turning it off.
this is what i put in the config "3F3A"
LVP- off
BOR- off
PWRTEN-off
WDT-off
HS osc
wow i believe i did it, i followed the flow chart
the WDT blips are gone from the pwm output
this brings up a question...
there must be a way to trap the WDT event from causing blips in the pwm output?
Thanks !!
since you are interrested in Renewable Energy ie the F&P alternator/motor,
i'm making a windmill control , using the F877A
it will measure
current comming from the alt.
battery voltage 12-24 or 48 Volts
windmill RPM
wind speed , all using sensors available to anyone.
Log the data for later analysis(sp) using a laptop
and maybe control the alt output by using pwm in a boost converter setup , if winds are low.
if winds are average , the alt will charge the battery directly
if winds are strong switch to a step down PWM setup
if batteries are fully charged then divert power to another application.