F
Fred Bartoli
Guest
Hello,
I have 2 fsm that are clocked on different and asynchronous clocks.
The first INSTR_fsm (clocked on CPLD_EXEC) executes some commands issued on
a serial bus. Basically it updates different registers.
The second GATING_fsm (clocked on Ck1600kHz) drives some signals for a fast
acquisition process.
In GATING_fsm I have a Hold_St where the acquired value is held and I wait
for the measurement to be completed by an external ADC (slow) before going
to the StartIntegrate_St or StartGate_St state for another measurement
cycle.
The state transition to StartIntegrate_St or StartGate_St is triggered by a
software acknowledge sent to the INSTR_fsm.
So basically what I have to do is have a MeasReaf flag ff that is set by the
GATING_fsm when entering the Hold_St state, used as a condition still in
GATING_fsm and is reset in CMD_fsm on a special command.
How can I do that in behavioral description ? I mean I'm an hardware guy
and I've tried hard to stay away from what is my first inclination, i.e.
thinking in hardware, so as to have good code clarity...
Oh, strong constrain is the final CPLD size : I can only afford 64MC thanks
to package size.
I also welcome any comment/suggestion about the programming style...
Thanks very much for your time.
Fred.
Here's the code :
-- **************************************************************
-- Serial communication register
-- **************************************************************
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY Ser2Par is
generic ( WIDTH : integer := 8 );
port (
Clk : in std_logic;
SerIn : in std_logic;
ParOut : out std_logic_vector ( WIDTH-1 downto 0);
SerOut : out std_logic
);
END Ser2Par;
ARCHITECTURE behv of Ser2Par is
constant clockEdge : std_logic := '1';
signal Q : std_logic_vector(WIDTH-1 downto 0);
BEGIN
--------------------------------------------------------------------------
----
shr: process(Clk)
--------------------------------------------------------------------------
----
begin
if (Clk = clockEdge and Clk'event) then
Q <= SerIn & Q(WIDTH-1 downto 1);
end if;
end process shr;
--------------------------------------------------------------------------
----
ParOut <= Q;
SerOut <= Q(0);
END behv;
-- **************************************************************
-- Gating counter
-- **************************************************************
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY PRBS_10 is
Port (
Clk : in std_logic;
Load : in std_logic;
Input : in std_logic_vector (9 downto 0);
EndCount: out std_logic );
END PRBS_10;
ARCHITECTURE behv of PRBS_10 is
signal Q: std_logic_vector (9 downto 0);
BEGIN
--------------------------------------------------------------------------
----
counter: process(Clk, Load, Input)
--------------------------------------------------------------------------
----
variable Count : std_logic_vector (9 downto 0);
begin
if Load = '1' then
Count := Input ;
elsif (Clk='0' and Clk'event) then
Count := Q(8 downto 0) & (Q(9) xor Q(6)) ;
end if;
Q <= Count;
end process counter;
--------------------------------------------------------------------------
----
EndCount <= '1' when Q = b"1111111111" else '0';
END behv;
-- **************************************************************
-- Clock predivider
-- **************************************************************
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY Ck100K_div is
Port (
Clk : In std_logic;
Rst : In std_logic;
CkDiv : Out std_logic
);
END Ck100K_div;
ARCHITECTURE behavior of Ck100K_div is
BEGIN
--------------------------------------------------------------------------
----
counter: process(Clk, Rst)
--------------------------------------------------------------------------
----
variable Count: Natural range 0 to 15;
begin
if (Rst = '1') then
count := 0;
elsif falling_edge(Clk) then -- Count is advanced by 1/2 clock cycle to
account for the
count := (count+1) mod 16; -- gating state machine 1 cycle delay when
stopping counting.
end if;
if (Count >= 8) then
CkDiv <= '1';
else
CkDiv <= '0';
end if;
end process counter;
--------------------------------------------------------------------------
----
END behavior;
-- **************************************************************
-- CPLD instance
-- **************************************************************
--library metamor;
--use metamor.attributes.all;
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
ENTITY CPLD is
port (
Ck_1600KHz : in std_logic := '0';
GATE_TRIG : in std_logic := '0';
CPLD_EXEC : in std_logic := '0';
SER_DATA : in std_logic := '0';
SER_CLK : in std_logic := '0';
CPLD_DATA : out std_logic;
CPU_REQ : out std_logic;
CalGen_Clk : out std_logic;
CalGen_Dat : out std_logic;
PRESET_ENABLE : out std_logic;
nCOS_HOLD_P : out std_logic;
nCOS_HOLD_M : out std_logic;
nSIN_HOLD_P : out std_logic;
nSIN_HOLD_M : out std_logic;
nIF_SAMPLE : out std_logic;
TEMP_A : out std_logic_vector(2 downto 0);
PRESET_A : out std_logic_vector(1 downto 0)
);
-- attribute pinnum of Ck_1600KHz : signal is "37";
-- attribute pinnum of GATE_TRIG : signal is "12";
-- attribute pinnum of CPLD_EXEC : signal is "2";
-- attribute pinnum of SER_DATA : signal is "11";
-- attribute pinnum of SER_CLK : signal is "10";
--
-- attribute pinnum of CPLD_DATA : signal is "3";
-- attribute pinnum of CPU_REQ : signal is "5";
-- attribute pinnum of CalGen_Clk : signal is "33";
-- attribute pinnum of CalGen_Dat : signal is "34";
-- attribute pinnum of PRESET_ENABLE: signal is "19";
-- attribute pinnum of nCOS_HOLD_P : signal is "18";
-- attribute pinnum of nCOS_HOLD_M : signal is "22";
-- attribute pinnum of nSIN_HOLD_P : signal is "23";
-- attribute pinnum of nSIN_HOLD_M : signal is "25";
-- attribute pinnum of nIF_SAMPLE : signal is "27";
--
-- attribute pinnum of TEMP_A : signal is "31,30,28";
-- attribute pinnum of PRESET_A : signal is "21,20";
END CPLD;
ARCHITECTURE structure of CPLD is
use work.all;
use work.IF_CPLD_types.all;
signal GateLoadBus : std_logic_vector ( 9 downto 0);
signal SerComBus : op;
alias SerComParm1 : std_logic is SerComBus(0);
alias SerComParm1_2 : std_logic is SerComBus(1);
alias SerComParm1_3 : std_logic is SerComBus(2);
alias SerComParm2 : std_logic_vector (1 downto 0) is SercomBus (1 downto
0);
alias SerComParm3 : std_logic_vector (2 downto 0) is SercomBus (2 downto
0);
signal Internal_100kHz_Clk : std_logic; -- internal 100KHz clock
signal CalEnable : std_logic;
signal GatingEnable : std_logic;
signal GateCounterLoad : std_logic;
signal GateEnd : std_logic; -- Pulses when Gatecounter ends.
signal PresetOn : std_logic; -- PresetEnable default states
signal PresetMode : std_logic;
signal PresetGating : std_logic; --
signal RstCalDiv : std_logic; -- Resets the 100kHz clock divider
signal SinHold_P : std_logic;
signal SinHold_M : std_logic;
signal CosHold_P : std_logic;
signal CosHold_M : std_logic;
signal IFsample : std_logic;
signal Integrate : std_logic;
signal MeasRead : std_logic;
type GatingStates is (StartIntegrate_St, StartGate_St, Hold_St,
WaitTrig_St, Count_St);
signal GatingState : GatingStates;
BEGIN
nSIN_HOLD_P <= not SinHold_P;
nSIN_HOLD_M <= not SinHold_M;
nCOS_HOLD_P <= not CosHold_P;
nCOS_HOLD_M <= not CosHold_M;
nIF_SAMPLE <= IFsample;
-- *************************************
-- Microcontroler interface
SerialComm: entity Ser2Par port map ( Clk=>SER_CLK, SerIn=>SER_DATA,
ParOut=>SerComBus, SerOut=>CPLD_DATA);
-- *************************************
-- Gating system
GateCounter: entity PRBS_10 port map (Clk=>Internal_100kHz_Clk ,
Load=>GateCounterLoad, Input=>GateLoadBus, EndCount=> GateEnd);
-- *************************************
-- Dividing and synchronizing the 1.6MHz clock for calibration generator and
Gate counter clocking.
CalClk_div: entity Ck100K_div port map (Clk=>Ck_1600KHz, Rst=> RstCalDiv,
CkDiv=>Internal_100kHz_Clk );
CalGen_Dat <= CalEnable and Internal_100kHz_Clk;
CalGen_Clk <= NOT Ck_1600KHz;
-- *************************************
-- Instruction process state machine
--------------------------------------------------------------------------
----
instr_fsm : process (CPLD_EXEC)
--------------------------------------------------------------------------
----
type Instr_state is (InstrFetch_St,LoadGateCountFetch_St);
variable Instr_St : Instr_state;
variable CurrentOp : op;
begin
if rising_edge(CPLD_EXEC) then
CurrentOp := SerComBus and op_mask;
-- op_LoadGateCount
case Instr_St is
when InstrFetch_St =>
case CurrentOp is
when op_LoadGateCount =>
Instr_St := LoadGateCountFetch_St;
GateLoadBus (9 downto 8) <= SerComParm2;
when op_LoadTempChannel =>
TEMP_A <= SerComParm3;
when op_LoadPresetChannel =>
PRESET_A <= SerComParm2;
PresetOn <= SerComParm1_3;
when op_EnablePresetMode =>
-- PresetMode <= SerComParm1_2;
when op_ReadStatus =>
null;
when op_EnableCalibration =>
CalEnable <= SerComParm1;
when op_EnableGating =>
GatingEnable <= SerComParm1;
when op_MeasRead =>
MeasRead <= '1';
when op_Integrate =>
Integrate <= SerComParm1;
when others =>
null;
end case;
when LoadGateCountFetch_St =>
Instr_St := InstrFetch_St;
GateLoadBus (7 downto 0) <= SerCombus;
end case;
end if;
end process;
-- *************************************
-- Gating handling state machine
--------------------------------------------------------------------------
----
Gating_fsm: process (Ck_1600KHz, GatingEnable, CalEnable)
--------------------------------------------------------------------------
----
-- type GatingStates is (StartIntegrate_St, StartGate_St, Hold_St,
WaitTrig_St, Count_St);
variable Gating_St : GatingStates;
-- variable GatingState : GatingStates;
variable Sampling : std_logic;
variable xHold : std_logic;
begin
if (GatingEnable = '0') then -- (continuous sampling mode)
Gating_St := StartIntegrate_St;
RstCalDiv <= not CalEnable;
GateCounterLoad <= '0';
-- PresetGating <= PresetOn; --'0';
PRESET_ENABLE <= PresetOn;
SinHold_P <= '0'; -- Averaging mode for all the outputs
SinHold_M <= '0';
CosHold_P <= '0';
CosHold_M <= '0';
IFSample <= '1'; -- (continuous sampling)
elsif rising_edge(Ck_1600KHz) then -- (gated sampling mode)
case Gating_St is
when StartIntegrate_St =>
if GATE_TRIG = '1' then
Gating_St := WaitTrig_St;
end if;
when StartGate_St =>
if GATE_TRIG = '1' then
Gating_St := WaitTrig_St;
end if;
when WaitTrig_St =>
if GATE_TRIG = '0' then
Gating_St := Count_St;
end if;
when Count_St =>
if GateEnd = '1' then
Gating_St := Hold_St;
end if;
when Hold_St =>
if MeasRead = '1' then
if Integrate = '1' then
Gating_St := StartIntegrate_St;
else
Gating_St := StartGate_St;
end if;
end if;
when others =>
Gating_St := StartIntegrate_St;
end case;
case Gating_St is
when StartIntegrate_St =>
GateCounterLoad <= '1'; -- Load the PRBS counter
RstCalDiv <= '1'; -- Stop the 100kHz gate counter clock
Sampling := '0';
PRESET_ENABLE <= '0';
xHold := '0';
MeasRead <= '0';
-- PresetGating <= '1';
when StartGate_St =>
GateCounterLoad <= '1'; -- Load the PRBS counter
RstCalDiv <= '1'; -- Stop the 100kHz gate counter clock
Sampling := '0';
PRESET_ENABLE <= '1';
xHold := '1';
MeasRead <= '0';
-- PresetGating <= '1';
when WaitTrig_St =>
GateCounterLoad <= '0'; -- Release it and wait for trigger
Sampling := '0';
PRESET_ENABLE <= '0';
xHold := '1';
-- PresetGating <= '0';
when Count_St =>
RstCalDiv <= '0'; -- Allow internal 100kHz clock for gate count
Sampling := '1';
when Hold_St =>
GateCounterLoad <= '1'; -- Load the PRBS counter
RstCalDiv <= '1'; -- Stop the 100kHz gate counter clock
Sampling := '0';
PRESET_ENABLE <= '1';
xHold := '1';
-- PresetGating <= '1';
end case;
SinHold_P <= Sampling; -- Average mode for all the outputs during gate
sampling
SinHold_M <= Sampling;
CosHold_P <= Sampling;
CosHold_M <= Sampling;
IFSample <= not Sampling; -- (Sample)
GatingState <= GatingStates'val(GatingStates'pos(Gating_St)); -- Just to
show correct SM states
end if;
end process;
--PRESET_ENABLE <= (PresetGating and GatingEnable) or ((not GatingEnable)
and PresetOn) ;
END structure;
I have 2 fsm that are clocked on different and asynchronous clocks.
The first INSTR_fsm (clocked on CPLD_EXEC) executes some commands issued on
a serial bus. Basically it updates different registers.
The second GATING_fsm (clocked on Ck1600kHz) drives some signals for a fast
acquisition process.
In GATING_fsm I have a Hold_St where the acquired value is held and I wait
for the measurement to be completed by an external ADC (slow) before going
to the StartIntegrate_St or StartGate_St state for another measurement
cycle.
The state transition to StartIntegrate_St or StartGate_St is triggered by a
software acknowledge sent to the INSTR_fsm.
So basically what I have to do is have a MeasReaf flag ff that is set by the
GATING_fsm when entering the Hold_St state, used as a condition still in
GATING_fsm and is reset in CMD_fsm on a special command.
How can I do that in behavioral description ? I mean I'm an hardware guy
and I've tried hard to stay away from what is my first inclination, i.e.
thinking in hardware, so as to have good code clarity...
Oh, strong constrain is the final CPLD size : I can only afford 64MC thanks
to package size.
I also welcome any comment/suggestion about the programming style...
Thanks very much for your time.
Fred.
Here's the code :
-- **************************************************************
-- Serial communication register
-- **************************************************************
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY Ser2Par is
generic ( WIDTH : integer := 8 );
port (
Clk : in std_logic;
SerIn : in std_logic;
ParOut : out std_logic_vector ( WIDTH-1 downto 0);
SerOut : out std_logic
);
END Ser2Par;
ARCHITECTURE behv of Ser2Par is
constant clockEdge : std_logic := '1';
signal Q : std_logic_vector(WIDTH-1 downto 0);
BEGIN
--------------------------------------------------------------------------
----
shr: process(Clk)
--------------------------------------------------------------------------
----
begin
if (Clk = clockEdge and Clk'event) then
Q <= SerIn & Q(WIDTH-1 downto 1);
end if;
end process shr;
--------------------------------------------------------------------------
----
ParOut <= Q;
SerOut <= Q(0);
END behv;
-- **************************************************************
-- Gating counter
-- **************************************************************
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY PRBS_10 is
Port (
Clk : in std_logic;
Load : in std_logic;
Input : in std_logic_vector (9 downto 0);
EndCount: out std_logic );
END PRBS_10;
ARCHITECTURE behv of PRBS_10 is
signal Q: std_logic_vector (9 downto 0);
BEGIN
--------------------------------------------------------------------------
----
counter: process(Clk, Load, Input)
--------------------------------------------------------------------------
----
variable Count : std_logic_vector (9 downto 0);
begin
if Load = '1' then
Count := Input ;
elsif (Clk='0' and Clk'event) then
Count := Q(8 downto 0) & (Q(9) xor Q(6)) ;
end if;
Q <= Count;
end process counter;
--------------------------------------------------------------------------
----
EndCount <= '1' when Q = b"1111111111" else '0';
END behv;
-- **************************************************************
-- Clock predivider
-- **************************************************************
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY Ck100K_div is
Port (
Clk : In std_logic;
Rst : In std_logic;
CkDiv : Out std_logic
);
END Ck100K_div;
ARCHITECTURE behavior of Ck100K_div is
BEGIN
--------------------------------------------------------------------------
----
counter: process(Clk, Rst)
--------------------------------------------------------------------------
----
variable Count: Natural range 0 to 15;
begin
if (Rst = '1') then
count := 0;
elsif falling_edge(Clk) then -- Count is advanced by 1/2 clock cycle to
account for the
count := (count+1) mod 16; -- gating state machine 1 cycle delay when
stopping counting.
end if;
if (Count >= 8) then
CkDiv <= '1';
else
CkDiv <= '0';
end if;
end process counter;
--------------------------------------------------------------------------
----
END behavior;
-- **************************************************************
-- CPLD instance
-- **************************************************************
--library metamor;
--use metamor.attributes.all;
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
ENTITY CPLD is
port (
Ck_1600KHz : in std_logic := '0';
GATE_TRIG : in std_logic := '0';
CPLD_EXEC : in std_logic := '0';
SER_DATA : in std_logic := '0';
SER_CLK : in std_logic := '0';
CPLD_DATA : out std_logic;
CPU_REQ : out std_logic;
CalGen_Clk : out std_logic;
CalGen_Dat : out std_logic;
PRESET_ENABLE : out std_logic;
nCOS_HOLD_P : out std_logic;
nCOS_HOLD_M : out std_logic;
nSIN_HOLD_P : out std_logic;
nSIN_HOLD_M : out std_logic;
nIF_SAMPLE : out std_logic;
TEMP_A : out std_logic_vector(2 downto 0);
PRESET_A : out std_logic_vector(1 downto 0)
);
-- attribute pinnum of Ck_1600KHz : signal is "37";
-- attribute pinnum of GATE_TRIG : signal is "12";
-- attribute pinnum of CPLD_EXEC : signal is "2";
-- attribute pinnum of SER_DATA : signal is "11";
-- attribute pinnum of SER_CLK : signal is "10";
--
-- attribute pinnum of CPLD_DATA : signal is "3";
-- attribute pinnum of CPU_REQ : signal is "5";
-- attribute pinnum of CalGen_Clk : signal is "33";
-- attribute pinnum of CalGen_Dat : signal is "34";
-- attribute pinnum of PRESET_ENABLE: signal is "19";
-- attribute pinnum of nCOS_HOLD_P : signal is "18";
-- attribute pinnum of nCOS_HOLD_M : signal is "22";
-- attribute pinnum of nSIN_HOLD_P : signal is "23";
-- attribute pinnum of nSIN_HOLD_M : signal is "25";
-- attribute pinnum of nIF_SAMPLE : signal is "27";
--
-- attribute pinnum of TEMP_A : signal is "31,30,28";
-- attribute pinnum of PRESET_A : signal is "21,20";
END CPLD;
ARCHITECTURE structure of CPLD is
use work.all;
use work.IF_CPLD_types.all;
signal GateLoadBus : std_logic_vector ( 9 downto 0);
signal SerComBus : op;
alias SerComParm1 : std_logic is SerComBus(0);
alias SerComParm1_2 : std_logic is SerComBus(1);
alias SerComParm1_3 : std_logic is SerComBus(2);
alias SerComParm2 : std_logic_vector (1 downto 0) is SercomBus (1 downto
0);
alias SerComParm3 : std_logic_vector (2 downto 0) is SercomBus (2 downto
0);
signal Internal_100kHz_Clk : std_logic; -- internal 100KHz clock
signal CalEnable : std_logic;
signal GatingEnable : std_logic;
signal GateCounterLoad : std_logic;
signal GateEnd : std_logic; -- Pulses when Gatecounter ends.
signal PresetOn : std_logic; -- PresetEnable default states
signal PresetMode : std_logic;
signal PresetGating : std_logic; --
signal RstCalDiv : std_logic; -- Resets the 100kHz clock divider
signal SinHold_P : std_logic;
signal SinHold_M : std_logic;
signal CosHold_P : std_logic;
signal CosHold_M : std_logic;
signal IFsample : std_logic;
signal Integrate : std_logic;
signal MeasRead : std_logic;
type GatingStates is (StartIntegrate_St, StartGate_St, Hold_St,
WaitTrig_St, Count_St);
signal GatingState : GatingStates;
BEGIN
nSIN_HOLD_P <= not SinHold_P;
nSIN_HOLD_M <= not SinHold_M;
nCOS_HOLD_P <= not CosHold_P;
nCOS_HOLD_M <= not CosHold_M;
nIF_SAMPLE <= IFsample;
-- *************************************
-- Microcontroler interface
SerialComm: entity Ser2Par port map ( Clk=>SER_CLK, SerIn=>SER_DATA,
ParOut=>SerComBus, SerOut=>CPLD_DATA);
-- *************************************
-- Gating system
GateCounter: entity PRBS_10 port map (Clk=>Internal_100kHz_Clk ,
Load=>GateCounterLoad, Input=>GateLoadBus, EndCount=> GateEnd);
-- *************************************
-- Dividing and synchronizing the 1.6MHz clock for calibration generator and
Gate counter clocking.
CalClk_div: entity Ck100K_div port map (Clk=>Ck_1600KHz, Rst=> RstCalDiv,
CkDiv=>Internal_100kHz_Clk );
CalGen_Dat <= CalEnable and Internal_100kHz_Clk;
CalGen_Clk <= NOT Ck_1600KHz;
-- *************************************
-- Instruction process state machine
--------------------------------------------------------------------------
----
instr_fsm : process (CPLD_EXEC)
--------------------------------------------------------------------------
----
type Instr_state is (InstrFetch_St,LoadGateCountFetch_St);
variable Instr_St : Instr_state;
variable CurrentOp : op;
begin
if rising_edge(CPLD_EXEC) then
CurrentOp := SerComBus and op_mask;
-- op_LoadGateCount
case Instr_St is
when InstrFetch_St =>
case CurrentOp is
when op_LoadGateCount =>
Instr_St := LoadGateCountFetch_St;
GateLoadBus (9 downto 8) <= SerComParm2;
when op_LoadTempChannel =>
TEMP_A <= SerComParm3;
when op_LoadPresetChannel =>
PRESET_A <= SerComParm2;
PresetOn <= SerComParm1_3;
when op_EnablePresetMode =>
-- PresetMode <= SerComParm1_2;
when op_ReadStatus =>
null;
when op_EnableCalibration =>
CalEnable <= SerComParm1;
when op_EnableGating =>
GatingEnable <= SerComParm1;
when op_MeasRead =>
MeasRead <= '1';
when op_Integrate =>
Integrate <= SerComParm1;
when others =>
null;
end case;
when LoadGateCountFetch_St =>
Instr_St := InstrFetch_St;
GateLoadBus (7 downto 0) <= SerCombus;
end case;
end if;
end process;
-- *************************************
-- Gating handling state machine
--------------------------------------------------------------------------
----
Gating_fsm: process (Ck_1600KHz, GatingEnable, CalEnable)
--------------------------------------------------------------------------
----
-- type GatingStates is (StartIntegrate_St, StartGate_St, Hold_St,
WaitTrig_St, Count_St);
variable Gating_St : GatingStates;
-- variable GatingState : GatingStates;
variable Sampling : std_logic;
variable xHold : std_logic;
begin
if (GatingEnable = '0') then -- (continuous sampling mode)
Gating_St := StartIntegrate_St;
RstCalDiv <= not CalEnable;
GateCounterLoad <= '0';
-- PresetGating <= PresetOn; --'0';
PRESET_ENABLE <= PresetOn;
SinHold_P <= '0'; -- Averaging mode for all the outputs
SinHold_M <= '0';
CosHold_P <= '0';
CosHold_M <= '0';
IFSample <= '1'; -- (continuous sampling)
elsif rising_edge(Ck_1600KHz) then -- (gated sampling mode)
case Gating_St is
when StartIntegrate_St =>
if GATE_TRIG = '1' then
Gating_St := WaitTrig_St;
end if;
when StartGate_St =>
if GATE_TRIG = '1' then
Gating_St := WaitTrig_St;
end if;
when WaitTrig_St =>
if GATE_TRIG = '0' then
Gating_St := Count_St;
end if;
when Count_St =>
if GateEnd = '1' then
Gating_St := Hold_St;
end if;
when Hold_St =>
if MeasRead = '1' then
if Integrate = '1' then
Gating_St := StartIntegrate_St;
else
Gating_St := StartGate_St;
end if;
end if;
when others =>
Gating_St := StartIntegrate_St;
end case;
case Gating_St is
when StartIntegrate_St =>
GateCounterLoad <= '1'; -- Load the PRBS counter
RstCalDiv <= '1'; -- Stop the 100kHz gate counter clock
Sampling := '0';
PRESET_ENABLE <= '0';
xHold := '0';
MeasRead <= '0';
-- PresetGating <= '1';
when StartGate_St =>
GateCounterLoad <= '1'; -- Load the PRBS counter
RstCalDiv <= '1'; -- Stop the 100kHz gate counter clock
Sampling := '0';
PRESET_ENABLE <= '1';
xHold := '1';
MeasRead <= '0';
-- PresetGating <= '1';
when WaitTrig_St =>
GateCounterLoad <= '0'; -- Release it and wait for trigger
Sampling := '0';
PRESET_ENABLE <= '0';
xHold := '1';
-- PresetGating <= '0';
when Count_St =>
RstCalDiv <= '0'; -- Allow internal 100kHz clock for gate count
Sampling := '1';
when Hold_St =>
GateCounterLoad <= '1'; -- Load the PRBS counter
RstCalDiv <= '1'; -- Stop the 100kHz gate counter clock
Sampling := '0';
PRESET_ENABLE <= '1';
xHold := '1';
-- PresetGating <= '1';
end case;
SinHold_P <= Sampling; -- Average mode for all the outputs during gate
sampling
SinHold_M <= Sampling;
CosHold_P <= Sampling;
CosHold_M <= Sampling;
IFSample <= not Sampling; -- (Sample)
GatingState <= GatingStates'val(GatingStates'pos(Gating_St)); -- Just to
show correct SM states
end if;
end process;
--PRESET_ENABLE <= (PresetGating and GatingEnable) or ((not GatingEnable)
and PresetOn) ;
END structure;