אני ממשתמש במצפן דיגיטלי מסוג CMPS03 בשיטת PWM.
אני עובד איתו עם כרטיס FPGA של XILINX מסוג SPARTAN 3
כתבתי קוד של VHDL שיראה את המעלות של המצפן על ה SEVEN SEGMENT שמצורף על הכרטיס.
הבעיה היא שהוא מראה את כל המעלות מ 0 עד 355, ומ 355 הוא מדלג ישר ל-360
אולי אני לא מבין את הפעולה של הPWM - לדעתי זה קשור משהו ל OFFSET שמצוין ב DATASHEET שלו שנמצא בכתובת הבאה:http://www.robotstorehk.com/CMPS03_release.pdf
מצורף כאן גם הקוד של המצפן שכתבתי.
בתודה מראש
אלון
הקוד:
- קוד: בחר הכל
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity CMPS is
port ( clk: in std_logic;
pwm: in std_logic;
rst: in std_logic;
degrees : out integer RANGE 0 to 360
);
end CMPS;
architecture arc_CMPS of CMPS is
begin
process(clk,pwm,rst)
variable one_deg_counter : integer RANGE 0 to 4999 := 0 ;
variable degrees_counter : integer RANGE 0 to 360 := 0;
variable first_time : std_logic;
variable offset : integer RANGE 0 to 50000 := 0;
begin
if(rst='1') then --executing reset command
degrees <= 0;
first_time := '1';
elsif(clk'event and clk='1') then
if( pwm = '1') then
first_time := '1';
if(one_deg_counter < 4999) then -- according to a clock of 50MHz this is the clocks amount for 1 degree.
one_deg_counter := one_deg_counter +1;
elsif(degrees_counter < 360) then -- meanging we need to reset that counter and increase the degrees
one_deg_counter := 0;
degrees_counter := degrees_counter + 1;
else
one_deg_counter := 0;
end if;
else --pwm equals 0 meaning this is the low time between 2 samples
if(first_time = '1') then
degrees <= degrees_counter; --
first_time := '0';
end if;
degrees_counter :=0;
one_deg_counter := 0;
offset :=0;
end if;
end if;
end process;
end arc_CMPS;



