PDA

View Full Version : rfPIC Serin problem



gavo
- 8th October 2007, 08:38
Hi All, I have been having some problems trying to send and receive data using the rfPIC16F675K and the rfRXD0420, I have been trying to use the serin command to read the data i have sent using the serout command:

pulsout porta.2, 1
SerOut PORTA.2,n2400,[$55,$55,"A",B0]

when I use the serin2 command to wait and to receive "A", it seems like it does not work

SERIN2 PORTC.1,n2400,1000,loop1,[WAIT("A"),B1]

i have also tried the pulsin command but seem to be getting nothing, does anyone have some ideas?

Many Thanks,

Gavin

mister_e
- 8th October 2007, 17:16
This should work... but as we don't se the whole code, it's hard to tell if you don't have anything missing in it. Make sure you have disabled all analog stuff on the pin you're using and it should be ok... unless i missed something

gavo
- 9th October 2007, 07:11
Hi Steve,

Many thanks for the reply ;-)

Please find below:

Transmitter Side

INCLUDE "modedefs.bas"
DEFINE OSCCAL_1K 1

TRISIO.0 = 1 ' set GPIO.0 as input
TRISIO.2 = 0 ' set GPIO.0 as output

B0 VAR WORD

start:

PAUSE 500
HIGH PORTA.5
PAUSE 500
LOW PORTA.5
PAUSE 500
HIGH PORTA.5
PAUSE 500
LOW PORTA.5
GOTO loop

LOOP:

PAUSE 500
LOW PORTA.5
IF PORTA.3 = 0 THEN GOTO LOOP1
IF PORTA.3 = 1 THEN GOTO loop

LOOP1:

HIGH PORTA.5
SerOut PORTA.2,n2400,[$55,$55,"A",B0]
Pause 100
GoTo LOOP

End
INCLUDE "modedefs.bas"


trisa = %00111111
trisc = %00111111

B0 VAR WORD
B1 VAR BYTE
B2 VAR BYTE
Pause 100

start:

high porta.4
low porta.1
pause 500
low porta.4
high porta.1
pause 500
high porta.4
low porta.1
pause 500
low porta.4
high porta.1
pause 500
GOTO loop

loop:

SERIN2 PORTC.1,N2400,1000,start,[WAIT("A"),B1]
GOTO LOOP2

loop2:

low porta.4
high porta.1
pause 3000
high porta.4
low porta.1
pause 3000
goto START


End

Receiver Side:

gavo
- 9th October 2007, 14:08
Hi steve,

I have been running the code again and it seems to get stuck on the the receive side in the line of:

SERIN2 PORTC.1,T2400,1000,start,[WAIT("A"),B1]

The code seems just to hang, it does not even run to the label "start" i am using the PIC16F676, any ideas why it is doing this?

Regards,

Gavin

Bruce
- 9th October 2007, 14:43
PORTC.1 on the 676 is an analog input by default at power-up. It will always read 0 until
you disable its A/D function.

The rfPIC12F675K also has A/D you may need to disable.

gavo
- 9th October 2007, 19:40
Hi Bruce,

Many thanks, i will try that ;-)

Regards,

Gavin

gavo
- 9th October 2007, 20:18
Hi Bruce,

I have used the ANSEL = 0 and the device works until I plug the receiver board in, when I plug the receiver board in the device "seems"to hang, I then put a scope on RC1 and noticed quite a crazy waveform, I then pressed the button on the transmitter and it took around +- 20 sec's before the receiver recognised the transmitter's data and then the device functioned correctly. I am assuming I have something wrong with my transmitter serout routine as I am not sure why it take so long for the receiver to recognise the transmitter, have you some ideas?

Many Thanks,

Regards,

Gavin

Bruce
- 9th October 2007, 23:13
Hi Gavin,

I'm just guessing, but are you using a Microchip rfPIC dev kit?

Bruce
- 10th October 2007, 05:43
I'm assuming this is the hardware you have, so I broke out my rfPIC eval kit, and played
a bit. Give these a try.

Receiver example;


'************************************************* ***************
'* Name : rfPIC_RX.BAS *
'* Author : B. Reynolds *
'* Notice : Copyright (c) 2007 Reynolds Electronics *
'* : All Rights Reserved *
'* Date : 10/09/2007 *
'* Version : 1.0 (Momentary decoder version) *
'* Notes : 2-Bit decoder for Microchip RF dev system *
'* : with rfRXD0420 module installed in PICkit 1 board *
'************************************************* ***************
@ DEVICE PIC16F676,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_ OFF
@ DEVICE PWRT_ON,PROTECT_OFF

DEFINE OSC 4
DEFINE NO_CLRWDT 1 ' Watchdog timer is disabled, so we don't need to reset it
DEFINE OSCCAL_1K 1 ' load factory calibration value
DEFINE INTHAND RESET_VT ' Interrupt on Timer1 overflow to reset outputs in 65.5mS
' if no serial data received in this time period
SYMBOL D_IN = PORTC.1 ' data input pin
SYMBOL TMR1IF = PIR1.0 ' Timer1 overflow interrupt flag (reset in int handler)
SYMBOL TMR1IE = PIE1.0 ' Timer1 interrupt enable bit

'Variables for saving state in interrupt handler
wsave VAR BYTE $5F system ' Saves W
ssave VAR BYTE bank0 system ' Saves STATUS
psave VAR BYTE bank0 system ' Saves PCLATH
fsave VAR BYTE bank0 system ' Saves FSR

