If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Thats what I thought it was doing, I did the same thing with the line in from the pc and I haven't had any errors since, but I still have the double buffer system that will make sure i know when i get one.
Now I can move on to the next challenge. Which is, having multiple commands qued to be executed at once.
I will get to work on that task and post my results when I get somewhere with it.
I have now given the master an 8 command buffer. And finnally life is good ^^.
I think I am going to up the buffer to 16, but that will require that I use 2 buffer arrays. For now, heres the master code, feel free to make any suggestions, and just let me know if you use it in any projects.
:MSmaster:
Code:'**************************************************************** '* Name : MSERVMASTER.BAS * '* Author : Joseph Dattilo * '* Notice : Copyright (c) 2007 Joseph Dattilo * '* : All Rights Reserved * '* Date : 5/25/2007 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** define OSC 8 OSCCON = %1111110 ' sets internal osc to run at 8MHZ '----------turn analog on porta off, and use as digital input/output '----------this is used to allow serial input on the A bus. CMCON = 7 'Comparators OFF ANSEL = 0 'A/D OFF -- Port pins all digital '---------- '---**Pins rsoutpin var porta.0 rsinpin var porta.1 picinpin var portb.4 picoutpin var portb.5 porta=0 portb=0 '---vars temp var byte qued var byte outqued var byte message var byte[24] '-up to 8 commands can be buffered in que array. que var byte[96] '--------------- qued = 0 'set number in que to 0 goto pcin '############################## pc recieve ################################ 'que up messages from pc '########################################################################## pcin: '---- let pc know we are ready to recieve message. serout2 rsoutpin, 16468, ["waiting!"] 'call for data '---- ready to recieve message serin2 rsinpin, 16468, [str message\24] '------------------------------------------------------------------------ 'compare both arrays checking for bad data if data bad request it again. for temp = 0 to 11 : if message[temp] <> message[temp+12] then goto baddata next temp '------------------------------------------------------------------------ serout2 rsoutpin, 16468, [str message\12] 'send confirmation of reciept. '------------------inque----------------- for temp = 0 to 11:que[(12*qued)+temp]=message[temp]:next temp serout2 rsoutpin, 16468, ["Qued:",str que\(12*qued+12)] 'display all in que '---------------------------------------- if message[11] = "n" then serout2 rsoutpin, 16468, ["still more commands!?"] 'debug statement qued=qued+1 'go to next position in que goto pcin 'request the data for the next item. else outqued = 0 'set picout que start position to 0 (first item in que first) goto picout 'we are ready to command the servo controller. endif '------------------------- 'where bad data takes you. baddata: serout2 rsoutpin, 16468, ["bad data!"] goto pcin '------------------------- '############################## pic transmit ############################# '---- picout procedure waits for high on picinpin and then transmits data '######################################################################### picout: '---------------------unque next item into message array for temp = 0 to 11:message[temp]=que[(12*outqued)+temp] message[temp+12]=que[(12*outqued)+temp]:next temp '------------------------------------------------------- input picinpin while picinpin = 0 pause 1 wend serout2 picoutpin, 16468, [str message\24] pause 7 if picinpin = 1 then 'checks if data was recieved goto picout 're-send until recieved endif serout2 rsoutpin, 16468, ["SUCCESS|",str message\12,"|"] 'tell computer if outqued < qued then outqued = outqued +1 'move to next qued item goto picout 'proceed to transmit it. else serout2 rsoutpin, 16468, ["|ALL",DEC (qued+1),"items transmitted succesfully|"] qued=0 goto pcin endif end
It is important that you attribute for the pause 7 in the master in the slaves procedure to prevent the master from constantly retransmitting the first message in the que.
This is the modified recieve part of the function which allows the mserv slave to recieve any number of messages in a row.
:MSslave:
Code:'############################SLAVE RECIEVE################################ '###################################################################### recieve: '----send serial request, and get user input for motor drive timeout 70 ms high picoutpin '---- serin2 picinpin, 16468,20,drivemotor, [dec2 servonum[0],skip 1,_ dec3 rate[0],skip 1,dec3 position[0],skip 1,donecommanding[0],_ dec2 servonum[1],skip 1,dec3 rate[1],skip 1,dec3 position[1],skip 1,_ donecommanding[1]] if servonum[0]!=servonum[1] or rate[0]!=rate[1] or _ position[0]!=position[1] or donecommanding[0]!=donecommanding[1] then 'data is bad recieve again goto recieve 'try again endif low picoutpin '----- 'setup the servo chosen goalarray[servonum-1]=position[0] 'set servo goal ratearray[servonum-1]=rate[0] 'set servo rate ' 'allow for multiple commands. if donecommanding[0] = "n" then pause 7 'pause long enough to make sure master does not attempt retrans. goto recieve endif goto drivemotor
Last edited by gandora; - 29th May 2007 at 08:31.
Okay so that wasn't too hard.
The master transmitter now uses pretty much all of the ram available on the 16F88 as a buffer. Allowing 16 commands to be stored and transmitted from 2 seperate buffers.
I am pretty sure I will not be needing more then that for this project and so here it is.
:MSmaster:
Code:'**************************************************************** '* Name : MSERVMASTER.BAS * '* Author : Joseph Dattilo * '* Notice : Copyright (c) 2007 Joseph Dattilo * '* : All Rights Reserved * '* Date : 5/25/2007 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** define OSC 8 OSCCON = %1111110 ' sets internal osc to run at 8MHZ '----------turn analog on porta off, and use as digital input/output '----------this is used to allow serial input on the A bus. CMCON = 7 'Comparators OFF ANSEL = 0 'A/D OFF -- Port pins all digital '---------- '---**Pins rsoutpin var porta.0 rsinpin var porta.1 picinpin var portb.4 picoutpin var portb.5 porta=0 portb=0 '---vars temp var byte qued var byte outqued var byte message var byte[24] '-up to 8 commands can be buffered in each que array adding up to 16 altogether. que var byte[96] que2 var byte[96] '--------------- qued = 0 'set number in que to 0 goto pcin '############################## pc recieve ################################ 'que up messages from pc '########################################################################## pcin: '---- let pc know we are ready to recieve message. serout2 rsoutpin, 16468, ["waiting!"] 'call for data '---- ready to recieve message serin2 rsinpin, 16468, [str message\24] '------------------------------------------------------------------------ 'compare both arrays checking for bad data if data bad request it again. for temp = 0 to 11 : if message[temp] <> message[temp+12] then goto baddata next temp '------------------------------------------------------------------------ serout2 rsoutpin, 16468, [str message\12] 'send confirmation of reciept. '------------------inque----------------- for temp = 0 to 11 if qued<8 then 'add to first que que[(12*qued)+temp]=message[temp] else 'add to second que que2[(12*(qued-8))+temp]=message[temp] endif next temp if qued>7 then serout2 rsoutpin, 16468, ["Que 1:",str que\96, _ "Que 2:",str que2\(12*(qued-8)+12)] else serout2 rsoutpin, 16468, ["Que 1:",str que\(12*qued+12)] 'display all in que endif '---------------------------------------- if message[11] = "n" and qued<15 then serout2 rsoutpin, 16468, ["still more commands!?"] 'debug statement qued=qued+1 'go to next position in que goto pcin 'request the data for the next item. else outqued = 0 'set picout que start position to 0 (first item in que first) goto picout 'we are ready to command the servo controller. endif '------------------------- 'where bad data takes you. baddata: serout2 rsoutpin, 16468, ["bad data!"] goto pcin '------------------------- '############################## pic transmit ############################# '---- picout procedure waits for high on picinpin and then transmits data '######################################################################### picout: '---------------------unque next item into message array for temp = 0 to 11 if outqued<8 then 'add to first que message[temp]=que[(12*outqued)+temp] message[temp+12]=que[(12*outqued)+temp] else 'add to second que message[temp]=que2[(12*(outqued-8))+temp] message[temp+12]=que2[(12*(outqued-8))+temp] endif next temp '------------------------------------------------------- input picinpin while picinpin = 0 pause 1 wend serout2 picoutpin, 16468, [str message\24] pause 7 if picinpin = 1 then 'checks if data was recieved goto picout 're-send until recieved endif serout2 rsoutpin, 16468, ["SUCCESS|",str message\12,"|"] 'tell computer if outqued < qued then outqued = outqued +1 'move to next qued item goto picout 'proceed to transmit it. else serout2 rsoutpin, 16468, ["|ALL",DEC (qued+1),"items transmitted succesfully|"] qued=0 goto pcin endif end
As a note no changes need be made to the slave from last version for cross compatability.
Bookmarks