PDA

View Full Version : Strange Behaviour - Simple code+DT_INT+16F676



financecatalyst
- 14th February 2010, 20:07
Hi, I am facing unexpected behaviour from my PIC.
I am trying to run a simple code for accepting serial data & checking the state of input pins in between using DT_Interrupts. I have tried to debug by blinking some leds on PICKit only but result is dissapointing again and again. Please help...
I have attached the code here:



@ __Config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN & _CP & _CPD

pin13 VAR PortA.0
pin12 VAR PortA.1
pin11 VAR PortA.2
'pin4 VAR PortA.3
pin3 VAR PortA.4
pin2 VAR PortA.5
pin10 VAR PortC.0
pin9 VAR PortC.1
pin8 VAR PortC.2
pin7 VAR PortC.3
pin6 VAR PortC.4
pin5 VAR PortC.5

'----------Variables declared here----------------
code VAR byte

Include "modedefs.bas"
INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
'----------Processor Initialisation---------------
PAUSE 50
TRISA = %111111
TRISC = 0
PORTC = 0
CMCON = 7
ANSEL = 0
OPTION_REG.7=0
WPUA=%110111

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _CHECK, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON=$31

BB:
@ INT_ENABLE TMR1_INT

'--------------Main Program starts here-----------
start:

Serin PORTA.3,N2400,["o9"],code
@ INT_DISABLE TMR1_INT
pause 500
if code=42 then pin5=1
if code=44 then pin6=1 '.........and so on for portc

goto BB

CHECK:
toggle portc.0
toggle portc.1
if pin2=0 then pin5=0
while pin2=0
wend
if pin3=0 then pin6=0
while pin3=0
wend
if pin13=0 then PORTC=0
while pin13=0
wend
@ INT_RETURN

The leds at portc.0 & 1 should toggle at regular interval. BUT they show random behaviour, sometimes steady on, then off, then just 1 is on and so on.
when I remove especially this statement 'if pin13=0 then PORTC=0
while pin13=0
wend', chances are good that LEDs will behave normal.
My DT_INTS-14.bas looks like this:




wsave var byte $20 SYSTEM ' location for W if in bank0
;wsave var byte $70 SYSTEM ' alternate save location for W
' if using $70, comment out wsave1-3
'
' --- IF any of these three lines cause an error ?? ----------------------------
' Comment them out to fix the problem ----
' -- It depends on which Chip you are using, as to which variables are needed --
;wsave1 var byte $A0 SYSTEM ' location for W if in bank1
;wsave2 var byte $120 SYSTEM ' location for W if in bank2
;wsave3 var byte $1A0 SYSTEM ' location for W if in bank3

I assume because of this problem only, the serin command is not acting as well when it receives the data.
Can someone please advise me what am I doing wrong here...?Thanks
__________________
___________________
WHY things get boring when they work just fine?

Darrel Taylor
- 15th February 2010, 18:05
What else did you comment out?
Since it won't fit in a 16F676 as is.
<br>

financecatalyst
- 15th February 2010, 18:19
What else did you comment out?
Since it won't fit in a 16F676 as is.
<br>

I also commented in ReEnter...
T3_SAVE
T4_SAVE

I didn't comment out anything else as far as I can remember. I am new to your interrupts, I attach my ReEnter & DT-14 with this reply so you can have an better idea of where I am going wrong. Thanks a lot for the help.

If you can please also advise me of what more I can comment out to have more space for writing code in ISR.

Darrel Taylor
- 15th February 2010, 19:01
Well ....

For a 16F676, you should add ...
DEFINE OSCCAL_1K 1
Assuming the chip still has it's calibration value.

Other than that, I see nothing wrong. Except what you're doing.
Here's what it does in the simulator.

