PDA

View Full Version : 16f690 crashes



Lincoln S.
- 22nd November 2008, 21:31
been trying to get this program to work again forever. its compiled for a 16f690. at current it is just on a breadboard. it only works for say 5 cycles err.. iterations sp?.. anyways it goes through its program say 5 times before it just up and quits. I know its running through because I test the output pins and it pulses and pauses for the set times and just stops..

the operation is as follows.. main processor receives the word "relay" with serial input command from the slave 12f509 outputing the word "relay"

not currently implemented
main processor sends a command back out to the slave 12f509 to trip the relay..

just trying to get the main code below to work on a 16f690 currently.. this is driving me mad.. I see nothing too wrong with the code to cause it to do this. all the settings are set to no mclr (input only) and intoscio (checked them on the code uploader too)



define osc 4
INCLUDE "modedefs.bas"
@ device PIC16f690, MCLR_OFF
info var byte[10] 'really should be 5 long, but I lengthened it just for the halibut.


info[0] = "t" 'trying to appease the compiler.. not really needed
info[1] = "t"
info[2] = "t"
info[3] = "t"
info[4] = "t"
info[5] = "t"





trisa = %00000000
trisb = %00000000
trisc = %00000000

'trisa.0 = %0 'me trying to manually set tris registers
'trisa.1 = %0
'trisa.2 = %0
'trisa.3 = %0
'trisa.4 = %0
'trisa.5 = %0

'trisb.4 = %0
'trisb.5 = %0
'trisb.6 = %0
'trisb.7 = %0

'trisc.0 = %0
'trisc.1 = %0
'trisc.2 = %0
'trisc.3 = %0
'trisc.4 = %0
'trisc.5 = %0
'trisc.6 = %0
'trisc.7 = %0


'ADCON0 = 0 'fiddling with additional registers trying to get
'ADCON1 = 0 'all outputs set to digital
'ADCON1 = 15

ansel = 0
anselh = 0





poll:

'SEROUT porta.0,N2400,["p"] 'I had set all pins to output data
'SEROUT porta.1,N2400,["p"] 'originally, all pins worked at one
'SEROUT porta.2,N2400,["p"] 'time using this.
'SEROUT porta.3,N2400,["p"]
'SEROUT porta.4,N2400,["p"]
'SEROUT porta.5,N2400,["p"]

'SEROUT portb.4,N2400,["p"]
'SEROUT portb.5,N2400,["p"]
'SEROUT portb.6,N2400,["p"]
'SEROUT portb.7,N2400,["p"]

'SEROUT portc.0,N2400,["p"]
'SEROUT portc.1,N2400,["p"]
'SEROUT portc.2,N2400,["p"]
'SEROUT portc.3,N2400,["p"]
'SEROUT portc.4,N2400,["p"]
'SEROUT portc.5,N2400,["p"]
'SEROUT portc.6,N2400,["p"]
'SEROUT portc.7,N2400,["p"]



pause 100
SERIN portc.5, N2400, 1000, nxt, ["r"], info[0] 'Get input
SERIN portc.5, N2400, info[1] 'get the word "relay"
SERIN portc.5, N2400, info[2]
SERIN portc.5, N2400, info[3]
SERIN portc.5, N2400, info[4]


SEROUT portc.0, N2400, [info[1], info[2], info[3], info[4] ]
'above line: output received data "relay" to computer serial line

pause 500




gosub poll


nxt:
serout portc.4, N2400, ["timeout"]
return

Melanie
- 22nd November 2008, 22:02
You are trying to do a timing-critical function (Serial Comms) on a PICs crappy internal oscillator, and you're wondering why it's not working?

But that (and other horrible things) aside... you should have a GOTO POLL, not a GOSUB POLL. You're filling up your stack and promptly dissapearing destined never to RETURN...

