PDA

View Full Version : SEROUT is not working!



jhorsburgh
- 3rd September 2008, 00:24
Hi Guys,
I have another little problem, the code below work perfectly with the exception of the SEROUT Command. For some reason the computer is not receiving the SEROUT information. Can anyone see anything that could cause it not to work? Oscillator maybe?
I have tested the pin and it is pulsing when it should be.

<code>
INCLUDE "modedefs.bas"

CMCON = 7 'comparators off
trisio = %00001000 'GPIO.3 INPUT FROM IR RCVR
GPIO = 0 'ALL OUTPUTS LOW

Define OSC 4
DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device

@ DEVICE PIC12f629, INTRC_OSC
@ DEVICE PIC12f629, WDT_ON
@ DEVICE PIC12f629, PWRT_ON
@ DEVICE PIC12f629, MCLR_OFF
@ DEVICE PIC12f629, BOD_ON
@ DEVICE PIC12f629, CPD_OFF

CODELENGTH VAR BYTE 'BYTE VARIABLE OK - LESS THAN 8 PULSES MEASURED
CODE VAR BYTE 'BYTE VARIABLE OK - LESS THAN 8 CODE BITS
TYPE VAR BYTE

codelength = 0
code = 0
type = 0

Pause 100 'SETTLE DOWN BOTH PIC & IR RECEIVER

STARTPULSE:
PulsIn GPIO.3,0,CODELENGTH 'MEASURE LOW PULSE (IR LED ON TIME)
IF CODELENGTH <200 Then STARTPULSE 'LOOKING FOR 3MS PULSE
IF CODELENGTH >400 Then STARTPULSE

CODEPULSES:
PulsIn GPIO.3,0,CODELENGTH
IF CODELENGTH > 150 Then LET TYPE = 1 '2MS PULSE IS 1
IF CODELENGTH > 250 Then LET TYPE = 2 '3MS PULSE IS 2
IF CODELENGTH > 350 Then LET TYPE = 3 '4MS PULSE IS 3
IF CODELENGTH > 450 Then LET TYPE = 4 '5MS PULSE IS 4
IF CODELENGTH > 550 Then LET TYPE = 5 '6MS PULSE IS 5
IF CODELENGTH > 650 Then LET TYPE = 6 '7MS PULSE IS 6
IF CODELENGTH > 750 Then LET TYPE = 7 '8MS PULSE IS 7
IF CODELENGTH < 150 Then LET TYPE = 0 '1MS PULSE IS 0

PulsIn GPIO.3,0,CODELENGTH
IF CODELENGTH > 150 Then LET CODE.bit0 = 1 '2MS PULSE IS 1
IF CODELENGTH < 150 Then LET CODE.bit0 = 0 '1MS PULSE IS 0

PulsIn GPIO.3,0,CODELENGTH
IF CODELENGTH > 150 Then LET CODE.bit1 = 1
IF CODELENGTH < 150 Then LET CODE.bit1 = 0

PulsIn GPIO.3,0,CODELENGTH
IF CODELENGTH > 150 Then LET CODE.bit2 = 1
IF CODELENGTH < 150 Then LET CODE.bit2 = 0

PulsIn GPIO.3,0,CODELENGTH
IF CODELENGTH > 150 Then LET CODE.bit3 = 1
IF CODELENGTH < 150 Then LET CODE.bit3 = 0

PulsIn GPIO.3,0,CODELENGTH
IF CODELENGTH > 150 Then LET CODE.bit4 = 1
IF CODELENGTH < 150 Then LET CODE.bit4 = 0

IF CODE = 23 Then hit
codelength = 0
code = 0
type = 0
GoTo STARTPULSE

HIT:
High GPIO.0 'LED ON
Serout 2, N2400,["Hello",10,13]
Pause 500
Low GPIO.0
codelength = 0
code = 0
type = 0
GoTo STARTPULSE

End
</code>

Thanks for your help,
Jeremy

skimask
- 3rd September 2008, 00:40
@ DEVICE PIC12f629, INTRC_OSC
I wouldn't expect this to work without at least a little bit of tweaking.
If you've wiped out the original OSCCAL value, chances are it's not going to be set right.
Which PIC programmer are you using?

jhorsburgh
- 3rd September 2008, 00:55
Hey Skimask,
I am using MicroCode Studio Compiler and WinPIC PIC Programmer.
I have just changed that statement to <code>@ DEVICE PIC12f629, INTRC_OSC_NOCLKOUT</code> which is what i wanted but it still does not work.

Thanks,
Jeremy

mackrackit
- 3rd September 2008, 01:58
The program makes it to thr HIT: label and turns on the LED? correct?

Are you using hyperterminal at the PC? And it is not receiving anything or is it receiving junk.

If junk, it may be the internal OSC is not good enough.

jhorsburgh
- 3rd September 2008, 04:02
Hi Dave,
The program makes it to the HIT routine and turns the LED on, it even sends a pulse out GPIO.2 but Hyperterminal doesn't receive anything. I'll try an external oscillator to see if that helps.

Thanks Guys,
Jeremy

jhorsburgh
- 3rd September 2008, 04:06
Hi Guys,
The external oscillator has fixed the problem! Thanks a bunch guys.

Jeremy

skimask
- 3rd September 2008, 04:14
Hi Guys,
The external oscillator has fixed the problem! Thanks a bunch guys.
Jeremy

Just a thought for you...
Since you know it works with an external oscillator and NOT with the internal one which likely needs to be calibrated...Now might be the time to learn how to calibrate it to work correctly for future uses in this arena...since you've got a working example that is...

And I don't know about the WINPIC programmer, but the PICKIT2 from Microchip has an option to get the CAL value back on these types of PICs...something else to think about...

Archangel
- 3rd September 2008, 04:19
Here is the link to an00250 from microchip, regarding how to recover the missing number:
http://ww1.microchip.com/downloads/en/AppNotes/00250a.pdf

jhorsburgh
- 3rd September 2008, 07:21
Thanks guys, i didn't realise you could calibrate the internal oscillator, ill definitely have a look into it.

Jeremy

mackrackit
- 3rd September 2008, 12:58
This has been my problem with using the internal OSC.
From the link Joe gave:


Applications that are exposed to a varying
voltage and temperature range could have
intelligent on-board recalibration.

I can make it work in the shop, but when it goes out into the world of 120 degrees F in the shade things get weird again. A three legged resonator does not have a problem.

Maybe I am missing something?