ZappBots wishes a warm welcome to everyone.

Especially our visitors from
Savage///Circuits and Parallax!!!


Please take a look our new forums, we hope you register and become an active user.

The ZappBots forums are being run on phpBB 3.1.4 software which is different then the vBulletin used on the Savage///Circuits and Parallax forums.
Therefore, things look and work a little different, especially creating posts and uploading images / attachments.


The important thing is we have a place toTalk, Learn and Showcase our projects.

Eye Activated Switch

This is the place to talk about Bio-Medical Electronics
User avatar
Electrons-R-Fun
Member
Member
Posts: 128
Joined: Tue May 12, 2015 7:03 pm
Contact:

Re: Eye Activated Switch

Postby Electrons-R-Fun » Wed Aug 31, 2016 1:37 am

Have not heard back from sensor company. So I will just purchase some pediatric sensors and try them out and/or only place the sensors on Lisa during the day and take them off at night,88 so here skin can breathe.

Chris,

After looking at the code I am not sure about 2 parts of it.

First the absolute value, I believe you did that in case the system clock counter flipped back to zero and the first value was taken before the the clock counter flipped back to zero. I'd there other reasons besides always returning a positive value?

Second, I don't know why shift/bitwise was used at the end of the code. Yeah got nothing, as of now?

Jason

User avatar
Savage///Circuits
VIP
VIP
Posts: 344
Joined: Tue May 12, 2015 2:43 pm
Location: Plumas Lake, CA
Contact:

Re: Eye Activated Switch

Postby Savage///Circuits » Fri Sep 02, 2016 4:24 pm

Jason,

I understand your confusion and that is partly my fault. First, let's break things down since the multiple nested parenthesis imply orders of operations. That is, things that must be done first. I also failed to address the shift right. So in the following line:

Code: Select all

Microseconds := (||(cnt1 - cnt2) / (clkfreq / 1_000_000)) >> 1


First cnt2 is subtracted from cnt1. Since the counter is always counting up you might assume that cnt2 will always be a larger value and therefore the result will be negative. In fact, while it could be, the counter could also roll over back to zero resulting in things being the opposite. Because of the 2's complement nature of math on the Propeller what we end up with is the total number of ticks between the two captured counter values. However this value may be positive or negative at this point.

Second clkfreq is divided by 1,000,000 to give us the number of ticks in one microsecond. So at 80 MHz this will be 80.

Third the || operator returns the absolute value of the cnt1 - cnt2 operation. So if the result was 127 it still is. If it was -127 it is now 127.

Fourth that result is divided by the 80 from the previous result of the clkfreq calculation (assuming 80 MHz).

At this point you now have the number of microseconds between the two counter capture points.

If you were measuring in µs you'd be done. The reason the shift right is there is it divides the value by 2. This is because the PING))) is returning the round trip time, but we only need one way. So for you, you don't need that shift. In fact, you would change the part (clkfreq / 1_000_000) to adjust for the resolution of time you want.
Image
I'm only responsible for what I say, not what you understand.

User avatar
Savage///Circuits
VIP
VIP
Posts: 344
Joined: Tue May 12, 2015 2:43 pm
Location: Plumas Lake, CA
Contact:

Re: Eye Activated Switch

Postby Savage///Circuits » Thu Sep 08, 2016 4:24 pm

I made a few small changes to make my explanation clear. Did it help at all?
Image
I'm only responsible for what I say, not what you understand.

User avatar
Electrons-R-Fun
Member
Member
Posts: 128
Joined: Tue May 12, 2015 7:03 pm
Contact:

Re: Eye Activated Switch

Postby Electrons-R-Fun » Fri Sep 09, 2016 12:31 am

Chris,

So sorry I didn't reply to your post or put up a video yet. I ended up getting Central serous retinopathy (CSR), which is to say I have lost vision in my right eye, In my case it is very bad 850 microns of fluid build up. Doing everything is very frustrating for me. Bread boards are really difficult because I have no depth perception and writing and reading code is odd, at best.

Free advice.... :D, don't take on too much stress, the stress will win.

Jason

User avatar
Savage///Circuits
VIP
VIP
Posts: 344
Joined: Tue May 12, 2015 2:43 pm
Location: Plumas Lake, CA
Contact:

Re: Eye Activated Switch

Postby Savage///Circuits » Fri Sep 09, 2016 3:15 pm

Good advice! Sorry to hear about this. I have several family members experiencing A.I.O.N. and a colleague who had a detached retina. Not at all easy to deal with in our fields/hobbies.

