Forum Discussion
Well here I am again... I follow your advises and I reduced my code in order to see where the error was, and and if I did not found any error I continued the development, but now I am in a crash. Let me explain what I am trying to do. My goal is to create a sinusoidal pattern in a matrix of 168 leds, that way one led will be on while the rest are off in an instant of time, the movement of the light will create the sinusoidal pattern, the frequency and the amplitude (number of leds used) of the pattern are variables and are suministrated in the "in signal" datos, in this stage I am not doing that, so I simule with the variable "seudodatos" this parameters. In order to create the sinusoidal pattern I created a function that calculates the arcsin of the signal, so that way I obtain the time that one led should be on, once that time is consumed I recalculated the time for the next led in the matrix (the sinusoidal pattern has variable speed). Here is my problem.
The first code I post here works perfectly, I am even seeing the leds of my kit blinking with a sinusoidal pattern right now, but when I update the code (this is the second code that I will submit in a second post) it gives me errors. Here is the code:
---- This one works perfectly-----
library ieee;
use ieee.std_logic_1164.all;
use ieee.math_real.all;
use ieee.numeric_std.all;
entity estimulador is
port(--load: in std_logic;
--done,estado_prueba: out bit;
--datos: in std_logic_vector(7 downto 0);
clk: in std_logic;
salida: out unsigned (7 downto 0));
end estimulador;
architecture estimulador_arch of estimulador is
TYPE ROM IS ARRAY(0 TO 169) OF unsigned(7 DOWNTO 0);
TYPE LED IS ARRAY(0 TO 7) OF integer;
TYPE FRECUENCIA_REAL IS ARRAY(0 TO 13) OF real;
TYPE SINUSOIDE IS ARRAY(0 TO 167) OF integer;
constant num_led:LED:=(18,36,54,72,94,116,140,168);
constant freq_prueba:FRECUENCIA_REAL:=(0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5);
constant uno: unsigned:="00000001";
signal seudo_salida: unsigned(7 downto 0);
constant freq_proc: real:=1000000.0;
--------------------------------------------------------------------------
-------------------- FUNCTION FOR CREATING A ROM -------------------------
FUNCTION INIT_ROM RETURN ROM IS
VARIABLE romvar: ROM;
variable suma_salida: unsigned (7 downto 0):=(others => '0');
begin
for i in ROM'range loop
romvar(i):= suma_salida;
suma_salida:= suma_salida + uno;
end loop;
return romvar;
end;
--------------------------------------------------------------------------
CONSTANT rom_salida: ROM := INIT_ROM;
--------------------------------------------------------------------------
-------------- FUNCTION FOR READING FROM THE ROM CREATED -----------------
FUNCTION LEER_ROM (cont: integer) RETURN unsigned IS
variable salidat: unsigned(7 downto 0);
begin
salidat:= rom_salida(cont);
return salidat;
end;
--------------------------------------------------------------------------
---------- FUNCTION FOR CREATING AN ARRAY OF VALUES ----------------------
----------------- FOR THE SINUSOIDAL PATTERN -----------------------------
FUNCTION SIN_INIT (amplitud,frecuencia:integer) RETURN SINUSOIDE IS
variable tabla_sin:SINUSOIDE;
variable cantidad_led:integer:=num_led(amplitud);
variable cantidad_frec:real:=freq_prueba(frecuencia);
variable limite:integer:=cantidad_led/2-1;
variable calculo, diferencia:integer:=0;
begin
for i in 0 to limite loop
calculo:=integer((arcsin(real(i+1)/real(cantidad_led/2))/(2.0 * MATH_PI * cantidad_frec))*freq_proc);
tabla_sin(i):=calculo-diferencia;
tabla_sin(cantidad_led-1-i):=calculo-diferencia;
diferencia:=calculo;
end loop;
if(cantidad_led<168) then
for k in cantidad_led to 167 loop
tabla_sin(k):=0;
end loop;
end if;
return tabla_sin;
end;
-------------------------------------------------------------------------
signal sentido: boolean:=true;
begin
--body of the architecture
PROCESS(clk)
variable tipo_prueba: std_logic_vector(1 downto 0):="10";
variable mostrar, cnt, cnt_sac, recorrido, contador_sin: integer:=0;
variable paso_led, cant_led, offset, centro: integer;
variable primeravez: boolean:=true;
variable tabla_sinusoide:SINUSOIDE;
variable seudodatos1: std_logic_vector(7 downto 0):="00000100";
variable seudodatos2: std_logic_vector(7 downto 0):="00000001";
variable amplitud_bit: std_logic_vector(2 downto 0);
variable frecuencia_bit: std_logic_vector(3 downto 0);
variable numero_led, frecuencia_prueba:integer;
begin
if(rising_edge(clk)) then
cnt:=cnt+1;
if(primeravez=true) then
amplitud_bit:=seudodatos1(4)&seudodatos1(3)&seudodatos1(2);
frecuencia_bit:=seudodatos2(6)&seudodatos2(5)&seudodatos2(4)&seudodatos2(3);
numero_led:=to_integer(unsigned(amplitud_bit));
frecuencia_prueba:=to_integer(unsigned(frecuencia_bit));
if(tipo_prueba="10") then
tabla_sinusoide:=SIN_INIT(numero_led,frecuencia_prueba);
contador_sin:=0;
paso_led:=tabla_sinusoide(contador_sin);
else
null;
-- I check some parameters in here. I "null it" for this publication because does not worth to analyze them
end if;
primeravez:=false;
cant_led:=num_led(numero_led);
recorrido:=cant_led/2;
offset:=84;
centro:=84;
else
if(cnt=paso_led) then
cnt:=0;
CASE tipo_prueba IS
WHEN "00" => null;
-- I check some parameters in here. I "null it" for this publication because does not worth to analyze them
WHEN "01" => null;
-- I check some parameters in here. I "null it" for this publication because does not worth to analyze them
WHEN OTHERS=>if(sentido=true) then
offset:=offset+1;
if(offset=centro+recorrido) then sentido<=false;
end if;
elsif(sentido=false) then
offset:=offset-1;
if(offset=centro-recorrido) then sentido<=true;
end if;
end if;
contador_sin:=contador_sin+1;
if(contador_sin=cant_led) then
contador_sin:=0;
end if;
paso_led:=tabla_sinusoide(contador_sin);
end CASE;
end if;
seudo_salida<= LEER_ROM(offset);
end if;
end if;
end process;
salida<=seudo_salida;
end estimulador_arch;