Sending cnt in bytes
Hello folks,
Once again I have come back with a question and I would really appreciate your help!
I am trying to send the System Counter register (cnt) through a serial line in bytes to a device that needs some sort of time update. However cnt is 32 bits (long) and I need to split it up since I am sending 8bit packets (1 byte) at a time. I am not too good with bit shifting so could someone lend a helping a hand on how to split up this 32 bit long variable into 4 separate bytes?
Looking at the parallax propeller manual on page 219 it states that if I am using a 5MHz crystal than 50,000 cycles is about 10 ms (1/100th second) of time. So is it safe to assume that 1 cycle is equal to .2 microseconds? (1cycle*(10ms/50,000cycles)=.0002ms = .2 microseconds?
Thank you,
Robert
Once again I have come back with a question and I would really appreciate your help!
I am trying to send the System Counter register (cnt) through a serial line in bytes to a device that needs some sort of time update. However cnt is 32 bits (long) and I need to split it up since I am sending 8bit packets (1 byte) at a time. I am not too good with bit shifting so could someone lend a helping a hand on how to split up this 32 bit long variable into 4 separate bytes?
Looking at the parallax propeller manual on page 219 it states that if I am using a 5MHz crystal than 50,000 cycles is about 10 ms (1/100th second) of time. So is it safe to assume that 1 cycle is equal to .2 microseconds? (1cycle*(10ms/50,000cycles)=.0002ms = .2 microseconds?
Thank you,
Robert

Comments
value := cnt repeat 4 fds.tx(value) value >>= 8 ' LSB firstorvalue := cnt repeat n from 0 to 3 fds.tx(value.byte[n])Assuming you actually run @5MHz then yes, this is correct. Usually PLL is added as well which will give you 80MHz (12.5ns).long value PUB SendDataByte(Data) '' Sends a serial data BYTE to two seperate locations if ina[USB_Rx] == 0 '' Check to see if USB port is powered outa[USB_Tx] := 0 '' Force Propeller Tx line LOW if USB not connected else COMport1.tx(Data) COMport2.tx(Data) PUB VersionRequest | n if U_Flag == 0 '' Normal version reply SendDataString(string("1.0")) ------------------------------------ value := cnt repeat n from 0 to 3 SendDataByte(value.byte[n]) ------------------------------------ else U_Flag := 0 '' Make the PSC compatible with the PSCI SendDataString(string("!SCVER?",13,"1.0"))int currenttime; char version[8] = {0x21,0x53,0x43,0x56,0x45,0x52,0x3F,'\r'}; //!SCVER? \r write(tty_fd1,version,8); if (read(tty_fd1,buffer1,19)>0) { if(buffer1[0] == '1' && buffer1[1] == '.' && buffer1[2] == '0') //check for snp packets and euler angles data type { currenttime = (int)(buffer1[3]+(buffer1[4]<<8)+(buffer1[5]<<16)+(buffer1[6]<<24)); printf("v1.0 %d\n\r",currenttime); } }Any ideas? I think I am shifting all the bits back into their correct location. The code reads the 1.0 (checked) but not the currenttime..
Is this correct:
long chksum PUB VersionRequest | n if U_Flag == 0 '' Normal version reply SendDataString(string("1.0")) value := cnt repeat n from 0 to 3 SendDataByte(value.byte[n]) chksum := chksum + value.byte[n] repeat n from 0 to 1 SendDataByte(chksum.byte[n])Something like that:
PUB VersionRequest | n, chksum if U_Flag == 0 '' Normal version reply SendDataString(string("1.0")) chksum := "1" + "." + "0" value := cnt repeat n from 0 to 3 SendDataByte(value.byte[n]) chksum += value.byte[n] SendDataByte(chksum.byte[0])Usually only one byte for the checksum is used (the lowest byte of the sum). This has enough information to verify the correct transmission.Andy