' Working variables
MATCH VAR BYTE bank0 system ' Match variable
DAT_OUTB VAR BYTE ' Holds decoded data for output
DAT_IN1 VAR BYTE ' 1st Data byte
DAT_IN2 VAR BYTE ' 2nd Data byte for verify
CHK_SUM VAR BYTE ' Holds checksum received
CheckSum VAR BYTE ' Computed checksum of all bytes received
LOOPS VAR BYTE ' Loop var

' Constants
Synch CON "~" ' 01111110 synch byte
N2400 CON 16780 ' 2400 bps inverted
N4800 CON 188 ' 4800 bps inverted

' hardware init
PORTA = 0
TRISA = %00111001 ' RA1 and RA2 are LED outputs
PORTC = 0 ' Clear outputs on power-up
TRISC = %00111110 ' RC1 = RF input
IOC = 0 ' Interrupt on change disabled
VRCON = 0 ' Comparator Vref disabled
CMCON = 7 ' Disable comparators
ANSEL = 0 ' disable A/D
OPTION_REG = 128 ' Pull-ups off

' Setup Timer1 for resets after ~65.5mS
T1CON = %00000000 ' Internal clock, 1:1 prescale, Timer1 off for now
TMR1L = 0
TMR1H = 0 ' Timer1 low & high bytes cleared
TMR1IF = 0 ' Clear Timer1 overflow flag before enabling interrupt
TMR1IE = 1 ' Enable Timer1 overflow interrupt
INTCON = %11000000 ' Global & peripheral ints enabled
MATCH = 0 ' Clear match count
GOTO MAIN ' Jump over int handler

ASM ; Timer1 overflow interrupt resets outputs when no valid key press
; is detected within ~65mS
RESET_VT
movwf wsave ; Save W
swapf STATUS, W ; Swap STATUS to W (swap avoids changing STATUS)
clrf STATUS ; Clear STATUS
movwf ssave ; Save swapped STATUS
movf PCLATH, W ; Move PCLATH to W
movwf psave ; Save PCLATH
movf FSR, W ; Move FSR to W
movwf fsave ; Save FSR

; Do interrupt stuff here
bcf T1CON,TMR1ON ; Stop Timer1
clrf TMR1L ; Clear low byte
clrf TMR1H ; Clear high byte
bcf PIR1,TMR1IF ; Clear Timer1 interrupt flag bit
clrf PORTA ; Clear outputs on button release
clrf MATCH ; Clear match variable

; Restore FSR, PCLATH, STATUS and W registers
movf fsave, W ; retrieve FSR value
movwf FSR ; Restore it to FSR
movf psave, W ; Retrieve PCLATH value
movwf PCLATH ; Restore it to PCLATH
swapf ssave, W ; Get swapped STATUS value (swap to avoid changing STATUS)
movwf STATUS ; Restore it to STATUS
swapf wsave, F ; Swap the stored W value
swapf wsave, W ; Restore it to W (swap to avoid changing STATUS)
bsf T1CON,TMR1ON ; Re-enable Timer1 before exiting interrupt handler
retfie ; Return from the interrupt
ENDASM

MAIN:
' Fire up Timer1 before entry to serial input routine
T1CON.0 = 1

' at 4MHz Timer1 overflows in 65536 * 1uS (~65.5mS) if no Synch byte
' and serial data arrive on time. SERIN2 timeout & label options
' are useless with a noisy RF receiver output - as noise continually
' resets the timeout period causing it to hang forever.

' Wait for Synch byte, then get new inbound data & checksum
SERIN2 D_IN,N2400,[WAIT(Synch),DAT_IN1,DAT_IN2,CHK_SUM]

T1CON.0 = 0 ' Stop Timer1 once we've received data
TMR1L = 0 ' Clear low byte
TMR1H = 0 ' Clear high byte

' / **** Begin data validation **** /

' Calculate checksum by adding 2 data bytes together
CheckSum = DAT_IN1 + DAT_IN2

' Test new checksum against one received in CHK_SUM
IF CheckSum != CHK_SUM THEN MAIN ' Failed checksum, return

' Test data bytes for match
IF (DAT_IN1) != (DAT_IN2) THEN MAIN ' Failed data comparison, return

MATCH = MATCH + 1 ' We have a match so increment match count
IF MATCH = 2 THEN DECODE ' Everything matched twice, we're good
GOTO Main ' Else do it all over

' Everything looking good - so place new data on outputs
DECODE:
' Place decoded values on port pins..
PORTA = DAT_IN1 & %00000110
DAT_IN1 = !DAT_IN2 ' Destroy the match
MATCH = 0
GOTO MAIN

END

Transmitter example;


'************************************************* ***************
'* Name : rfPIC_TX.BAS *
'* Author : B. Reynolds *
'* Notice : Copyright (c) 2007 Reynolds Electronics *
'* : All Rights Reserved *
'* Date : 10/09/2007 *
'* Version : 1.0 *
'* Notes : 2-BIT Encoder for remote control with the *
'* : rfPIC12F675 on Microchip rfPIC demo board *
'************************************************* ***************
@ DEVICE PIC12F675,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_ OFF
@ DEVICE PWRT_ON,PROTECT_OFF

