Hi all, looking to have some of you smart guys to review my code for a project I am working on. Ihave tried to encorprate you previous comments. Please review my code. Question do I need to put in the "Wait 9890 us 'To allow last two bytes Tx" on the send data sub?
Thanks, in advance Ed.
'Chip model#chip 18F4455, 40#config MCLRE = On'Configure Usart#define USART_BAUD_RATE 2400#define USART_BLOCKING'Transmit dataSubSendData'Send power monitor dataCallSendCRC'Caculate CRCSetSPEN=Off'Turn Usart off to prevent interferance from pulseoutSetT/R=Off'Turn Off Rx turn on Txwait1000us'Transmitter delay Typical = 490 uspulseoutPortC.6,12ms'Init RecieverSetSPEN=On'Turn Usart onHSerSendSolar1A_hHSerSendSolar1AHSerSendSolar2A_hHSerSendSolar2AHSerSendWindA_hHSerSendWindAHSerSendTEGA_hHSerSendTEGAHSerSendBattAVG_hHSerSendBattAVGHSerSendETimeHrs_hHSerSendETimeHrsHSerSendS1TimeHrs_hHSerSendS1TimeHrsHSerSendS2TimeHrs_hHSerSendS2TimeHrs_hHSerSendWindTimeHrs_hHSerSendWindTimeHrsHSerSendTEGTimeHrs_hHSerSendTEGTimeHrsHSerSendCRCWait9890us'To allow last two bytes TxSetT/R=On'Turn off Tx turn on RxsetCREN=On'Turn Receiver Onwait400us'Receiver delay Typical = 180 usReturn'Recieve dataSubReceiveDataSolar1A_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalSolar1A=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2Solar2A_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2Solar2A=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2WindA_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2WindA=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2TEGA_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2TEGA=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2BattAVG_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2BattAVG=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2ETimeHrs_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2ETimeHrs=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2S1TimeHrs_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2S1TimeHrs=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2S2TimeHrs_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2ETS2_hrs=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2WindTimeHrs_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2WindTimeHrs=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2TEGTimeHrs_h=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2TEGTimeHrs=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2Cs=HserReceive1RSSIS=ReadAD10(AN0)'Read RSSI with signalRSSISAvg=(RSSISAvg+RSSIS)/2CallRECCRCIfCs<>CRCthenDataErrors=DataErrors+1SetCRCRED=OnElsesetCRCGREEN=onWait10msEndIfSetCREN=Off'Turn Receiver offwait10ms'Wait for RSSI to settleRSSISampleNS=ReadAD10(AN0)'Read RSSI with no signalRSSISamplesNSAVG=(RSSISamplesNSAVG+RSSISamplesNS)/2RSSISampleNS=ReadAD10(AN0)'Read RSSI with no signalRSSISamplesNSAVG=(RSSISamplesNSAVG+RSSISamplesNS)/2RSSISampleNS=ReadAD10(AN0)'Read RSSI with no signalRSSISamplesNSAVG=(RSSISamplesNSAVG+RSSISamplesNS)/2setCREN=OnReturn
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Some formating errors. Each "Sub" needs an "End Sub" instead of a "return".
The if then else needs to rearrange. Look these up in help. Also when you "call" a sub you don't need to use "Call", just use the name of the sub.
I assume these two subs are in different processors?
The setup of the HSer routines looks right but is missing the "dir" of the Hserial ports. Remember to set them up.
In the sending , you are using "Blocking", so the usart is waiting for the input register to be empty before putting the next byte in.
In receiving, with "blocking", you are waiting for the next new byte to come in, for each of your variables.
You asked if you should wait 9.8 ms for the transmit USART to clear. If USART was always enabled on, I would not think you would need the "wait" because the USART will clear itself by sending what is in the shift register, transfering the byte from the Tx input register, and shifting that out.. But you are turning the USART on and off, so i think you need to wait for the USART to finish before shutting it off.
I like the " linear programming" of the HSerSends. it makes it easy to read. But a coder would probably put all the variables into an array and then use a loop to send the array. Same for the receive.
Any questions? please ask!
GL
73
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Also, this will not complile under v.0.95.006 (due out this weekend). These types of errors are not found in earlier releases of GCB - I am improving the pre-processor all the time.
08:47:05 G+Stool-COMPILE/ASSEMBLE, processing C:\GCB@Syn\G+Stools\makeHEX.bat
Source-File = C:\GCB@Syn\GreatCowBasic\Demos\code.gcb
6.0 Sec. <<< WARNINGs / ERRORs while compiling!
Doubleclick on errormessage below to go to sourcecode-line:
first-start-sample.gcb (9): Error: Missing Function/Sub definition
first-start-sample.gcb (114): Error: If-Else line has continous code - not permitted. Place code on next line
Line 41 and the same at line 127 - needs to be a End Sub. Whilst Return will work you may have issues with code using Exit Sub
Line 114 - you need to put the code after the else on the next line. I think the 'set CRCGREEN = on' is as risk of not being compiled. I would correct rather than wade thru the ASM.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all, looking to have some of you smart guys to review my code for a project I am working on. Ihave tried to encorprate you previous comments. Please review my code. Question do I need to put in the "Wait 9890 us 'To allow last two bytes Tx" on the send data sub?
Thanks, in advance Ed.
Some formating errors. Each "Sub" needs an "End Sub" instead of a "return".
The if then else needs to rearrange. Look these up in help. Also when you "call" a sub you don't need to use "Call", just use the name of the sub.
I assume these two subs are in different processors?
The setup of the HSer routines looks right but is missing the "dir" of the Hserial ports. Remember to set them up.
In the sending , you are using "Blocking", so the usart is waiting for the input register to be empty before putting the next byte in.
In receiving, with "blocking", you are waiting for the next new byte to come in, for each of your variables.
You asked if you should wait 9.8 ms for the transmit USART to clear. If USART was always enabled on, I would not think you would need the "wait" because the USART will clear itself by sending what is in the shift register, transfering the byte from the Tx input register, and shifting that out.. But you are turning the USART on and off, so i think you need to wait for the USART to finish before shutting it off.
I like the " linear programming" of the HSerSends. it makes it easy to read. But a coder would probably put all the variables into an array and then use a loop to send the array. Same for the receive.
Any questions? please ask!
GL
73
Mike
Also, this will not complile under v.0.95.006 (due out this weekend). These types of errors are not found in earlier releases of GCB - I am improving the pre-processor all the time.
08:47:05 G+Stool-COMPILE/ASSEMBLE, processing C:\GCB@Syn\G+Stools\makeHEX.bat
Source-File = C:\GCB@Syn\GreatCowBasic\Demos\code.gcb
6.0 Sec. <<< WARNINGs / ERRORs while compiling!
Doubleclick on errormessage below to go to sourcecode-line:
first-start-sample.gcb (9): Error: Missing Function/Sub definition
first-start-sample.gcb (114): Error: If-Else line has continous code - not permitted. Place code on next line
and,
first-start-sample.gcb (44): Error: Missing Function/Sub definition
Line 41 and the same at line 127 - needs to be a End Sub. Whilst Return will work you may have issues with code using Exit Sub
Line 114 - you need to put the code after the else on the next line. I think the 'set CRCGREEN = on' is as risk of not being compiled. I would correct rather than wade thru the ASM.
Thanks, Mmotte and Evan. Have made the changes. Regards, Ed.