<object id='stUkhdQ01IR19ZQlhVXFxaVVFR' width='425' height='344' type='application/x-shockwave-flash' data='http://www.screentoaster.com/swf/STPlayer.swf' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0'><param name='movie' value='http://www.screentoaster.com/swf/STPlayer.swf'/><param name='allowFullScreen' value='true'/><param name='allowScriptAccess' value='always'/><param name='flashvars' value='video=stUkhdQ01IR19ZQlhVXFxaVVFR'/></object>

I have seen the PICkit2 intermittently interfere with my 44-pin demo board. (complete randomness).
Disconnecting the PICkit helped.
<br>

financecatalyst
- 15th February 2010, 19:31
Thanks for the help.

Interesting software, is this simulation software available to buy anywhere?

You mentioned


DEFINE OSCCAL_1K 1
Assuming the chip still has it's calibration value


I use MPLAB wit PBP, could you advise me what settings are required in the software(MPLAB) so it does not delete this value in the PIC please or guide me to any article explaining such detail. Thanks

Darrel Taylor
- 15th February 2010, 20:27
The simulator is Proteus.
http://www.labcenter.co.uk/index.cfm

And whether it keeps the calibration intact or not depends on the Programmer.
PBP, MCS or MPLAB cannot control that.

Both the PICkit and meLabs programmers will retain the OSCCAL values, but it does it by re-writing the value after erasing.
If a program cycle fails after erasing, the value can still be lost.

The PICkit software allows you to recreate an OSCCAL value if lost.
(I've never tried it though)
<br>

financecatalyst
- 16th February 2010, 13:19
Hello Darrel, I tried adding "DEFINE OSCCAL_1K 1" once above the @_Config....statement and once below it, both cases my PIC went dead. Is it that any other statement goes along with this?

financecatalyst
- 16th February 2010, 18:23
I tried whole day today to make this code work via my PC but unfortunately it didn't worked. The serin command is not working at all. I tried using MAX232 and sent data via PC after setting correct baud rate and other settings, but no results at all.

:) The interrupt and whatever is in ISR, is working fine. Though the weak internal pullup for PortA.0 & 1 didn't worked (I wonder why), but I managed with external pullups for them. :)


Sending o9* via my PC does not put pin5 high. I tried it nearly million times today.
Can oscillator be the culprit?

As explained in the above post, my PIC went dead when I tried using DEFINE OSCCAL_1K 1. So I removed that statement and kept trying but :(

I really need some help to make it work with Serin command.

Darrel Taylor
- 16th February 2010, 19:02
Hello Darrel, I tried adding "DEFINE OSCCAL_1K 1" once above the @_Config....statement and once below it, both cases my PIC went dead. Is it that any other statement goes along with this?

That means the OSCCAL value is gone.
Without the calibration's RETLW, using OSCCAL_1K creates an infinite loop.

And without the calibration, SERIN has a snowball's chance ...

You could try random OSCCAL values, you might get lucky.
Or, stick a crystal or resonator on it, and it should be able to SERIN.
<br>

financecatalyst
- 17th February 2010, 18:13
Hi, I tried it with another PIC with the define statement on top of the code. It worked fine. I can't use external resonator, as I am using those pins.

How do I know which PICs need this DEFINE statement and which don't?
I am trying to serout with 12F635 & serin at 16F676. It is still giving problems, does 635 also needs some kind of calibration? Thanks

Darrel Taylor
- 17th February 2010, 18:53
How do I know which PICs need this DEFINE statement and which don't?
The same way you know about all the other things the chip does ... the Datasheet. (Oscillator section)
Only the really OLD chips need OSCCAL calibration.


I am trying to serout with 12F635 & serin at 16F676. It is still giving problems, does 635 also needs some kind of calibration? Thanks
No, the 635 doesn't need an OSCCAL.
It has a precision multi-speed internal oscillator, and you can select the speed with OSCCON. But it defaults to 4Mhz.
It's factory calibrated, and the calibration can not be erased.

The 635 has a comparator that needs to be turned off though.
CMCON0 = 7
<br>