K150 - Errors Programming

Status
Not open for further replies.

Tom81

Member
I knew this day would come.

I'm programming a 16F88 PIC and suddenly it comes up with an error (see attached).

I didn't change any settings. I'm using the same pic, same programmer as always. No problems with it till now.

The programmer's a K150 (Kits-R-Us). When I load the software (microburn) it says the board is connected. I try erasing the chip but the programmer can't recognise it as a 16F88...then I try programming the chip and it comes up with errors.

Tried two different chips with the same result... what a bugger.

Clues??

Ta -Tom
 

Attachments

  • Error1.JPG
    73.3 KB · Views: 1,725
Ok I've narrowed the problem down... It's not the programmer (at least I think not).

I grabbed another 16F88 PIC (new). It seemed to erase fine. I then loaded it with a different program. Seemed to load fine too.

So it's occurred to me that my program is killing my PICs! It's basically started happening when I started playing around with the Timer1 function. essentially, the program should turn an LED on, wait until Timer1 overflow interrupt occurs, then turn it off. Think it might be something to do with the T1CON Reg set up... Here's the code:

;**********************************************************************
; This file used as an interrupt example. *
; Uses 4 x LEDS on Port B Pins 1,2,3 & 4. *
; PIC16F88 is used. Uses interrupt on overflow for 16bit Timer1 *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; Internal RC Clock Used. *
; *
;**********************************************************************
; *
; Filename: 16F88_Interrupt_Timer1.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: P16F88.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************


list p=16F88 ; list directive to define processor
#include <p16F88.inc> ; processor specific variable definitions

ERRORLEVEL 0, -302 ;suppress bank selection messages

__CONFIG _CONFIG1, _CP_OFF & _WDT_OFF & _LVP_OFF & _INTRC_IO & _MCLR_OFF
; __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.
; "Copy Protect" and "Watch Dog Timer" has been turned off, "Internal RC Oscilator" enabled.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


; org is the origin - PIC start up begins from here. NOTE: Tabbed once across to remove from column 1
Org 0
goto Start

;Org 4 is where the program goes when interrupt is detected.
Org 4
goto ISR

;*****Set up the Variables****

LED_OUT equ 22h

W_TEMP equ 23h
STATUS_TEMP equ 24h
TMR0_TEMP equ 25h
PORTB_TEMP equ 26h


Start
;****Set up the port****
bsf STATUS,5 ;Switch to Bank 1

;THESE THREE INSTRUCTIONS ARE USED TO SET CLOCK TO 31.25kHZ SETTING (INTERNAL)
;POSSIBLY UNNECESSARY? SINCE THE INTRC IS SET AT 31.25kHz anyway.
bcf OSCCON,6
bcf OSCCON,5
bcf OSCCON,4

;This is to make sure that RA2 & RA3 can be used as Digital outputs.
CLRF ANSEL

clrf TRISB ;Port B to outputs by setting to "ZERO".
clrf TRISA ;Port A to outputs.

;bsf TRISB,0 ;Set Port B pin 0 to an input (external interrupt)

; bsf OPTION_REG,6 ;Set INTEDG for rising edge interrupt on RB0

bcf STATUS,5 ;Switch back to Bank 0

;Clear the Ports
clrf PORTA
clrf PORTB

;interrupts set up for Timer1 overflow
bsf INTCON,GIE ;Enable Global Interrupt, bit 7
bsf INTCON,PEIE ;Enable Peripheral Interrupts

bsf PIE1,TMR1IE ; Peripheral Interrupt Enable Register. Enable Timer1 interrupt (bit 0).

;Now set up T1CON. This is the Timer1 control register.
;Prescaler is 1:1. see p.74 of datasheet.
movlw b'01001001'
movwf T1CON

;Set LED_OUT
movlw b'00010000' ; Turn on LED
movwf LED_OUT

;****Start****

Main
movf LED_OUT,0
;clrf PORTB
movwf PORTB
Goto Main

;Reset_LED movlw b'00010000' ; Flashing LED order start
; movwf LED_OUT
; return

;Interrupt Service Routine

ISR
movwf W_TEMP ;Save W
swapf STATUS,W
movwf STATUS_TEMP ;Save STATUS
;movf TMR0,W
;movwf TMR0_TEMP ;Save TMR0
;movf PORTB,W
;movwf PORTB_TEMP ;Save PORTB

