Pilot,
You've messed up the variable ordering again!

ax long 1
number long 1
adder long 1
bcdi long 1
bcdlen long 1
bcdstr res 2 'IMPORTANT: overlays digit1/2
digit1 long 1 ' must follow bcdstr
digit2 long 1

EDIT: Ah, I note you've deleted my code. You may as well delete the variables too.

ax long 1
number long 1
adder long 1
digit1 long 1
digit2 long 1

I used a calculator to check that out and it gave me 33.3333. So you are saying to take the remainder the 1 and use that formula. That gives me a new integer and a floating point.

Still not clear in coding the asm for that formula

I used a calculator to check that out and it gave me 33.3333. So you are saying to take the remainder the 1 and use that formula. That gives me a new integer and a floating point.

Still not clear in coding the asm for that formula

I had some laptop problems today and did not get to slowly try to work this. I will try later tonight.

Thanks

What are you dividing by, and how many decimal places do you want?

If you are trying to develop something generally applicable you'll need much more effort than if you are making something specific.

So, for 25/3 the result you'd expect when doing it on a basic calculator is 8.33... (out to the number of digits it can display)
But doing it the old-school (paper) way it would become 8 1/3 (improper fraction)
Now, qdiv gives results of 8 (quotient) and 1 (remainder) which is the improper fraction without the divisor but you already know that.

A specific divide by 3 routine can only give 3 possible results for the remainder (0, 1, & 2)

For a display routine, you could select the number of decimal places you want to display (e.g. 2) and then select a pre-canned string to display (e.g. .00, .33, or .67)

This can work for other divisors too (4: .00, .25, .50, .75)

For a small number of divisors you could create a look-up table of results

You could accommodate the decimal point and three digits in a single long per result and for most applications that would be sufficient.

A simple lookup could be performed with something like (untested)

ALTS dig2, #rem3 'where #rem3 is the address of the table encoding the strings of the remainders for divide by 3
'can have tables for any single integer divisors required and with self-modifying code to replace the table address use the same code loop
MOV temp, 0-0 'temp holds remainder string
REP #3, #4 'print remainder string (S= #4 for 3 digits, #3 for 2 digits)
GETBYTE pa, temp, #0 '0 or 3, depending on encoding order (big-endian or little-endian)
SHR temp, #8 'SHR or SHL, depending on encoding order
CALL #send_char

This would be used in a more generic loop, where you loop dividing by 10 until you get to the decimal point and then use this code for the remainder.

> @msrobots said:
> @AJL
>
> you really make it complicated.
>
> The remainder is the rest left over after calculating the full division. Now since we want a decimal output, the question is how many digits.
>
> So we need to multiply the remainder by 10 for each digit and do the division again for the rest, getting a result and a new remainder.
>
> no need for tables...
>
> Mike

@msrobots,

That is the general approach which is slower (two extra operations) and also requires some effort to deal with rounding (a runtime decision). Sometimes ‘complicated’ is actually simpler when the full context is understood.

Additionally, the OP has already shown some difficulty in understanding what to do with the non-terminating remainders that can result from upstream operations (like dividing 25 by 3 and printing the result). I simply have shown an embedded systems solution that doesn’t rely on floating point libraries. If it works for him what’s the damage to you?

If you care to note, my first question was what he was dividing by.

You guys have been helping me learn how to do math in P2asm.
My goal is to use the math to learn asm as well as to hopefully use it in future projects.

I simply multiplied 7x3 and got 21.
Where does the 20 come from??

What 20? Do you mean the 2 from the GETQY? That 2 is because #itod routine is using cordic QDIV and that's the final remainder it generated. Best solution is grab both components together, eg:

qmul number,multiplier
getqx answer
getqy decimal

Also, your program is going off into la-la-land at the end without any stop or loop. I usually put a JMP to self at the end of my main test routine:

@Parallax
I have tried to read/understand the P2 docu and this thread regarding Syn2 filter mode and Sync3 filter mode. The info given is good enough to activate these modes in my code. But the info is not good enough to be able to rely on these modes. Some other people have stated the same discomfort in this thread. What are the limits, downsides and caveats to use these filters?
In my experience successful engineering is not to make impossible things true but to know limits and respect them.

So let me ask the question, if it is planned to improve the information regarding these modes?
Thank you! Christof

What isn't so great is the noise floor and drift of the internal ADCs.

The sinc2/3 filters work well. They're just extensions of the simpler sinc1 (box filter) that everyone has used before. What they are is second and third order respectively. I didn't understand them at first either, but second order just means it tracks the slope at a squared rate. And third order means it tracks the slope at a cubed rate.

Yes that all applies to the Prop2. The sigma-delta ADC is in the custom laid pad-ring with the low-level I/O circuitry. Whereas the sinc filters are located in the smartpins and streamers, which are part of the synthesised HDL in the Prop2's central region. The pin's IN signal is used to transport the bitstream from the ADC to the smartpin.

## Comments

836Got it working with a good understanding.

Thanks

836Got it working with idot. Thanks and I have a better understanding

about to use the other routine

836Got the dec_to_ascii working and understood with some help from @evanh

Thanks much

836Got the dec_to_ascii from @ersmith working. Now trying to get the remainder from qdiv working. Even numbers are of course zero.

Looking around as to how to get the remainder e.g. 25/3 = 8.33

Any ideas?

Thanks

15,264You've messed up the variable ordering again!

EDIT: Ah, I note you've deleted my code. You may as well delete the variables too.

15,264836I will put it back and try again. Thanks

since I am not a mathemitician, gladly not , how do I make 8 r 1 become 8.33?

