Altera_Forum
Honored Contributor
17 years agoHow to use altfp_sqrt with the Nios II?
Hi,
for the reason of data processing I need the NiosII to calculate a floating point square root many times. The calculation without extra hardware block is to slow to meet the timing requirements, so want to use the altfp_sqrt megafunction. By the way I need single precision (32bit). I instantiated it with the following inputs and outputs: inputs: clock data[32] outputs: result[32] NaN Overflow Zero I connected the the clock input to a 50MHz clock comming out of the PLL. The input data[] is connected to a 32bit wide PIO output from the NiosII. The result[] is connected to a 32bit wide PIO input of the NiosII. The three status output signals are connected to an external logic analyzer for monitoring purpose. For testing I just write the same value to data input of altfp_sqrt again and again, while waiting until the result port outputs some value greater than 1. Here the code: # include <stdio.h># include <unistd.h># include "system.h"# include "altera_avalon_pio_regs.h" int main() { while(1) { float data = 6025.0; float result = 0.0; do{ IOWR_ALTERA_AVALON_PIO_DATA(SQRT_BASE, data); result = IORD_ALTERA_AVALON_PIO_DATA(SQRT_BASE); }while (result < 1); printf("Wurzel 6025.0 = %ld\n",(long int)result); } } Up to now the value of result is always zero. The zero signal which is monitored on the external logic analyzer stays at high all the time. Maybe someone has an idea what could be the reason. kloocki