Author Topic: Casting problem in VHDL  (Read 3412 times)

0 Members and 1 Guest are viewing this topic.

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1908
  • Country: ca
Casting problem in VHDL
« on: October 18, 2016, 03:11:00 pm »
Hi
I'm kinda new to VHDl, I can not seems to figure out how to do this conversion, what should I do?

Code: [Select]
type myFRQ_BUF0 is array (0 to 7) of STD_LOGIC_VECTOR (47 DOWNTO 0);
signal CapVal_00,CapVal_01 : STD_LOGIC_VECTOR (47 downto 0); 
signal freerun_cnt: STD_LOGIC_VECTOR (31 downto 0); 
signal RMS_BUF0,RMS_BUF1: myRMS_BUF0;

process (clk)
begin
if rising_edge(clk) then

freerun_cnt <= freerun_cnt + '1';

if rising_edge(capture) then
CapVal_01 <= freerun_cnt;
if(CapVal_01 > CapVal_00) then
FRQ_BUF0 <= STD_LOGIC_VECTOR (unsigned(CapVal_01) - unsigned(CapVal_00));
else
FRQ_BUF0 <= STD_LOGIC_VECTOR((unsigned(CapVal_01) + X"100000000000") - unsigned(CapVal_00));
end if;
CapVal_00 <= CapVal_01;
end if;

end if;

end process;



ISE would trough this error

Near std_logic_vector ; type conversion does not match type myfrq_buf0
« Last Edit: October 18, 2016, 03:16:06 pm by ali_asadzadeh »
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline ale500

  • Frequent Contributor
  • **
  • Posts: 415
Re: Casting problem in VHDL
« Reply #1 on: October 18, 2016, 03:27:43 pm »
What is the FRQ_BUF0 definition ?

FRQ_BUF0 <= STD_LOGIC_VECTOR (unsigned(CapVal_01) - unsigned(CapVal_00));
 

Offline Scrts

  • Frequent Contributor
  • **
  • Posts: 797
  • Country: lt
Re: Casting problem in VHDL
« Reply #2 on: October 18, 2016, 05:56:35 pm »
Your myFRQ_BUF0 is array:

Code: [Select]
type myFRQ_BUF0 is array (0 to 7) of STD_LOGIC_VECTOR (47 DOWNTO 0);

You are assigning std_logic_vector to an array. Assign it to one vector of that array then. For example to array element (0).
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1908
  • Country: ca
Re: Casting problem in VHDL
« Reply #3 on: October 19, 2016, 12:28:31 pm »
Thanks Scrts
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1908
  • Country: ca
Re: Casting problem in VHDL
« Reply #4 on: October 19, 2016, 02:42:59 pm »
I wanted to capture the duty cycle of a low speed input, it's called capture and it's about 500HZ my system clock is 50MHz, I have used chip scope to see the FRQ_BUF0(0) value, but it seems it does not capture the data correctly, I will get the FRQ_BUF0(0) some odd values like 0,2,3, 361 etc...

what's wrong with my code, I have done it in an NXP LPC timer and the code is similar to the C implementation in there.

my C code for the LPC looks like this and it works perfectly.

Code: [Select]
void TIMER2_IRQHandler(void)
{
LPC_TIMER2->IR=0XF0;//Clear all sources
CaptureValue[0][1]=LPC_TIMER2->CR0;
if(CaptureValue[0][1]>CaptureValue[0][0])
{
freq[0] = CaptureValue[0][1] - CaptureValue[0][0];
}
else
{
freq[0] = ((uint64_t)CaptureValue[0][1]+ 0x100000000) - (uint64_t)CaptureValue[0][0];
}
CaptureValue[0][0]=CaptureValue[0][1];

}
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline Dago

  • Frequent Contributor
  • **
  • Posts: 659
  • Country: fi
    • Electronics blog about whatever I happen to build!
