reading sequential eeprom addresses, syntax problem using the data

moorea21

Senior Member
I'm away from my pc with all the picaxe stuff on it, trying to write the (hopefully) last piece of code while I have some time, but not able to compile/run/test it for a week or so, so this is probably going to be rubbish code anyway...

This should hopefully compute the value of b1, which gets used as the eeprom address to start from to look up 4 bytes of data, and use them with a pwm output.

Elabel:
b1 = b1 - 12: b1 = b1 / 2: b1 = b1 + 63: gosub playNote

playNote:
symbol Address = b1 'typical data would be m4,4,158,316
read Address,b10
Address = Address + 1
read Address,b11
Address = Address + 1
read Address,b12
Address = Address + 1
read Address,b13

setfreq b10: pwmout pwmdiv b11, C.2, b12, b13
etc

There must be a less clumsy way of reading 4 bytes of eeprom into variables? It looks awful!
I'm sure that 'pwmdiv b11' wouldnt work either.

Can anyone suggest the proper way to do this? I have a block of time off, but no access to my computer, and the flu. Not the best combination...
 

hippy

Technical Support
Staff member
You could simply use -

Code:
read Address, b10, b11, b12, b13
If you explicitly wanted to adjust Address as the code executes or to reduce code size slightly you can probably make things look better by putting two commands on one line ...

Code:
read Address, b10 : Address = Address + 1
read Address, b11 : Address = Address + 1
read Address, b12 : Address = Address + 1
read Address, b13
Or alternatively, which some people may consider more aesthetically pleasing -

Code:
Address = Address + 1 : read Address, b10
Address = Address + 1 : read Address, b11
Address = Address + 1 : read Address, b12
Address = Address + 1 : read Address, b13
Though you would have to set the initial Address one lower than in the existing example.

You could put much of it inside a Macro if you wanted but I would tend to just put it into a subroutine as you have, put that towards the end of the program, forget about it, and not worry that it might seem a bit clunky.

You can move the calculation of Address into your 'playNote' routine to save having to calculate it every time before calling 'playNote'.
 

hippy

Technical Support
Staff member
I'm sure that 'pwmdiv b11' wouldnt work either.
You are correct on that. But you can do ...

Code:
select case b11
  case  1 : pwmout           C.2, b12, b13
  case  4 : pwmout pwmdiv4,  C.2, b12, b13
  case 16 : pwmout pwmdiv16, C.2, b12, b13
  case 64 : pwmout pwmdiv64, C.2, b12, b13
end select
 

moorea21

Senior Member
Ah, so much better! Especially the last one, solves 2 problems at once.

I'm look forward to testing that now, although I have noticed that some of my data is > 255, so not sure how the eeprom is handling that, although the DATA section of the code compiled ok. Also in order to end up with something like

'pwmout pwmdiv16, C.2, 252, 504'

I think I need w not b variables.
 
Top