' With rfRXD0420 module installed in PICkit 1 board;
' SW1 toggles LED D6 on PICkit 1 board
' SW2 toggles LED D7 on PICkit 1 board
DEFINE OSC 4
DEFINE NO_CLRWDT 1
DEFINE OSCCAL_1K 1

SYMBOL D_OUT = GPIO.2 ' RF serial data output
SYMBOL E_OUT = GPIO.5 ' RF transmitter enable output

DAT_OUT VAR BYTE ' Holds 8-bit data byte
LOOPS VAR BYTE ' Loop var
CHK_SUM VAR BYTE ' Holds calculated checksum of outbound data
BAUD VAR WORD ' Holds baud rate

' Constants
PreAmble CON $A5 ' 10100101 preamble
Synch CON "~" ' 01111110 synch byte
N4800 CON 188 ' 4800 bps
N2400 CON 16780 ' 2400 bps
GUARD CON 5 ' 5mS guard time pause

' hardware init
GPIO = 0 ' Everything off on boot
' GPIO.2=data out, GPIO.5=RF enable, GPIO.3,4=SW1/SW2 switch inputs (rfPIC board)
TRISIO = %00011011 '
ANSEL = 0 ' Disable A/D
INTCON = %00001000 ' Enable port change wakeup from sleep
WPU = %00010000 ' pull-up on for GPIO.4 (external pull-up already on GPIO.3)
IOC = %00011000 ' Wakeup on change enabled for GPIO.3,4
VRCON = 0 ' Disable internal Vref
CMCON = 7 ' Disable comparators
OPTION_REG = 0 ' Pull-ups on

D_OUT = 0 ' Idles low for inverted serial output
E_OUT = 0 ' Enable for RF transmitter=0 (transmiter off)
BAUD = N2400 ' Set baud rate here

Main:
' Read port to clear missmatch, if with no buttons pressed, then
' clear int-on-change flag & snooze until wake up on change. This
' conserves battery power on the demo board with 3V coin cell.
IF (GPIO.3=1) AND (GPIO.4=1) THEN ' pins will be 0 only when buttons are pressed
E_OUT=0 ' Disable transmitter
INTCON.0 = 0 ' No buttons down, so clear int on change flag
@ SLEEP ' and start snoozin..zzzzzzzzzzz
@ NOP ' Do nothing for 1st instruction on wake-up
ENDIF
E_OUT=1 ' Enable transmitter (+ lights RFEN LED on demo board)
PAUSEUS 25 ' Allow RF stage to stabilize

' Button pressed (or being held down), so keep going
Encode:
' Only DAT_OUT bits 1 and 2 are used. We add a few 1's in bit
' positions 0,3,5,7 to balance out the data packet being sent.
DAT_OUT = %10101001
' Get data on button inputs & invert 0's to 1's
DAT_OUT.0[1]=~GPIO.3
DAT_OUT.0[2]=~GPIO.4
INTCON.0 = 0 ' Clear int on change flag

' Build checksum of 2 data bytes
CHK_SUM = (DAT_OUT * 2)

Transmit:
SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM]
PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.

GOTO Main

END

You should be able to modify these pretty easily for your own application.

gavo
- 10th October 2007, 07:30
Hi Bruce,

Many thanks I will give it a bash ;-), regards, Gavin

onepiece
- 16th November 2007, 23:23
Hi,

I'm a beginner in PIC programming and now struggling to program rfPIC12F675. I'm confused on how TRISIO assign input and output.

movlw b'00010000' ; set GP<4> as digital inputs and other bits as output
movwf trisio ; and set others as outputs/mclr/clkout/osc

However, when I try to simulate it, and try to observe the output (we fire the GP4 as high),
it seems that the output is 0 all the time.

Other than setting the trisio, do I need to call any other instructions to make sure the data is being read in - send to modulation - and then output accordingly.

I'm a bit lost now. Hope that you can help

Bruce
- 17th November 2007, 14:47
The data sheet has everything you're looking for.

And if you're looking for examples in Microchip assembler, then check the Microchip website for rfPIC examples. Here's a direct link to rfPIC examples; http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010060

onepiece
- 19th November 2007, 11:14
Thanks for that. It is useful!

medusa2584
- 19th November 2007, 11:33
im looking at the demo program for development kits transmitter and receiver rfpic12675 and receiver rf rxd XXX. im trying to apply the same program to my telemtry project but with digital input.

i dont understand the part of program which under head transmitter loop. do we need to do the loop if our input is digital? and what about the '' rrf ' and 'bnz' instruction? rotate right flag?

i don't understand the TZnextbit too? im so lost right now. can anyone explain this to me?

thanks

Bruce
- 19th November 2007, 20:39
Help for rrf; PIC data sheet.

Help for bnz assembly language pseudo-instruction; MPASM help file.

Help with assembly language/code examples for rfPIC; http://forum.microchip.com/tt.aspx?forumid=166

Knowing where to look; priceless

For everything else; there's MasterCard....;o}

onepiece
- 20th November 2007, 19:31
Not only mastercard....
Having to learn from an expert.....much more priceless....

Bruce
- 20th November 2007, 21:13
We have a CD-ROM with PicBasic Pro code examples on this page http://www.rentron.com/QRELAY.htm that we offer for a modest fee of $39.95.

Two of the simple PBP code examples on this CD have generated > 100K $ in sales of tiny little 8-pin PIC micros. In less than 1 year. That's why we don't give this stuff away for free..;o}

