Posted: Sat Jul 18, 2009 6:12 am
Is this the part of the slave code you are talking about?
low MasterBus ;Turn on MasterBus Optocoupler (Reqd due to sink driven)
serout MasterBus,Baud2400,(VData) ;Send VData (b0) to Master at Baud2400
high MasterBus ;Turn off MasterBus Optocoupler (Reqd due to sink driven)
low SlaveBusOut ;Turn on interrupt signal for next Slave (SlaveBusOut)
Pause Delay ;Allow time for next Slave and Master to be ready
high SlaveBusOut ;Turn off interrupt signal for next Slave (SlaveBusOut)
I don't think even I can fully explain it now, except to say the slave optos are sink driven for better low voltage effciency. However being sink driven that means the optos are on when the Pin 5 is low. I found the serial commands did not work without the low/high commands. So the data is inverted from what you would expect when using the N1200 command. This is why the Master uses the T1200 command in the receiver section.
Of course looking at it again now my own logic does not make sense and there is probably a much simpler solution like a High MasterBus command at the program start!
Of course I found all this out by trial and error.
Feel free to change the code for a simpler version if you can get it to work.
I've actually been thinking about sending a pulse of length (X) instead of serial data using the PULSOUT command to transfer the Cell Voltage as this would be simpler. Running the 08M Slaves at 8mhz the pulse time is in 5us units.
PULSOUT MasterBus, VData ;Sends a pulse on the Master Bus equivalent to VData x 5us
Using PULSIN on the Master it can measure the length of the pulse and recreate the cell voltage.
PULSIN MasterBus , 1 , VData ;Receives the pulse in the Master
If no Pulse is received within the timeout period (0.32seconds at 8mhz) then we can jump to the error routine as we do now with any serial comms error. If the value in VData was 255 (Max) then that would take 255 x 5us to transmit or 1.275ms per Slave. Pretty fast and much faster than the serial comms! Hmm looks interesting. Could speed up the comms a lot!
We would need a High MasterBus instruction at the begining of the Slave software to turn the MasterBus opto off, because PULSOUT inverts the state of the pin. Then whenever it sends a pulse we get the desired signal out.
If the really short pulses proved inaccurate or prone to noise we could simply x 10 everything and take a more leisurely 12.75ms per slave to transmit the longest (highest possible voltage) VData pulse.
In fact thinking even more we could get rid of the squeezing the data into one byte system I used.
So we could send the full Voltage Value using the Word Variable CellVoltage!!!
PULSOUT MasterBus, CellVoltage ;Sends a pulse on the Master Bus equivalent to CellVoltage x 5us
This avoid all the adding and subtracting 175 from variables at both ends!!
Edit
Try this Digital Slave software and look at the Master Bus signal with a scope.
www.solarvan.co.uk/bms/SLAVESIMPLEDIGIT ... _PULSE.TXT
Ignore the stupid google warning!!!!!
low MasterBus ;Turn on MasterBus Optocoupler (Reqd due to sink driven)
serout MasterBus,Baud2400,(VData) ;Send VData (b0) to Master at Baud2400
high MasterBus ;Turn off MasterBus Optocoupler (Reqd due to sink driven)
low SlaveBusOut ;Turn on interrupt signal for next Slave (SlaveBusOut)
Pause Delay ;Allow time for next Slave and Master to be ready
high SlaveBusOut ;Turn off interrupt signal for next Slave (SlaveBusOut)
I don't think even I can fully explain it now, except to say the slave optos are sink driven for better low voltage effciency. However being sink driven that means the optos are on when the Pin 5 is low. I found the serial commands did not work without the low/high commands. So the data is inverted from what you would expect when using the N1200 command. This is why the Master uses the T1200 command in the receiver section.
Of course looking at it again now my own logic does not make sense and there is probably a much simpler solution like a High MasterBus command at the program start!
Of course I found all this out by trial and error.
Feel free to change the code for a simpler version if you can get it to work.
I've actually been thinking about sending a pulse of length (X) instead of serial data using the PULSOUT command to transfer the Cell Voltage as this would be simpler. Running the 08M Slaves at 8mhz the pulse time is in 5us units.
PULSOUT MasterBus, VData ;Sends a pulse on the Master Bus equivalent to VData x 5us
Using PULSIN on the Master it can measure the length of the pulse and recreate the cell voltage.
PULSIN MasterBus , 1 , VData ;Receives the pulse in the Master
If no Pulse is received within the timeout period (0.32seconds at 8mhz) then we can jump to the error routine as we do now with any serial comms error. If the value in VData was 255 (Max) then that would take 255 x 5us to transmit or 1.275ms per Slave. Pretty fast and much faster than the serial comms! Hmm looks interesting. Could speed up the comms a lot!
We would need a High MasterBus instruction at the begining of the Slave software to turn the MasterBus opto off, because PULSOUT inverts the state of the pin. Then whenever it sends a pulse we get the desired signal out.
If the really short pulses proved inaccurate or prone to noise we could simply x 10 everything and take a more leisurely 12.75ms per slave to transmit the longest (highest possible voltage) VData pulse.
In fact thinking even more we could get rid of the squeezing the data into one byte system I used.
So we could send the full Voltage Value using the Word Variable CellVoltage!!!
PULSOUT MasterBus, CellVoltage ;Sends a pulse on the Master Bus equivalent to CellVoltage x 5us
This avoid all the adding and subtracting 175 from variables at both ends!!
Edit
Try this Digital Slave software and look at the Master Bus signal with a scope.
www.solarvan.co.uk/bms/SLAVESIMPLEDIGIT ... _PULSE.TXT
Ignore the stupid google warning!!!!!