PDA

View Full Version : Help with configuring



financecatalyst
- 15th August 2014, 07:54
Hello there. I have written a simple code but it seems not to work properly. I am not sure what I am missing here and any help will be appreciated.

The code is as follows:

#CONFIG
ifdef PM_USED
device pic16F688, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
else
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _CPD_ON & _BOD_ON & _IESO_ON & _FCMEN_ON
endif
#ENDCONFIG
DEFINE OSC 8 ' OSCCON defaults to 8MHz on reset
DEFINE NO_CLRWDT 1
Include "modedefs.bas"

' declare the interrupt handler
define INTHAND _ISR

goto main

ISR:
asm

; my asm code

endasm

main:
PAUSE 50
OSCCON = %01110001 ' Internal Oscillator 8MHz
TRISA = %000100
TRISC = %000010
CMCON0 = 7
ANSEL = 0 ' NO ANALOGS
OPTION_REG = %10000011 ' RAPU = off, PS 1:16 to TMR0
PORTA=0
PORTC=0

' setup iZCD to interrupt on change
' INTCON= %10110000
' | Global interrupts enabled
' | Timer0 interrupt enabled
' | Zero Crossing interrupt enabled
' ---- Flags are cleared
while 1
toggle PortA.4
pause 500
wend



When I comment the INTCON, my led blinks fine @ 500mS. When I uncomment it, the timings go out.
I want to run my PIC16F688 at internal 8MHz and not sure if I am missing any configuration register.

financecatalyst
- 16th August 2014, 07:29
Anyone?????

richard
- 16th August 2014, 09:22
if you enable interrupts and provide no code to service the interrupt and worse still provide no code to reset the interrupt flag what do you expect to happen ?

financecatalyst
- 16th August 2014, 10:24
Here you are:


ISR:
asm
movwf wsave ; Save WREG
swapf STATUS, W
clrf STATUS ; Point to bank 0
movwf ssave ; Save STATUS
movf FSR,w
movwf fsave ; save FSR
movf PCLATH, W ; Save PCLATH
movwf psave


; get ready to jump within the ISR page
movlw ((INTHAND) >> 8) ; Set PCLATH for jump
movwf PCLATH
btfsc INTCON, INTF
goto ZeroCrossingInt

T0Overflow
bcf INTCON, T0IF ; clear the timer overflow flag

goto EndInt

ZeroCrossingInt
bcf INTCON, INTF ; clear the interrupt

EndInt ; restore the machine state and return from interrupts
movf fsave,w
movwf FSR ; restore FSR
movf psave,w
movwf PCLATH ; restore PCH
swapf ssave,w
movwf STATUS ; restore Status
swapf wsave,f
swapf wsave,w ; restore WREG
retfie
endasm

richard
- 16th August 2014, 11:25
I cant see that you have declared wsave ,ssave and psave vars ?

financecatalyst
- 16th August 2014, 11:35
I missed that.



wsave var byte $70 SYSTEM ' safe for W in all banks
ssave var byte BANK0 SYSTEM ' save STATUS
psave var byte BANK0 SYSTEM ' save PCLATH
fsave var byte BANK0 SYSTEM ' save FSR

richard
- 16th August 2014, 11:39
dt ints is easier

financecatalyst
- 16th August 2014, 12:07
I know that. But latency causes problem.

mackrackit
- 17th August 2014, 00:19
I know that. But latency causes problem.
What latency? I have never noticed any with DT's INTS.

Dick Ivers
- 17th August 2014, 01:08
Suggestion: Simplify your job by switching to a 16F1823. Same pinout as your present PIC but with automatic context saving.