;Routine Goes here...Hofefully TURN LED OFF!

Loop clrf PORTB
goto Loop

;Restore all values...
swapf STATUS_TEMP,W
movwf STATUS
;movf TMR0_TEMP,W
;movwf TMR0
;movf PORTB_TEMP,W
;movwf PORTB
movf W_TEMP,W

;Reset Interrupt..
bcf PIR1,TMR1IF ;Reset Timer1 Overflow Interrupt Flag

;..and Return
retfie

End
 

Attachments

  • Error2.JPG
    76.3 KB · Views: 683
Hi Tom,
Just a quick guess, but I think the trouble is that you have
_INTRC_IO & _MCLR_OFF
programmed it to not use master clear, with an internal oscillator.

Try a bulk erase on the chip first - before trying to program it.
 
Hi BeeBop, I've programmed these chips before with both internal osc. and MCLR off. So far I've never had any dramas using both functions. It's only when I've started playing with the Timer1 register that I had problems. These functions could be linked though, I'll check the datasheet when I get time...

To erase the problematic chips, I've tried to do a "blank" for each one. That's when the errors come up. How do I do a bulk erase? or is that the same thing? Doesn't look like there's any function for a bulk erase in MicroPro. Unless it's an erase using just hardware?

Thanks -Tom
 
Yeah I'm aware of that. That's intentional. Basically the ISR only gets called on timer1 overflow. So the LED switches on (at the start of the program), waits for overflow (which should be about ~8 seconds), goes to ISR, turns off and does nothing (loops). Would an infinite loop have this kind of effect on the programmer/chip?? I've not used Timer1 overflow interrupts before. It's just a simple testing program.

Cheers -Tom
 
Don't use an infinite loop in the ISR. Change the port pin, or set another one on, anything but...

Never tried setting OSCON to 32khz before, I think Pics come set at 1Mhz from the factory, but don't quote me on that. If you can sucessfully erase the chip, then try a different clock rate and see if that makes the difference.

Of the many Pics that I have programmed, the 16f88 was the only one that has hung up. If you have a Pickit2, you might try ticking the "Use VPP first program entry", otherwise, do a search on this.

The effect you are trying to make could easily be done with the watch dog timer and sleep. I.E. run at faster clock and spend more time in sleep. Increment a counter each wdt period and put back to sleep, for x number of times , then branch to execute code.
 
I've used the OSCON settings before in other programs, again without any problems. I'm not even sure if those three instructions are reallly necessary; I think once you set config to internal clock, the 31.25kHz is default anyway.

I use PICs mostly just for basic rough timing sequences, so most of the time I don't have a need for an external clock. I use the 88's for a few reasons. I haven't used many other PIC's but the 88's seem to have a wide range of functions available, particularly since you can use all the pins as I/O (except +/- of course) and the analogue inputs are useful. plus there's the EPROM memory. I know there's other PIC's out there which are probably cheaper that can do just as much, but I'm happy with the 88's so far and I'm becoming more farmiliar with them.

What exactly do you mean by "hung up"? Have you had problems like this before?

I wrote the program really just to familiarise myself with Timer1 and interrupts. It serves no other purpose other than curiosity

Thanks for the constructive advise - always welcome. -Tom
 
Found the culprit. It was the T1CON Resgister set up:
movlw b'01001001'
movwf T1CON
This made the PIC try and run off Timer1 Oscillator, even though it was set to IntRC osc. bad bad bad. Instead set bit "0" in the T1CON Reg (see code).

Here's the updated code. Although I still can't get the interrupt to work. I've simplified it to make it easier to read and got rid of some irrelevant sections:

;**********************************************************************
; This file used as an Timer1 interrupt example. *
; Uses 1 x LED on Port B Pin 4. *
; PIC16F88 is used. Uses interrupt on overflow for 16bit Timer1 *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; Internal RC Clock Used. *
; *
;**********************************************************************
; *
; Filename: 16F88_Interrupt_Timer1.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: P16F88.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************


list p=16F88 ; list directive to define processor
#include <p16F88.inc> ; processor specific variable definitions