It may seem super simple once you have the source code, but it's a different story when you write each routine from scratch. And test each routine on 50 or so RF transmitters & receivers to make sure they actually work with various RF modules.

Like Melanie recently said, it's not what you have, but how you use it. She really does know what she's talkng about..;o}

Even when she only hints.

chuck
- 20th November 2007, 23:18
Bruce do you have a distributor in the uk ?

for the CD-rom

Bruce
- 21st November 2007, 00:49
Hi Chuck,

Sorry, but we don't have any distributors for this CD. If postage is outrageous to your location, we can pop one in the regular mail for you.

medusa2584
- 21st November 2007, 06:10
does anyone know how to calculate the transmission bitrate for rfPIC12F675?

and im confuse about one thing. if the datasheet says it would transmit data in 433.9 mHZ, is that referring to the frequency band or the carrier frequency.? as far as i understood, it is the frequency bandwidth, and the carrier frequency depending on the oscillator that we used. isn't it??? can anyone please confirm this to me??

do you know the range of data can be transmitted by rfPIC12F675??

thank you in advance

Bruce
- 21st November 2007, 12:55
The transmit frequency = RFXTAL frequency * 32. This can be trimmed by the value of C1 as shown in the chart. This is the carrier frequency for ASK modulation.

ASK transmits at the center frequency. FSK transmits a few kHz from center frequency. This is explained in the data sheet.

The bit-rate data is transmitted at depends on your firmware. If you look at the Microchip code examples you'll see how they use delays between toggling the data pin to set the bit- rate. 40 kbps is the upper limit.

What you'll have for operating range will vary like the wind depending on your finished RF design, voltage on the PS pin, and a boat-load of other factors like receiver sensitivity, operating environment, antenna design/selection, etc, etc,.

medusa2584
- 21st November 2007, 15:06
thank you very much for the reply..

i have one more question..im testing the rfPIC development kit right now with the demo program..we are trying to test the rf12F675 by using oscilloscope by conneting the probe to the pin output which is pin GP5 and GP0. however, we see no signals output from the transmitter except the analog voltage value 1.29 mv which i think comes from the power supply.

any suggestion how to test it? we have checked the connection circuit many times..but it still give us the same result

Bruce
- 21st November 2007, 15:26
You must have a different rfPIC development kit than the one I have. GP0 on mine connects
to POT0. GP5 to the RFENA pin?

Here are the pin definitions in the Microchip demo tx code example;

#define POT0 GPIO, 0 ; (Analog Input) Potentiometer GP0
#define POT1 GPIO, 1 ; (Analog Input) Potentiometer GP1
#define TXD GPIO, 2 ; (Output) Transmit Data
#define PB3 GPIO, 3 ; (Input Only) Push button switch GP3
#define PB4 GPIO, 4 ; (Input) Push button switch GP4
#define RFENA GPIO, 5 ; (Output) RF Enable

I also have a full schematic in .PDF format on my CD that verifies this.

Have you tried placing the scope on GP2?

medusa2584
- 21st November 2007, 16:40
yup we did try..but we dont get the expected signal..

am i right if im expecting a modulated signal came out from the output channel? so i should be able to see an analog modulated signal with ASK. but, we only see a digital signal 0 1 which i think comes from the power supply that we used.

im sorry..i gave the wrong information. we are using the same develoment kit as yours

thank you

Bruce
- 21st November 2007, 17:01
we only see a digital signal 0 1
You should be seeing a digital signal if you're placing a scope probe on GP2. This is a digital
I/O-pin connected to pin #14 DATAask on your tx board. That's your outbound data being
used to control the PA.

Read the data sheet, section 9.4, ASK Modulation and you'll see why an I/O-pin
would be connected to pin #14.

You can find a modulated signal on the antenna output, but you'll be loading it with your
scope probe.

onepiece
- 21st November 2007, 18:00
Hi
I would like to test whether my rfpic12f675 an rfrxd0420 works according to the demo for the development kit. The part for LED indicators on the Pickit Flash 1, it says that when my GP buttons on transmitter are pressed, LED will be lite up. Does that mean that we can just verify this through the dev kit? The LED on my board sometimes toggle when I press the switches, and I thought I should have got a 7 LEDs to light up.
I'm confused at the part where I need to use PIC16f676 for the rxrfd420, do I need to connect the pins RA5 to RC 2 to the PIC itself? Can anyone help me please.

Bruce
- 21st November 2007, 18:36
Read the rfPIC Dev Kit Quick Start Quide. It has blow-by-blow instructions. The link above
will take you directly to the page where you can download this if you don't already have it.

medusa2584
- 22nd November 2007, 07:23
yes..we finally manage to test the rfkit and it works..:)

now its the time for me to alter the code..the transmitter right now required no external input except from the switch to operate. we planned to replace the gp4 with input from sensor and the input is digital . however there are some part of the demo program that i dont understand the purpose which i pasted below.

under part "fill in transmission buffer" , why they purposely inserted the random number into the buffer register?and then will be ignored by receiver ? and how the receiver is going to ignore it?

and since the input for this demo is analog signal, they have used the converter and have the result stored in register ADRESH and ADRESL. so as for me who has a digital input, i should be able to read straight from the gpio port , but im not sure how is the command since im only read from one bit of register.



and this command means the input data being read and stored in temp register?