https://en.wikipedia.org/wiki/Anterior_ ... neuropathy
Image
I'm only responsible for what I say, not what you understand.

User avatar
Electrons-R-Fun
Member
Member
Posts: 128
Joined: Tue May 12, 2015 7:03 pm
Contact:

Re: Eye Activated Switch

Postby Electrons-R-Fun » Mon Sep 12, 2016 2:22 pm

Hey Chris,

Just wanted to work on a reply.

let's break things down since the multiple nested parenthesis imply orders of operations. That is, things that must be done first.


I believe I understand the parenthesis thing, it's just like in math.

First cnt2 is subtracted from cnt1. Since the counter is always counting up you might assume that cnt2 will always be a larger value and therefore the result will be negative. In fact, while it could be, the counter could also roll over back to zero resulting in things being the opposite.


I believe I understand this also, The counter on the propeller counts to a very large value, (possibly a 32 bit number) and then starts over again from 0. Since the counter is always counting "up" I have no Idea when Lisa is going to invoke the code count, there is no way of knowing where in the count the cnt1 value will be selected, and by the time the cnt2 value is selected the counter could have "rolled over" back to zero(that's what I call it) therefore possibly giving me a negative value,(and I think the most computers don't really know how to handle negative values. I believe I could also use code

Code: Select all

Microseconds := (||(cnt2 - cnt1) / (clkfreq / 1_000_000)) >> 1


I changed the position of cnt1 and cnt2 because since we are taking the absolute value of their difference it would work out the same.

Because of the 2's complement nature of math on the Propeller what we end up with is the total number of ticks between the two captured counter values. However this value may be positive or negative at this point


Not really sure about the "2's complement nature of math"? but I think you mean, the propeller is a computer and computers only understand binary (on/off) so the math is done in binary. The rest of that sentence I understand.

If I made any errors in typing I'm blaming it on being in a hurry and using one eye. :D

Jason

Second clkfreq is divided by 1,000,000 to give us the number of ticks in one microsecond. So at 80 MHz this will be 80.


Fourth that result is divided by the 80 from the previous result of the clkfreq calculation (assuming 80 MHz).


these two are related and I believe your meaning is that at

Code: Select all

CON

    _xinfreq = 5_000_000                     
    _clkmode = xtal1 + pll16x


I tend to think of the above explanation like this
when the code is set for the recommended max speed on the propeller (80 MHz) clkfreq is directly related to the set speed in the CON section of the code, well actually I guess it's not only related but it is.

As an example I could write the code below to mean the same thing, wait one second at 80 MHz

Code: Select all

waitcnt(clkfreq + cnt)

  waitcnt(80_000_000 + cnt)


or also kinda like your code method for returning time in Milliseconds

Code: Select all

PRI Delay(MS)

  waitcnt(clkfreq / 1_000 + cnt)

  waitcnt(80_000_000 / 1_000 + cnt)
I added the second part.



At this point you now have the number of microseconds between the two counter capture points.


I believe this is what I am really after but as a positive number.

If you were measuring in µs you'd be done. The reason the shift right is there is it divides the value by 2. This is because the PING))) is returning the round trip time, but we only need one way. So for you, you don't need that shift. In fact, you would change the part (clkfreq / 1_000_000) to adjust for the resolution of time you want.


I understand how to get the resolution degree I would like to use, but I'm not really sure about the PING part. I am not sure if you are referring to the actual PING sensor that uses sound to bounce off of an object a certain distance away (so there and back at the speed of sound, which changes at temperature and altitude by the way.) or if you are saying I am PINGING the propeller counter and that is the "one way" part you are referring to as far as total time (there and back) for ping to be measured. I think in my case, the ping, is simply the amount of time the propeller takes to execute the piece of code, which is in SPIN so I think it is around (can't remember so I take first guess) 10 microseconds.

User avatar
Savage///Circuits
VIP
VIP
Posts: 344
Joined: Tue May 12, 2015 2:43 pm
Location: Plumas Lake, CA
Contact:

Re: Eye Activated Switch

Postby Savage///Circuits » Thu Sep 15, 2016 2:56 pm

When I posted that code I mentioned it was from the PING))) object, so that's what I am referring to when I mention not needing the shift.

For your purposes the only thing you would need to change is to take off the >> 1 and change the section that sets the resolution. Everything else is where it needs to be, including the order of the subtraction. No need to reverse those.
Image
I'm only responsible for what I say, not what you understand.


Return to “Bio-Medical Electronics”

Who is online

Users browsing this forum: No registered users and 2 guests