Need code optimization help
RickH
Posts: 40
I'm working on integrating my stamps into 1 stamp project to free some others up. Currently my code works fine. I have just ran out of room in EPROM trying to make room in RAM. This is an example I will show you.
Their must be a less code intensive way to do this. The goal is to check to see if MIDIValue_6 has changed from last time sub was run(The If Statement). Then I load my Bits into a byte and send it out. Then I transfer my bits into 7 bits representing the current state of the value. I have in doing this freed up about a word in RAM but I have also used up almost all of my Rom in the process. Is their a more effitiont way of doing this.
Post Edited (RickH) : 5/20/2008 10:47:54 AM GMT
IF NOT ADCLast_6(0) = MIDIValue_6(0) OR NOT ADCLast_6(1) = MIDIValue_6(1) OR NOT ADCLast_6(2) = MIDIValue_6(2) OR NOT ADCLast_6(3) = MIDIValue_6(3) OR NOT ADCLast_6(4) = MIDIValue_6(4) OR NOT ADCLast_6(5) = MIDIValue_6(5) OR NOT ADCLast_6(6) = MIDIValue_6(6) THEN MIDICon.BIT0 = MIDIValue_6(6) MIDICon.BIT1 = MIDIValue_6(5) MIDICon.BIT2 = MIDIValue_6(4) MIDICon.BIT3 = MIDIValue_6(3) MIDICon.BIT4 = MIDIValue_6(2) MIDICon.BIT5 = MIDIValue_6(1) MIDICon.BIT6 = MIDIValue_6(0) SEROUT MidiOut, MidiBaud, [noparse][[/noparse]MIDICC, CCSelection20_6, MIDICon] ADCLast_6(0) = MIDIValue_6(0) ADCLast_6(1) = MIDIValue_6(1) ADCLast_6(2) = MIDIValue_6(2) ADCLast_6(3) = MIDIValue_6(3) ADCLast_6(4) = MIDIValue_6(4) ADCLast_6(5) = MIDIValue_6(5) ADCLast_6(6) = MIDIValue_6(6) ENDIF
Their must be a less code intensive way to do this. The goal is to check to see if MIDIValue_6 has changed from last time sub was run(The If Statement). Then I load my Bits into a byte and send it out. Then I transfer my bits into 7 bits representing the current state of the value. I have in doing this freed up about a word in RAM but I have also used up almost all of my Rom in the process. Is their a more effitiont way of doing this.
Post Edited (RickH) : 5/20/2008 10:47:54 AM GMT
Comments
IF··ADCLast_6 <> MIDIValue_6 THEN
then you would need to transfer the value of MIDIValue_6 to ADCLast_6 in preparation for the next comparison.
ADCLast_6=MIDIValue_6
now·transfer the value of MIDIValue_6 to· MIDICon for the serial output
MIDICon=MIDIValue_6
it looks as though you are reversing the bit pattern, if you are substitute the above line with
MIDICon=MIDIValue_6 REV 7
END IF
Jeff T.
I was up too long last night working on this [noparse]:)[/noparse]
this is a litle bit more optimized -
for each midi value I have saved about 2 full lines in the EPROM. at the moment I'm about half way used EPROM so I'm still trying to optimize it a bit more.
Post Edited (RickH) : 5/20/2008 12:44:05 AM GMT
Midicon = 0 ' Clear it in preparation...
For I = 6 downto 0
Midicon = MidiValue_6(I)
Midicon *2 ' This 'shifts' Midicon up one bit.
NEXT
Midicon now holds the MidiValue bits.
How can I optimize this even more than it already is? I'm thinking of using RAM Addresses insted of VARiabls. I may be able to shorten up the·following statment if I do.
·Is the Case Select more optimized than a bunch if IF then Statments? I'm using quite a big Case Select with 8 case statments.
That is just a sketchy snippet, not complete. No CASE statement necessary--The address is computed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
·Now I'm working on getting the code ready for when my IC2 chips get hear. I'm garantied to have enough memory now lol.
Another question I'm wondering about is, the PCF8574 IC2 chip has an INT pin to indicate when data has changed on its bus. Is it as simple as tying a 4.7K pullup resistor and adding it to pin 10 to monitor a change insted of scanning the chip ever so often?
Hear is my updated code, let me kow what you think.