Spin to PASM code conversion help for Ping Sensor
Tony B.
Posts: 356
I am working to learn PASM and need some help with a line of code from the Ping.spin object available with the Propeller tool Library. The line I am having trouble translating is the following line which involves division of two values located at the end of PUB Ticks.
Microseconds := (||(cnt1 - cnt2) / (clkfreq / 1_000_000)) >> 1
I have researched the issue online and studied the math examples in appendix B of the Propeller Manual and understand that division is done by subtraction. Having never written this type of code I am not familiarwith the process of using subtraction to do division nor how to translate it into PASM. Also, unlike the example in the Propeller Manual I'm not concerned with the remainder, but just need the absolutevalue like the "||" gives in the Spin code. In other words do I use "||" in PASM and if so, how?
Since I will be running at 80Mhz I can evaluate the second value, clkfreq/1_000_000, but the first will be different each time. I also understand that shifting the final value 1 place to the right is like dividing by 2 those removing the return time in the value.
I will first use this code on my Spin Stamp BOE-Bot that I am programing completely in PASM. I have the servos working and hopefully the Ping sensor and will have it roaming around in no time. Then I plan on adding a Serial LCD and will have to learn how to do simple bit banging. Been studying and working on the code, but may need some help in the future. But I will work on one issue at a time.
Guidance and help would be most appreciated.
Thanks,
Tony
Microseconds := (||(cnt1 - cnt2) / (clkfreq / 1_000_000)) >> 1
I have researched the issue online and studied the math examples in appendix B of the Propeller Manual and understand that division is done by subtraction. Having never written this type of code I am not familiarwith the process of using subtraction to do division nor how to translate it into PASM. Also, unlike the example in the Propeller Manual I'm not concerned with the remainder, but just need the absolutevalue like the "||" gives in the Spin code. In other words do I use "||" in PASM and if so, how?
Since I will be running at 80Mhz I can evaluate the second value, clkfreq/1_000_000, but the first will be different each time. I also understand that shifting the final value 1 place to the right is like dividing by 2 those removing the return time in the value.
I will first use this code on my Spin Stamp BOE-Bot that I am programing completely in PASM. I have the servos working and hopefully the Ping sensor and will have it roaming around in no time. Then I plan on adding a Serial LCD and will have to learn how to do simple bit banging. Been studying and working on the code, but may need some help in the future. But I will work on one issue at a time.
Guidance and help would be most appreciated.
Thanks,
Tony
Comments
I've been studying your code and I have a question concerning your use of "cnt". I understand "cnt" to be a reserve word for the system counter register and is a read-only register never to be used as a destination register. It appears to me that you are using it in this way. Your wellingness to help me understand this bit of code would be most appreciated.
Thanks,
Tony
Thanks,
Tony