HI EVERY ONE
i m trying to control a robotic arm with wireless serial communication between two PICs. the sender pic takes and input from a joustick potintiometers and send instructios to the receiving pic. there should be 7 bytes to send using serin command. a preamble byte $55 and 6 control bytes.
i established the serial communication between the two pic successfully. and i tested the received data with lcd. everything works great.
the problem is, when i wrote a PWM routine in the receiving pic, i used TMR0 interrupts. now when i try to reveive data and do PWM. the pic doesnt work.
i tried to figure out whats wrong but i failed
can u help me?
here are the codes. i didnt add potentiometers reading to sender pic. i just tried to test it with numbers.
Code:
INCLUDE "MODEDEFS.BAS"
S1 VAR BYTE
S3 VAR BYTE
S4 VAR BYTE
S6 VAR BYTE
S7 VAR BYTE
DC VAR BYTE
DC1 VAR BYTE
DC2 VAR BYTE
CNT VAR BYTE
S1 = 255
S3 = 3
S4 = 44
S6 = 10
S7 = 20
DC = 77
TRISB = 0
PAUSE 500
MAIN:
PORTB.0 = 1
PAUSE 1000
PORTB.0 = 0
PAUSE 1000
PORTB.0 = 1
PAUSE 1000
PORTB.0 = 0
PAUSE 1000
DATASEND:
SEROUT 7,T2400,[$55,S1,S3,S4,S6,S7,DC]
PAUSEUS 2
GOTO DATASEND
the receiver pic code is here
Code:
'****************************************************************
'* Name : W_ROB_REC.PBP *
'* Author : [AHMAD ABU OMAR] *
'* Notice : Copyright (c) 2009 [AHMAD ABU OMAR] *
'* : All Rights Reserved *
'* Date : 16/12/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'****************************************************************
'* DIFINTIONS
'****************************************************************
define osc 48
INCLUDE "MODEDEFS.BAS"
'****************************************************************
'* VARIABLES
'****************************************************************
S1 VAR BYTE ' first servo motor position
S2 VAR BYTE
S3 VAR BYTE
S4 VAR BYTE
S5 VAR BYTE
S6 VAR BYTE
S7 VAR BYTE
DC VAR BYTE
DC1 VAR BYTE ' right DC motor of mobile base
DC2 VAR BYTE ' left DC motor of mobile base
OLD VAR BYTE ' a counter variable
dc1 = 0
DC2 = 0
S1 = 1
S2 = 255
S3 = 1
S4 = 1
S5 = 255
S6 = 1
S7 = 1
'****************************************************************
'* MAIN PROGRAM START
'****************************************************************
INTCON2 = $F5 ' DISBALE PORTB PULL-UPS, SET TRM0 INTERRUPT TO HIGH PERIORITY
INTCON3 = $C0 ' DISABLE EXTERNAL INTERRUPTS PERIORITY
RCON.7 = 0 ' DISABLE PERIORITY LEVELS ON INTERRUPTS
PIE1 = 0 ' DISABLE ALL PREPHIRAL INTERRUPTS
PIE2 = 0
PIR1 = 0
PIR2 = 0
ADCON1 = 15 ' ALL DIGITAL I/O
TRISA = 0
TRISB = %10000000 ' RB7 is input, used to reveive serial data
TRISC = 0
LATA = 0
LATB = 0
LATC = 0
INTCON = %00100000 ' ENABLE TIMER0 INTERRUPTS
T0CON = %00000101 ' SET PRESCALAR 64 FOR TMR0, APROX 5us PER INCREMENT
' AND TMR0 WORKING IN 16 BIT MODE
TMR0L = $60 ' SET A BALANCE FOR 20ms PERIOD BEFORE INTERRUPT
TMR0H = $F0
ON INTERRUPT GOTO PW
INTCON = %10100000
T0CON.7 = 1
MAIN:
WHILE 1
PAUSEUS 1
GOSUB RECEIVE
WEND
'****************************************************************
'* PW: INTERRUPT SERVICE ROUTINE
'****************************************************************
DISABLE
PW:
PORTB =%01111111
OLD = 0
TMR0L = 0
PAUSEUS 800
s2 = 255 - s1
s5 = 255 - s4
FOR OLD = 0 TO 255
IF S1<= 0 THEN PORTB.0 = 0:S1 = 1
IF S2<= 0 THEN PORTB.1 = 0:S2 = 1
IF S3<= 0 THEN PORTB.2 = 0:S3 = 1
IF S4<= 0 THEN PORTB.3 = 0:S4 = 1
IF S5<= 0 THEN PORTB.4 = 0:S5 = 1
IF S6<= 0 THEN PORTB.5 = 0:S6 = 1
IF S7<= 0 THEN PORTB.6 = 0:S7 = 1
S1 = S1 - 1
S2 = S2 - 1
S3 = S3 - 1
S4 = S4 - 1
S5 = S5 - 1
S6 = S6 - 1
S7 = S7 - 1
WHILE TMR0L = OLD
WEND
NEXT OLD
TMR0L = $EF ' SET A BALANCE FOR 18ms PERIOD BEFORE INTERRUPT
TMR0H = $F1
INTCON = %10100000
T0CON.7 = 1 ' TIMER0 ON
RESUME
ENABLE
'****************************************************************
'* SUBROUTINE RECEIVE
'****************************************************************
RECEIVE:
serIN PORTB.7,T2400,[$55],S1,S3,S4,S6,S7,DC
PAUSEUS 1
RETURN
i m using PIC 16f628a on sending end and 18f2550 on the reciving end
crystals used on both sides are 4 MHz
Bookmarks