Thanks

222You want to decimal places, so you do 1*100/3=33.

15,264836Thanks

836Still not clear in coding the asm for that formula

division

qdiv dividend,divisor

getqx dig1

getqy dig2

mov number ,dig1

call #dec_to_ascii

call #putnl

mov number,dig2

' qmul number,remainder

call #dec_to_ascii

I had some laptop problems today and did not get to slowly try to work this. I will try later tonight.

Thanks

515What are you dividing by, and how many decimal places do you want?

If you are trying to develop something generally applicable you'll need much more effort than if you are making something specific.

So, for 25/3 the result you'd expect when doing it on a basic calculator is 8.33... (out to the number of digits it can display)

But doing it the old-school (paper) way it would become 8 1/3 (improper fraction)

Now, qdiv gives results of 8 (quotient) and 1 (remainder) which is the improper fraction without the divisor but you already know that.

A specific divide by 3 routine can only give 3 possible results for the remainder (0, 1, & 2)

For a display routine, you could select the number of decimal places you want to display (e.g. 2) and then select a pre-canned string to display (e.g. .00, .33, or .67)

This can work for other divisors too (4: .00, .25, .50, .75)

For a small number of divisors you could create a look-up table of results

You could accommodate the decimal point and three digits in a single long per result and for most applications that would be sufficient.

A simple lookup could be performed with something like (untested)

This would be used in a more generic loop, where you loop dividing by 10 until you get to the decimal point and then use this code for the remainder.

3,704you really make it complicated.

The remainder is the rest left over after calculating the full division. Now since we want a decimal output, the question is how many digits.

So we need to multiply the remainder by 10 for each digit and do the division again for the rest, getting a result and a new remainder.

no need for tables...

Mike

515> @AJL

>

> you really make it complicated.

>

> The remainder is the rest left over after calculating the full division. Now since we want a decimal output, the question is how many digits.

>

> So we need to multiply the remainder by 10 for each digit and do the division again for the rest, getting a result and a new remainder.

>

> no need for tables...

>

> Mike

@msrobots,

That is the general approach which is slower (two extra operations) and also requires some effort to deal with rounding (a runtime decision). Sometimes ‘complicated’ is actually simpler when the full context is understood.

Additionally, the OP has already shown some difficulty in understanding what to do with the non-terminating remainders that can result from upstream operations (like dividing 25 by 3 and printing the result). I simply have shown an embedded systems solution that doesn’t rely on floating point libraries. If it works for him what’s the damage to you?

If you care to note, my first question was what he was dividing by.

836@msrobots

Thanks to both of you as well as @evanh

836@msrobots

@evanh

His making it complicated and your making it simple gave me a better understanding.

515Glad to be of assistance.

836@evanh

@msrobots

You guys have been helping me learn how to do math in P2asm.

My goal is to use the math to learn asm as well as to hopefully use it in future projects.

Thanks

836@evanh

@AJL

Is there a plain english version of the P2asm command list??

Thanks

15,264836Thanks

836How are you, been working nights for 5 weeks now back with the living.

Finally got back to coding brain was fried.

I simply multiplied 7x3 and got 21.

Where does the 20 come from??

836Howdy,

I tried to follow what you said and I did not get anything that follows your guidance. What did I screw up.

15,264Also, your program is going off into la-la-land at the end without any stop or loop. I usually put a JMP to self at the end of my main test routine:

836I will rewrite it and try that.

Thanks

1,116@Parallax

I have tried to read/understand the P2 docu and this thread regarding Syn2 filter mode and Sync3 filter mode. The info given is good enough to activate these modes in my code. But the info is not good enough to be able to rely on these modes. Some other people have stated the same discomfort in this thread. What are the limits, downsides and caveats to use these filters?

In my experience successful engineering is not to make impossible things true but to know limits and respect them.

So let me ask the question, if it is planned to improve the information regarding these modes?

Thank you! Christof

15,264What isn't so great is the noise floor and drift of the internal ADCs.

The sinc2/3 filters work well. They're just extensions of the simpler sinc1 (box filter) that everyone has used before. What they are is second and third order respectively. I didn't understand them at first either, but second order just means it tracks the slope at a squared rate. And third order means it tracks the slope at a cubed rate.

1,116Thanks, evanh!

I have found something about frequency response: https://www.ti.com/lit/an/sbaa230/sbaa230.pdf?ts=1631686814131&ref_url=https%3A%2F%2Fwww.google.de%2F

This seems to be good: https://www.digikey.de/de/articles/analog-basics-part-4-optimizing-delta-sigma-adcs-for-low-noise

And some description of a sync3-filter: https://cdn.weka-fachmedien.de/media_uploads/documents/1525877591-240-digitalfilter-fuer-sdm.pdf

Does this apply here?

15,264Yes that all applies to the Prop2. The sigma-delta ADC is in the custom laid pad-ring with the low-level I/O circuitry. Whereas the sinc filters are located in the smartpins and streamers, which are part of the synthesised HDL in the Prop2's central region. The pin's IN signal is used to transport the bitstream from the ADC to the smartpin.

Block diagram - https://forums.parallax.com/discussion/171420/smartpin-diagram/p1

Here's a drawing I did a while back - https://forums.parallax.com/discussion/comment/1484327/#Comment_1484327

Chip posted the real schematic of the ADC here - https://forums.parallax.com/discussion/comment/1510744/#Comment_1510744

1,116Thank you very much, evanh!

This is very helpful, as it answers the question how the accumulators work and also about input impedance.

https://forums.parallax.com/discussion/comment/1484327/#Comment_1484327

This information is needed in the P2 docu!