the part of demo program that im confused

;----------------------------------
; fill in transmission buffer
;----------------------------------

XMIT

bsf RFENA ; Enable Transmitter

movlw 0x73 ; send Serial number
movwf CSR0

movfw FuncBits ; send Function Bits
movwf CSR1

; send 16-bit Counter
;
; send analog value (this is modified from the fixed
; KeeLoq(r) protocol; these two fields are normally
; used for 16-bit counter value)

bsf STATUS, RP0 ; ----- Select Bank 1 -----
movfw ADRESL ; ADRESL Result
bcf STATUS, RP0 ; ----- Select Bank 0 -----
movwf CSR2

movfw ADRESH ; ADRESH Result
movwf CSR3

movlw 0x56 ; send 32-bit serial number 1 (ignored by receiver)
movwf CSR4

movlw 0x34
movwf CSR5

movlw 0x12
movwf CSR6

movlw 0x20
movwf CSR7

movlw 0x55 ; send Flags
movwf CSR8

onepiece
- 24th November 2007, 23:51
I think I have the same problems with gavo. But currently I'm using assembly to do my programming. This rfPIC12f675 is different from other normal PICs where it has only one tris and gpio port. And the gpio reg is assigned to the pin itself.
Can you kindly explain to me about how can I read in data serially using assembly? I'm sorry that I'm not really familiar with the code you pasted before.
Can I just read in data bit by bit say into gp3 and then send it to gp2 for ASK modulation?
Or can I just put or connect my digital input to gp2?

I understand that the coding below is a Keeloq protocol

' Constants
PreAmble CON $A5 ' 10100101 preamble
Synch CON "~" ' 01111110 synch byte
N4800 CON 188 ' 4800 bps
N2400 CON 16780 ' 2400 bps
GUARD CON 5 ' 5mS guard time pause

As I'm not familiar with your coding, may I know what CON indicates and what N4800 CON 188 means?


Thanks again for your help!

mister_e
- 25th November 2007, 00:12
in PBP, CON is used to define a software constant, in asm it should looks like

YourConstantVariable = .25

or
#DEFINE YourConstantVariable .25

Using pre-defined constant here and there, allow to have a better readable code, and also allow to do some changes without having to scroll the whole code.

For a 12F675 asm example.. well, first google hit gave me
http://www.jbgizmo.com/page29.htm

medusa2584
- 6th December 2007, 09:03
hi people,

has anyone ever encountered a problem of stack overflow in their program?
rite now im doing a program to transmit a stack of data which contain 16 bit + 64 bit +

and the pic that im using is a pic12f675. what should i do to reduce this error?

BobK
- 6th December 2007, 13:15
Hi Medusa,

I had this problem once and it turned out to be a subroutine that had a GOTO at the end of it instead of RETURN. Changed the word--solved the problem.

HTH,

BobK

medusa2584
- 7th December 2007, 23:02
thanks bobk..i tried that, put return at the end of each goto instruction i have, but still it has not succeeded. is it possible due to overflow stack?

my program is supposed to have a stack of 8 byte output excluding the preamble and header and timeguard.

does anyone ever write a program that has a subroutine as follows

read input from port GPIO
move data from GPIO to 'input' register
take only data from bit 1
store the input (bit 1)to bit 0 at another register

repeat for eight times

what i already have in mind

movfw GPIO
movwf input
movlw 0000 0000
xorwf input,f
goto rotate

rotate
rrf input,f
rrf input,f

anyone has any idea to continue?

BobK
- 8th December 2007, 03:38
Hi Medusa,

That's not what I meant. If you are calling a subroutine then at the end of the subroutine you put a RETURN. GOTO does not go at the end of a subroutine. This was the problem I had with one of my projects (18F452). The stack overflow was causing my project to hangup when it got to the subroutine after the stack overflowed. This was the only point I was trying to make.

If you have both a GOTO and a RETURN then you might still be experiencing a problem.

HTH,

BobK

hell_pk
- 10th December 2007, 05:46
Hi Bruce!
I have tried ur codes on RfPIC kit. i can see the data being sent by transmitter on GP2 and received on PORTC.1 on receiver side but the LED's are not blinking. what might be the problem.plz help me troubleshoot.
thanks

Bruce
- 10th December 2007, 15:55
That's hard to say. It works perfectly on my rfRXD0420 module installed in PICkit 1 board.

Are you compiling the receiver code without any changes, and programming it into a
PIC16F676 on the PICKit 1 board with the rfRXD0420 installed per the instructions?

hell_pk
- 11th December 2007, 07:39
Hi
U have not included modedefs.bas in ur program.is that an issue?
I did that but to no avail.
maybe config fuses are causing something.they seem ok.they are as under when i read them using PICkit 1 software:
12F675
config word:0x31D4
osccal: 0x3480
bandgap: 0x3000

12F676
config word:0x31C4
osccal: 0x3440
bandgap: 0x3000

onepiece
- 11th December 2007, 19:15
Hi there,

I've altered the receiver_demo program to suit my application. - I took in the data from rfRxd0420 drom RC2 and try to take it out serially from RC0 of the pic16f676 so that I can
probe the data transmitted.

Currently, I'm simulating the program using MPLAB IDE. Pardon me if I'm wrong.
The receive_demo program that I understand, will check for header. But,
it does says that if the data is high before 6ms, therefore the header is valid.
What if the data is also 'LOW'?
I'm actually having problems with simulation coz it does not want to
come out of the loop - unless I put '1' in between.

When it came out of the loop, I should be able to record that and then output that
to the RC0 but it seems that the program didn't even jump to search for a guard time,
instead it continue the process to find for high or low pulse.

I just altered the receive demo of the dev kit. Can anyone help me please?
Or do you suggest a better way to simulate this program?

MAIN
call CLOCK ; to update TRMLOW and TMRHIGH
; TMRLOW ~=4us TMRHIGH ~=1ms

movlw HIGH STATEM
movwf PCLATH
movf STATECNTR, W ; Mask out the high order bits of
andlw B'00001111' ; STATECNTR (a noise guard)

addwf PCL, F ; The program clock (PCL) is incre-
STATEM
; check for possible start of data stream
goto BEGIN ; mented by STATECNTR in order
goto BEGIN1 ; to go to the appropiate routine
goto HEADER ; header is being ignored
goto HEADER1 ; just count up the time and then takes the data
goto HIGHPLSE ; times the width of Hi Pulse
goto LOWPULSE
goto RECORD ; record the 8 byte data
goto WAIT4END ; wait for guard time to be greater than 8ms

goto FIRST0 ; check whether DATA0 of bit 0 is 0 or 1
call SENDOUT ; to send out the serial data out through portc pin 0
goto RESET ; These RESET commands correct
goto RESET ; erroneous values of STATECNTR
goto RESET ; not caught by the mask above.
goto RESET
goto RESET
goto RESET

medusa2584
- 11th December 2007, 20:58
from the demo program, they used ASK modulation which use NRZ format modulation.
in this format, when the input is zero it would give you a pulse of 110 while if the input is one, it would give pulse 011, which means it will still give you pulse high for whichever input.

medusa2584
- 11th December 2007, 21:34
im still experiencing this overflow stack error message..
ive tried to change all goto to call instruction
put return for every subroutine..but still it doesnot work
can anyone help me

i pasted my full program below



;nur azrin hilmi
;gdp 17-telemetr


LIST P=RF675K ; list directive to define processor
#include <RF675K.INC> ; processor specific variable definitions


;**************define variables*********************************

#define sensor GPIO, 1
#define txd GPIO, 2 ; (Output) Transmit Data
#define pb3 GPIO, 3 ; (Input Only) Push button switch GP3
#define pb4 GPIO, 4 ; (Input) Push button switch GP4
#define rfena GPIO, 5 ; (Output) RF Enable

; GPIO Pins = xx543210
; #define gptris b'00011011'

#define TGUARD d'5'
#define exor b'00000000'
#define total d'8'
; #define rtime d'5'
;************************************************* **************

org 0x00
goto initialize

org 0x004

movwf w_temp
swapf STATUS,W
bcf STATUS, 5 ;select bank 0
movwf status_temp ;save status register
;************************************************* **************

; interrupt service routine (ISR)
; interrupt on change on pin of gpio

movfw GPIO
bcf INTCON,0

;************************************************* *************

swapf status_temp,w ;set bank into original state
movwf STATUS
swapf w_temp,F
swapf w_temp,W

retfie


;************************************************* **************

WaitxTE
movwf Count2 ; [1]

waitxlp
movlw D'30' ; [1]
movwf Count ; [1]

wait400lp
nop ; [1]

nop ; [1]
decfsz Count,F ; [1]
goto wait400lp ; [2]
; --------
; 79 x 5 = 395us

decfsz Count2,F ; [1]
goto waitxlp ; [2]

retlw 0 ; [2]

; total 2 (call) + W x (395 + 5) + 2 (return)
; w = 1 -> 406us @4MHz
; w = 2 -> 806us @4MHz
;************************************************* ************
;initialize pic
;************************************************* ************

initialize

;clearing all ports
CLRF nobit
CLRF nobit2
clrf input
clrf store
clrf rotateright
clrf Count
clrf Count2
clrf ltime
clrf rtime
;disable global interrupts during initialization

bcf INTCON,7

;calibrating the internal oscillator

; bsf STATUS,5 ;select bank 1
call 0x3FF
movwf OSCCAL
; bcf STATUS,5

;turn off the comparator
bsf STATUS,5

clrf ANSEL ; clear ansel register
bcf STATUS,5

clrf GPIO ; initialize General Purpose Input Output to 0

;setting gpio register to the cosrresponding io pin
bsf STATUS,5

bsf TRISIO,0
bsf TRISIO,1
bsf TRISIO,4
bcf TRISIO,2
bCf TRISIO,5

bcf STATUS,5 ;select bank 0

;set bit 0:2 at register cmcon ;setting gp2 as digital output |offkan comparator
bsf STATUS,5
bsf CMCON,0
bsf CMCON,1
bsf CMCON,2
BCF STATUS,5
; VRCON register ; CVref circuit powered down,no Idd drain

bsf STATUS,5
bcf VRCON, 7
bcf STATUS,5


;************************************************* ***************
;****timer1 module gate control**********************************
; disabling timer1
bsf STATUS, 5 ; select Bank 1
movlw b'01000100' ; disable TIMER1
movwf T1CON ;
bcf STATUS, 5 ; select Bank 0

;************************************************* ***************
;weak pull-up register (wpu)
;each pull-up is automatically turned off when the pin is configured as an output
bsf STATUS,5
movlw b'00010000'
movwf WPU
bcf STATUS,5