Re: Casting problem in VHDL
« Reply #5 on: October 20, 2016, 04:21:21 am »
Are you synchronizing the input signal going to the FPGA? A 1-3 stage flip-flop chain is usually used for this.
Come and check my projects at http://www.dgkelectronics.com ! I also tweet as https://twitter.com/DGKelectronics
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Casting problem in VHDL
« Reply #6 on: October 20, 2016, 05:49:52 am »
Code: [Select]
if rising_edge(clk) then
 
 freerun_cnt <= freerun_cnt + '1';
 
 if rising_edge(capture) then

Nested "if rising_edge(xxx)" makes no sense. It might simulate but is wrong.

 - no two signals can have a rising edge at the sametime.

- In hardware a flipflop can only be sensitive to one edge.

Also your sensitivity list is just for one signal.

« Last Edit: October 20, 2016, 05:51:33 am by hamster_nz »
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1908
  • Country: ca
Re: Casting problem in VHDL
« Reply #7 on: October 21, 2016, 08:07:09 am »
Thanks I have syncronized the capture with the CLK but I still out of lock

Here is the updated code

Quote
type myFRQ_BUF0 is array (0 to 7) of STD_LOGIC_VECTOR (47 DOWNTO 0);
signal CapVal_00,CapVal_01 : STD_LOGIC_VECTOR (47 downto 0); 
signal freerun_cnt: STD_LOGIC_VECTOR (31 downto 0); 
signal RMS_BUF0,RMS_BUF1: myRMS_BUF0;
signal capture : STD_LOGIC_VECTOR(2 downto 0);

process (clk)
begin
if rising_edge(clk) then
 
 freerun_cnt <= freerun_cnt + '1';
 
 capture <= capture(2 downto 1) & capture_pin;
 if  capture(2)= '0' and capture(1) = '1' then --rising_edge capture
  CapVal_01 <= freerun_cnt;
  if(CapVal_01 > CapVal_00) then
   FRQ_BUF0(0) <= STD_LOGIC_VECTOR (unsigned(CapVal_01) - unsigned(CapVal_00));
  else
   FRQ_BUF0(0) <= STD_LOGIC_VECTOR((unsigned(CapVal_01) + X"100000000000") - unsigned(CapVal_00));
  end if;
  CapVal_00 <= CapVal_01;
 end if;
 
end if;
 
end process;


ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Online Someone

  • Super Contributor
  • ***
  • Posts: 4550
  • Country: au
    • send complaints here
Re: Casting problem in VHDL
« Reply #8 on: October 21, 2016, 09:22:28 am »
You cant simply rewrite sequential (C) code in VHDL syntax and have it work. Here is a really high level and shallow coverage of the basics:
http://web.mit.edu/6.111/www/f2007/handouts/L06.pdf
You need to spend some serious time learning about how a simultaneous evaluation language (non-blocking assignments in HDL) works, and why its not directly the same as sequential language. This isnt something quick and easy but many days of slow learning to completely change your point of view about what programming is.

Walk before you run.....
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Casting problem in VHDL
« Reply #9 on: October 21, 2016, 09:36:18 am »
If your intention is to implement a shift register, the following code snippet may not do what you intend to do:

Code: [Select]
capture <= capture(2 downto 1) & capture_pin;

See here: http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode8.html
« Last Edit: October 21, 2016, 09:39:59 am by Kalvin »
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1908
  • Country: ca
Re: Casting problem in VHDL
« Reply #10 on: October 23, 2016, 06:12:11 am »
Quote
capture <= capture(2 downto 1) & capture_pin;
It's for  synchronising the capture_pin to the FPGA clock
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Casting problem in VHDL
« Reply #11 on: October 23, 2016, 09:48:45 am »
Quote
capture <= capture(2 downto 1) & capture_pin;
It's for  synchronising the capture_pin to the FPGA clock

Or a little less subtly,  how does the value in capture(1) change when you keep on assigning it to itself?

Did you mean:
Code: [Select]
capture <= capture(1 downto 0) & capture_pin;
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf