Is it Just Me

oracacle

Senior Member
Is it just me who reads back code and finds you get confused on why you did something, and once you've re-read the entire code find its a clever way to reduce code space or processing times?

just recently I have been writing new code for the macro rail to account for internally focusing lenses, and instead of loading 2 constants to the fpu and running a different sum (and there for needing 2 large i2c commands) I alter the FPU constant between the required states. This had the affect of removing the addition of an extra 4 if statements.

alas that programme was abandoned due to constraints in another programme slot. Moving to use uM FPU functions and the additional if statements save about 100 bytes of programme space in the latest version of the programme. In the end the updated sub procedures saved 10 lines of code, 8 hi2couts, 2 i2cin, 2 if statements and added 4 new if statements. I am o not sure how it compares in the form of speed, but I should imagine it would not be slower as there is less time transmitting on the i2c bus

A bit of random 5AM thought I know, but I cant the only one who surprises themselves when they look back at old code.

an old sub
Code:
[color=Black]increment:
      [/color][color=Blue]if [/color][color=Purple]tempbyte [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then
            [/color][color=Green]'increment width
            [/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uwidth[/color][color=Black], [/color][color=Blue]fadd[/color][color=Black], [/color][color=Blue]tfloat0)
            hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uwidth[/color][color=Black], [/color][color=Blue]fcmp[/color][color=Black], [/color][color=Blue]tfloat1)           [/color][color=Green]'>300
            [/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](readstatus)
            hi2cin [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Purple]status[/color][color=Blue])
            if [/color][color=Purple]status [/color][color=DarkCyan]= [/color][color=Navy]128 [/color][color=Blue]then
                  hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uwidth[/color][color=Black], [/color][color=Blue]fsub[/color][color=Black], [/color][color=Blue]tfloat0)
            end if
      else
            [/color][color=Green]'increment hight
            [/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uhight[/color][color=Black], [/color][color=Blue]fadd[/color][color=Black], [/color][color=Blue]tfloat0)
            hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uhight[/color][color=Black], [/color][color=Blue]fcmp[/color][color=Black], [/color][color=Blue]tfloat1)
            hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](readstatus)
            hi2cin [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Purple]status[/color][color=Blue])
            if [/color][color=Purple]status [/color][color=DarkCyan]= [/color][color=Navy]128 [/color][color=Blue]then
                  hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uhight[/color][color=Black], [/color][color=Blue]fsub[/color][color=Black], [/color][color=Blue]tfloat0)
            end if 
      end if
      gosub [/color][color=Black]display
      [/color][color=Blue]return[/color]
a new sub
Code:
[color=Black]increment:
      [/color][color=Blue]if [/color][color=Purple]tempbyte [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then
            [/color][color=Green]'increment width
            [/color][color=Blue]if [/color][color=Purple]tempbyte1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
                  hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](fcall[/color][color=Black], [/color][color=Blue]inc_sens_width_deci)
            else
                  hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](fcall[/color][color=Black], [/color][color=Blue]inc_sens_width_unit)
            end if
      else
            [/color][color=Green]'increment hight
            [/color][color=Blue]if [/color][color=Purple]tempbyte1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
                  hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](fcall[/color][color=Black], [/color][color=Blue]inc_sens_hight_deci)
            else
                  hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](fcall[/color][color=Black], [/color][color=Blue]inc_sens_hight_unit)
            end if 
      end if
      gosub [/color][color=Black]display
      [/color][color=Blue]return[/color]
pre compiled FPU code for increasing the unit width
Code:
#function inc_sens_width_unit
uwidth = uwidth + 1
if uwidth > 300 then
	uwidth = uwidth - 1
endif
and post compling
Code:
  ' #function inc_sens_width_unit
  ' uwidth = uwidth + 1
  ' ;;	SELECTA, 23
  ' ;;	FADDI, 1
  ' if uwidth > 300 then
  ' ;;	LOADWORD, 300
  ' ;;	FCMP2, 23, 0
  ' ;;	PJMP, LE, __3
  ' 	uwidth = uwidth - 1
  ' ;;	SELECTA, 23
  ' ;;	FSUBI, 1
  ' endif
  ' ;;__3:
 

bpowell

Senior Member
I really enjoy coding...to me, it's like doing a crossword, or sudoku....it's just a puzzle that's fun to figure out.

I won't lie and say there haven't been frustrations along the way...but all in all, it's been fun!
 

ZOR

Senior Member
The simulator should be removed from the program editor so we can all go bonkers together
 

oracacle

Senior Member
could be, but I don't use it often at all. I find myself using a breadboard to test things.
The uM FPU cant be simulated so it has to be tested on hardware
And then there is the projects that use more than one picaxe, or programmes that uses more than one programme slot, that can get very interesting as you have to test everything on hardware, be it a close approximation of the final design or the actual hardware you plan on using. its where the debug and serial com come into there own, and running more than one instance at a time so that you can debug more than one picaxe in a system at once is really very handy
 

inglewoodpete

Senior Member
The simulator should be removed from the program editor so we can all go bonkers together
The simulator may as well not be there for me. Practically never used - I prefer the real thing.

So, back to your question, my answer is 'yes' :).
 

tmfkam

Senior Member
I like the simulator. I find it really useful when first fleshing out the idea I've formulated in my head. I also use it for trying to track those nagging, intermittent errors that I insist on writing into my code. Like passing $010 to a variable when I actually meant $00a (decimal 10), or using a byte variable that I've foolishly used elsewhere as part of a word variable. For many things, breadboard or Veroboard is the way to go for a prototype, but for looking into how the code runs [or more often than not, doesn't run], the simulator is an enormous help to me.

I wish there was one that worked as well, and as reliably for the equivalent PIC devices (16F1825/1829?). I've been advised that MPLAB can import an .asm file produced by a *competing* compiler and will simulate the program operation. Once I get time, I'm going to look into this.
 

erco

Senior Member
And is it just me: Often I have a problem, search diligently for hours, finally give in and post a question in the forum, then stumble across the answer just milliseconds after I click "Submit"?
 
Top