ERRORLEVEL 0, -302 ;suppress bank selection messages

__CONFIG _CONFIG1, _CP_OFF & _WDT_OFF & _LVP_OFF & _INTRC_IO & _MCLR_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.
; "Copy Protect" and "Watch Dog Timer" has been turned off, "Internal RC Oscilator" enabled.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


; org is the origin - PIC start up begins from here. NOTE: Tabbed once across to remove from column 1
Org 0
goto Start

;Org 4 is where the program goes when interrupt is detected.
Org 4
goto ISR

;*****Set up the Variables****

W_TEMP equ 23h
STATUS_TEMP equ 24h
TMR0_TEMP equ 25h
PORTB_TEMP equ 26h


Start
;****Set up the port****
bsf STATUS,5 ;Switch to Bank 1

;THESE THREE INSTRUCTIONS ARE USED TO SET CLOCK TO 31.25kHZ SETTING (INTERNAL)
;POSSIBLY UNNECESSARY? SINCE THE INTRC IS SET AT 31.25kHz anyway.
bcf OSCCON,6
bcf OSCCON,5
bcf OSCCON,4

;This is to make sure that RA2 & RA3 can be used as Digital outputs.
CLRF ANSEL

clrf TRISB ;Port B to outputs by setting to "ZERO".
clrf TRISA ;Port A to outputs.

bcf STATUS,5 ;Switch back to Bank 0

;Clear the Ports
clrf PORTA
clrf PORTB

;Now set up T1CON. This is the Timer1 control register.
;Prescaler is 1:1. see p.74 of datasheet.
bsf T1CON,TMR1ON ;Turn the Timer1 on.

;interrupts set up for Timer1 overflow
bsf INTCON,GIE ;Enable Global Interrupt, bit 7
bsf INTCON,PEIE ;Enable Peripheral Interrupts

;Enable Timer1 Overflow Interrupt
bsf PIE1,TMR1IE ; Peripheral Interrupt Enable Register. Enable Timer1 interrupt (bit 0).

;Reset Interrupt flag..
bcf PIR1,TMR1IF ;Reset Timer1 Overflow Interrupt Flag

;Set LED_OUT
bsf PORTB,4 ; Turn on LED

;****Start****

Main
bsf PORTB,4 ; Turn on LED

Goto Main

;Interrupt Service Routine

ISR
movwf W_TEMP ;Save W
swapf STATUS,W
movwf STATUS_TEMP ;Save STATUS
;movf TMR0,W
;movwf TMR0_TEMP ;Save TMR0
;movf PORTB,W
;movwf PORTB_TEMP ;Save PORTB

;Routine Goes here...Hofefully TURN LED OFF!

Loop nop
bcf PORTB,4
goto Loop

;Restore all values...
swapf STATUS_TEMP,W
movwf STATUS
;movf TMR0_TEMP,W
;movwf TMR0
;movf PORTB_TEMP,W
;movwf PORTB
movf W_TEMP,W

;Reset Interrupt..
bcf PIR1,TMR1IF ;Reset Timer1 Overflow Interrupt Flag

;..and Return
retfie

End
 
I think I had to erase the chip and fiddle with the config and programmer settings to get the chip to reprogram. Somehow backed the OSC into a goofy situation, I forget already. There are some errata sheets talking about certain problems, they may apply? Nothing the matter with the 'f88, lots of features like you say.

Ooops.... see that you are half way home to fixing your problem.
 
Cheers, yes half way home. Still having problems with the code. It definitely runs - I've tested it on MPLAB simulator and on a prototype/breadboard - but in both instances it never actually gets to the ISR. very annoying. The Timer1 is definitely counting, and the overflow occurs (I've monitored the overflow flag and it goes high at Timer1 rollover from FFFF to 0000). The interrupt itself isn't working though... DOH!
 
Don't do assembler, but numerous banksel's missing like ANSEL, TRISB etc. Also save PCLATH in ISR. Never hurts to turn off the compare mode in CMCON register either, if not being used. It will then work.
 
G'day nickelflippr, thanks again for the advise. I found the problem... I'd been setting Enable Interrupt Overflow Timer1 in bank 0, not bank 1. I am a goose! All working now.

Cheers -Tom
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…