;***************set pin for config_address regsiter

;OPTION Register

; OPTION_REG contains control bits to configure:
; Weak pull-ups on GPIO (see also WPU Register above)
; External GP2/INT interrupt
; TMR0
; TMR0/WDT prescaler

bsf STATUS,5 ; ---- Select Bank 1 -----

bcf OPTION_REG, NOT_GPPU ; GPIO pull-ups: enabled

bsf OPTION_REG, INTEDG ; Interrupt Edge: on rising edge of GP2/INT pin

bcf OPTION_REG, T0CS ; TMR0 Clock Source: internal instruction cycle (CLKOUT)
bcf OPTION_REG, T0SE ; TMR0 Source Edge: increment low-to-high transition on GP2/T0CKI pin

bcf OPTION_REG, 3 ; Prescaler Assignment: assigned to TIMER0

; TMR0 Prescaler Rate: 1:2
bcf OPTION_REG, 2 ; Prescaler Rate Select bit 2
bcf OPTION_REG, 1 ; Prescaler Rate Select bit 1
bcf OPTION_REG, 0 ; Prescaler Rate Select bit 0

bcf STATUS, 5 ; ---- Select Bank 0 -----




;************************************************* **************
;interrupt on-change register
bsf STATUS,5

movlw b'00011011' ;enable global interrupts in order for the individual pin to be configured(kalo switch
movwf IOC

movlw b'00000000' ;peripheral interrupt register; disable
movwf PIE1

bcf STATUS,5

movlw b'00001000' ;enable interrupt control register
movwf INTCON


;************************************************* *****************
;MAIN PROGRAM
;************************************************* ****************8
MAIN


bsf INTCON,7 ; enable global interrupts
; bsf rfena ; enable transmitter
call BITCHECK

;************************************************* ****************
;CHECK INPUT
;************************************************* ****************


BITCHECK
btfsc nobit2,3
goto TRANSMIT

movfw GPIO
movwf input
incf nobit2,f
movfw nobit2
movwf nobit


btfsc nobit2,2
goto checkleft ;for bit number 4,5,6,7
goto checkright ;for bit number 1,2,3,8


checkleft

btfsc nobit2,1
goto rleft
btfsc nobit2,0
goto bit5
goto rright1
return;
checkright
btfsc nobit2,3
goto rleft
return;
rright1
movlw d'5'
movwf rtime
return;
rright

decf rtime,f
decfsz nobit
goto rright
; movwf rtime
rotater
rrf input,f
decfsz rtime
goto rotater
movfw input
xorwf store,w
movwf store
goto BITCHECK
return;
bit5
movfw input
xorwf store,w
movwf store
goto BITCHECK
return;
rleft

movfw nobit
movwf ltime
decf ltime
decf ltime
decf ltime
decf ltime
decf ltime
return
rotatel
rlf input,f

decfsz ltime
goto rotatel
movfw input
xorwf store,w
movwf store
goto BITCHECK
return;
TRANSMIT
bsf GPIO,5
; send preamble (50% duty cycle)
Preamble ;send 16 bit
movlw d'16'
movwf BitCount ; init number of preamble bits

PreL
bsf txd ; ON
movlw 1
call WaitxTE ; delay
bcf txd ; OFF
movlw 1
call WaitxTE ; delay
decfsz BitCount,F ; loop
goto PreL

; sync pause

TXloop

movlw d'10'
call WaitxTE ; Theader = 10 x Te

; send 72 bit pattern

movlw store ; lsb first
movwf FSR

TXNextByte
movlw D'8'
movwf BitCount

TXNextBit

rrf INDF,W ; 8 bit rotate | rotate right f through carry
rrf INDF,F ; Carry contain lsb
BC ONE ; branch on carry | goto ONE if bit is set
ZERO ;wave pattern if the bit is zero
movlw 2 ;
movwf TimeHi ; +---+---+ +--
movlw 1 ; | | |
movwf TimeLo ;---+ +---+
goto Trasm_BIT ; | 2Te Te |

ONE ;wave pattern if the bit is one
movlw 1 ;
movwf TimeHi ; +---+ +--
movlw 2 ; | | |
movwf TimeLo ;---+ +---+---+
; | Te 2Te |

Trasm_BIT

bsf txd ; ON
movf TimeHi,W
call WaitxTE

bcf txd ; OFF
movf TimeLo,W
call WaitxTE

decfsz BitCount,F
goto TXNextBit ; loop on bits


; guard time
movlw TGUARD
call WaitxTE

org 0x3ff
retlw 0x80


;----------------------------------------------------------------------
end ; end of program directive
;----------------------------------------------------------------------

onepiece
- 12th December 2007, 20:00
Hi,

I managed to work through the receiving and process the data and store it to DATA0.
What I can't do now is sending out serially the 8 bit DATA0 to
the pin SER_OUT(which happens to be PIN RC0).

I've tried to copy DATA0 to PORTC (in RECORD2) but since PORTC is only 6 bit, the data is not out correctly. Can anyone help me please?

;----------------------------------------
; RECORD
; Records each bit as it comes in from the data stream.
;
; Input Variables:
; RXDATA
; Output Variables: 1 bytes of the 8 bit data read from sensor
; DATA0

RECORD
movf HIGHWDTH, W
subwf LOWWDTH, W ; The state of the carry bit after
; this operation reflects the data
; logic. This is then rotated
; into the storage bytes.
rrf DATA0, F ; the only data to be processed
movlw HIGHP ; 0x04 to STATECNTR
movwf STATECNTR
decfsz BITCNTR, F ; If the bitcntr is = 0 , skip next instruction
goto MAIN
; set to count for 1 data - record 1 byte of data bit by bit
movlw D'1' ; Starting here and including RECORD1
movwf COUNTR ; a check is made to make sure that

movlw DATA0 ; the data is not composed entirely
movwf FSR ; of 1s.
;FSR is the register to store the DATA0
RECORD1 ; this is the procedure of indirect addressing
movlw 0xFF
xorwf INDF, W ; Use indirect referencing to point to
btfss STATUS, Z ; DATA0 on subsequent loops
goto RECORD2 ; in RECORD1.

incf FSR, F
decfsz COUNTR, F
goto RECORD1

goto RESTART

RECORD2
movlw WAIT
movwf STATECNTR ; Make state WAIT4END

movfw DATA0 ; copy DATA0 to PORTC
movwf PORTC ; want to send data out serially

; bsf SER_OUT ; pin RC5 to observe the processed output

goto MAIN

skimask
- 12th December 2007, 20:46
medusa2584,
Recheck your code flow.
You're still trying to RETURN from GOTO in various places.
And (I'm not even sure if it's possible in MPLAB) are you getting stack OVERFLOW errors or stack UNDERFLOW errors? If getting UNDERFLOW is possible, that's what I'd say you're getting.

medusa2584
- 13th December 2007, 12:40
thanks skimask. i solved the the underflow and overflow program. however, i got a new problem.

when i tested my program with rfpic12f675, and put probe at gp2 and gp5. the output is similar with what i simulated in mplab sim. there is preamble, header, and data bits. however, there is no change of output displayed on the oscilloscope even i dont supply any input to the transmitter. any suggestion why this happened?

the output always showed data bit of 1111 0111 which is weird since i sont supply any input to the system.

any suggestion anyone?

T.Jackson
- 15th December 2007, 13:42
medusa2584,
Recheck your code flow.
You're still trying to RETURN from GOTO in various places.
And (I'm not even sure if it's possible in MPLAB) are you getting stack OVERFLOW errors or stack UNDERFLOW errors? If getting UNDERFLOW is possible, that's what I'd say you're getting.

Hello skimask,

I'd like to take this opportunity to welcome you back to the forum. I do hope that your stay will be a long, pleasant & fruitful one. Everyone deserves a second chance :)

onepiece
- 15th December 2007, 16:12
Hi,

I was simulating my program and did not even finish running everything - my MPlab just suddenly close itself with a window Microsoft is checking the problem.

Does anyone know why? Is that because of my Vista or because of the bug in the
new version MPLab IDe 8?

mister_e
- 16th December 2007, 10:00
Check out the Microchip forum, i remember to have already heard about some strange problem using Vista.
http://forum.microchip.com/tt.aspx?forumid=57

PS: you have 'till January to buy an XP o/s... to me, Vista is really not recommended before, at very least, 1 year...

onepiece
- 16th December 2007, 11:46
I suppose that might be the problem. I'll try simulating that on XP based first then.

I need some help with understanding the rate of data in programming the receiver rfrxd420 using pic16f676.

The demo program currently indicates that the the TMRHIGH and TMRLOW to be multiply with 4us. Does this relates to the baud rate?
I'm having problem to understand the timing of the program.
Can anyone help?

skimask
- 17th December 2007, 15:19
Hello skimask,
I'd like to take this opportunity to welcome you back to the forum. I do hope that your stay will be a long, pleasant & fruitful one. Everyone deserves a second chance :)

2nd chance?
2nd chance at what?
Did I lose my first chance at something?
Did you have something to do with afford me a second chance at whatever it is?
Did I go somewhere else that I needed to come back?

mackrackit
- 17th December 2007, 16:26
Howdy skimask, good to hear from you again.

T.Jackson
- 18th December 2007, 02:27
2nd chance?
2nd chance at what?
Did I lose my first chance at something?
Did you have something to do with afford me a second chance at whatever it is?
Did I go somewhere else that I needed to come back?

I see that someone is experiencing some considerable "self-denial".

skimask
- 18th December 2007, 13:55
I see that someone is experiencing some considerable "self-denial".

Time for someone else to step outside and play a one-handed game of hide and go @$%&# one's self...and deny some of that...

medusa2584
- 1st January 2008, 00:41
thank you very much for the reply..

i have one more question..im testing the rfPIC development kit right now with the demo program..we are trying to test the rf12F675 by using oscilloscope by conneting the probe to the pin output which is pin GP5 and GP0. however, we see no signals output from the transmitter except the analog voltage value 1.29 mv which i think comes from the power supply.

any suggestion how to test it? we have checked the connection circuit many times..but it still give us the same result

does anyone know why we have to times it by 32? i have looked at the datasheet, but it does not state the reason anywhere.

Destovi
- 11th March 2008, 17:52
Hi all I am currently working on a project using the rfPIC micro. I am wondering if anyone has done any work with this PIC without using the dev board. I want to build the circuits myself and program them to work. if anyone has done this and can give me some assistance it would be greatly appreciated.

Thanks