Pulsin and combining two word variables??

D n T

Senior Member
Using a 28x1
I need to take a reading every either 2 or 5 seconds over 80 minutes, the range of the readings willbe between 0 and about 60, although the majority will be between 5 and 20.
This means that I need to take a total of either:
60/2 x 80 = 2400 readings at every 2 seconds
or
60/5 x 80 = 960 readings at every 5 seconds
With the usual or "average" reading not exceeding 25 this mean that the sum of the readings ( used to calculate the average) will be around
60,000 for every two seconds
24,000 for every five seconds

The pulsin command ( not related to the average sample) uses 65535 as the maximum for its word variable, that means that it is a 16 bit variable ( I think) or two bytes. How do I do that??
b0 is an 8 bit variable and w0 is a 10 bit variable
Do I need to split the binary number and store it in 2 8 bit variables, if so, how, code would be nice or direction to help.
I had a look at manual 2 page 9,19 and it says it can be done with * for the low word and ** for the high word variable, how, a little help, please.:confused:
 

Dippy

Moderator
Dnt: can you have another go at explaining? I'm totally lost.

Are these 2 unconnected questions?
 

gbrusseau

Senior Member
Does anyone remember who's on first? Anyway...

B0 is the lower 8 bits of W0
B1 is the upper 8 bits of W0
TOTAL OF 16 bits for W0

The largest number that W0 can be is 65535. Adding 1 to that will cause W0 to roll over and be 0


With the 2400 readings senerio, just divide W0 by 2400 to get the average. (B2=W0/2400)
With the 960 readings senerio, just divide W0 by 960 to get the average. (B2=W0/960)
 
Last edited:

hippy

Technical Support
Staff member
I think I understand ... You take 1,000 readings of a value between 0 and 60 which can give a sum of 0 to 60,000. As 60,000 fits in a word you're lucky.

Code:
w0 = 0                      ' The sum of all readings
For w2 = 1 To 1000     ' The number of readings
  PulSin PIN, LEVEL, w1 ' The reading 0 to 60
  w0 = w0 + w1          ' Add curent reading to the sum
Next
w3 = w0 / 1000          ' Determine the average
If your PulSins are 0 to 60, you can read into a byte variable ( b13 say ) and then add that to w0 ( w0=w0+b13 ). The PICAXE handles adding 8-bit to 16-bit auto-magically.
 

Dippy

Moderator
Is hippy and Uri Geller the sameperson?

Heck hippy, that was Gold Medal clairvoyance!

What happened to all the '10 bit' words and the **?

Dnt, I hope you teach your kids before midnight :)
 

hippy

Technical Support
Staff member
Guess good clairvoyance comes best when aligned on the same side of midnight :)

I think the key was ignoring the "how I do it", "this doesn't work" and just looked at what was wanted - I had to just go back and re-read to understand what the reference to 10-bit and ** was, I'd simply blanked that out !

Moral there for all posters : Always explain what you're trying to do as well as what isn't working as it helps to polish the crystal ball and give better reception.
 
Top