Also... when you have a problem and you jump to NXT (I haven't checked the syntax of your SERIN command btw), it performs a GOTO and NOT a GOSUB... therefore it's NOT a subroutine so the RETURN statement is not valid.

Lincoln S.
- 22nd November 2008, 23:26
ok.. I'll go ahead and clean that up and post it again..

Lincoln S.
- 23rd November 2008, 23:32
heres the new cleaned up version of the old code. I haven't hooked it up to the pc but this one seems to work just great (it pulses the pin selected for output). I did that stuff you were talking about with the goto command. thanks for the help.

as for the xtal, yeah, I'm going to have to condede to that. I was hoping to see if I could just get by without one, but I'm going to probably have to give those pins back to the xtal. I was kinda getting away without needing an xtal due to the fact that nothing else was hooked to it whilst I was testing this code.

I've also been looking for a tutorial on setting all pins on the device to digital. it seems the settings I have do that, but I really don't have a clear understanding off the following ansel, anselh and adcon. I looked in the microchip pdf but it was rather confusing.

thanks for the help with the code.


INCLUDE "modedefs.bas"
define osc 4

@ device PIC16f690, MCLR_OFF

info var byte[5]



trisa = %00000000
trisb = %00000000
trisc = %00000000

ansel = 0
anselh = 0






poll:




pause 100
SERIN portc.5, N2400, 1000, nxt, ["r"], info[0] 'Get input
SERIN portc.5, N2400, info[1] 'get the word "relay"
SERIN portc.5, N2400, info[2]
SERIN portc.5, N2400, info[3]
SERIN portc.5, N2400, info[4]


SEROUT portb.7, N2400, [info[1], info[2], info[3], info[4] ]


pause 500




goto poll


nxt:
serout portb.7, N2400, ["timeout"]
goto poll

mackrackit
- 24th November 2008, 00:58
A tutorial for the analog settings would be great, but this should help some
http://www.picbasic.co.uk/forum/showthread.php?t=561
and here is a way to use the ADC that is a little different than the manual, I still prefer this method.
http://rentron.com/PICX2.htm
Read through the above example, when you understand how it works it should really help you understand the inner workings.
Post your questions.

Lincoln S.
- 25th November 2008, 00:24
hey, my code is working great, but I have been running into some problems with noise. I geuss I should state the problem first. I am trying to get both input and output working on about a 1 foot long straight (four wires untwisted parrallel) serial cable to a PC. it worked ok before when I was just using on line and a ground, but now that I have input and output lines going to the pc, I get noise on the other line everytime I use the serout command from the pic. tried using 10k pulldowns (not being sure about the connection on that I ran 10k from data line to ground and the unused in from the pc as well). that didn't work. then I tried a 10 mf electrolytic on the unused line with neg side going to ground. this worked but it didn't quite seem kosher to be putting a 10mf electrolytic on a line of this sort, especially going to a PC serial line.

is there perhaps a post here with few help hints and some schematics showing how to reduce noise on straight cabling? I been looking for quite some time for some info to glean.

also worth noting, when I ran this pic (16f690).. just on the protoboard with intosc and nothing but power, I got no noise, so it is the parrallel capacitance of those wires doing it. recon I could try some cat5 I have lying around.. would be interested in all things noise reduction however.

I added an xtal btw. specs say +- 1 but in the area of millions of cycles per second, that could be a deal breaker.

thanks for any help. thanks for the help you allready gave me.

mackrackit
- 25th November 2008, 00:47
then I tried a 10 mf electrolytic on the unused line with neg side going to ground. this worked but it didn't quite seem kosher
Capacitors are the best way to reduce noise. I would guess the unused line is acting like an antenna and the cap is suppressing it.

Lincoln S.
- 25th November 2008, 01:18
huh.. I tried that electrolytic 10 mf cap. works fine across unused line from the pic. but I started wondering what it might do to the waveform of the incoming pc. I put it accross the pic out, and it went from high/low pulsing to low pulsing. anotherwords the cap is too high. I recon I'm going to have to pull out the old cap box I salvaged some years back and try some various values. I recon its about time to re-stock on the salvaged caps, the goo inside is prolly starting to dry up on the old ones. man.. I sure hope I don't have to find a scope to do this with, that would be a pain in the rear.

gotta hammer away some more and try to find some solutions. I think I am going to replace the wires with twisted pair cat 5 and see what that does.

Acetronics2
- 26th November 2008, 08:32
Hi, Lincoln

Why do you think ICs creators spend their efforts in creating LINE DRIVERS with as little as possible output impedance ???

Good question ... don't you think ?

Alain