Integer Square Root Calculator (in the UDBs)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Over on the PSoC Sensei Blog, Brad has started posting about my implementation of an Integer Square Root Calculator using datapaths. Here is the component.

   

 

   

A quick overview:

   

8, 16, 24 & 32 bits.

   

In 32-bit mode, takes a 32-bit input and calculates a 16-bit square root in at most 114 clock cycles. Smaller widths are even faster.

   

CPU-mode for easy firmware interaction, DMA-mode for HW-controlled, CPU-free operation.

   

 

   

Even if you have no use for a hardware-based square-root calculator, I think this is another good example of just how flexible and powerful the PSoC datapaths are.

0 Likes
8 Replies
Anonymous
Not applicable
0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hopefully the third time's the charm getting the upload to work.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Is it restrricted to PSoC3 or did I miss something when I tried to compile it for a PSoC5?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 You are correct. This component makes use of "FIFO Dynamic Control" in the datapaths (section 11.3.4 of the Component Author Guide), which is only available on PSoC 3 and PSoC 5LP.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

So I have to speed up the replacement of my old PSoC5 Kits and modules to PSoC5 LP!

   

 

   

Thanx

   

Bob

0 Likes
JamesD_81
Employee
Employee
First like received Welcome!

 Bob,

   

Contact Axel Krepil in the Germany Cypress sales office...tell him I sent you and he'll help you in accelerating your upgrade of moving to PSoC 5LP with our PSoC 5LP Development Kit.  When we were at Embedded World I should have helped you then :).

   

Best regards!

   

Jim 

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

There is now a followup available which shows how to formulate the algorithm so it can be matched to what the data paths does (including showing how the algorithm works on the data path). Great stuff!

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Thank you for making square root component, real gem!

   


While using API _ComputeIsqrtAsync() I noticed that calculation results get corrupted if function called again before the previous calculation is finished. To prevent this issue I use binary flag to indicate that component in the idle mode and ready to accept new data:

   

CYBIT flag_Isqrt_1_Idle = !0; // semaphore flag

   


....

   

// start asyncronous calculation->
if (flag_Isqrt_1_Idle!= 0) {
                    flag_Isqrt_1_Idle = 0;
                    Isqrt_1_ComputeIsqrtAsync(val);
                } 

   

...

   

// get result of calculation->
if (Isqrt_1_AsyncComplete() != 0)           // Isqrt_1 calculation is complete
        {
            uint16 root = Isqrt_1_ReadIsqrtAsync();
            flag_Isqrt_1_Idle = !0; // component goes into idle state
        }

   


Please add the Idle flag to the API to prevent data corruption in asyncronous calculation mode.

0 Likes