Jump to content
  • 0

Programming


1116345

Question

Hello Everyone,
I am encountering some errors with my codes.Being a beginner, I dn't know much about loops.. I tried to use multiple looping but i cn't reach a proper result....can anyone help??? and PFA my flowchart post-50-0-99135500-1419269244_thumb.png
 my codes are as follows:
 
library IEEE;
use IEEE.STD_LOGIC_1164.all;
 
entity comparator is 
generic (N : integer := 6);
port(
S : in STD_LOGIC_VECTOR(N-1 downto 0);
Z : out STD_LOGIC_VECTOR(2 downto 0)
    );
end comparator;
 
 
 
architecture comparator of comparator is 
  begin
       process(S)
       begin 
 comp1: for N in 0 to 4 loop -- for the sensors 0-4--
 
if  S(N) < S(N-1) then
 N <= N+1;
elsif ( comp2: while ( S(N)= '1')loop )   then --for S(N) < max value --
 
   Z(0) <= 1 ;             --rotate in specific direction--
end loop comp2; 
 
         elsif N = '4' then
              
               Z(1) <= 1; --reset motor that is return to initial position --
         
         else 
             N <= N+1;
 
         end if;
      end if;
    end if;
 
end loop comp1;
 
   if S(5) > S(2) then
        Z(2) <= 1 ;-- second motor is rotated --
   end if;
 end process;
 end comparator;
end comparator;

 

 

 

 

and here are the errors:

 

# Compile...
# Warning: DAGGEN_0523: The source is compiled without the -dbg switch. Line breakpoints and assertion debug will not be available.
# File: c:My_Designscomparatorcomparatorsrccomparator.vhd
# Compile Entity "comparator"
# Compile Architecture "comparator" of Entity "comparator"
# Error: COMP96_0015: comparator.vhd : (22, 16): ')' expected.
# Error: COMP96_0019: comparator.vhd : (22, 18): Keyword 'then' expected.
# Error: COMP96_0019: comparator.vhd : (22, 41): Keyword 'end' expected.
# Error: COMP96_0111: comparator.vhd : (25, 13): Labels do not match.
# Error: COMP96_0019: comparator.vhd : (27, 10): Keyword 'end' expected.
# Error: COMP96_0019: comparator.vhd : (31, 10): Keyword 'end' expected.
# Error: COMP96_0016: comparator.vhd : (32, 14): Design unit declaration expected
Link to comment
Share on other sites

12 answers to this question

Recommended Posts

Hi 1116345,

 

Merry (late) Christmas to you too!

 

Yes, getting the solar panel and the sensors lined up with each other perfectly won't be easy and cannot be easily accounted for in software; that will need to be done with your hands and some angle measurement tools such as a protractor.

 

As for the microstepping, it will be possible to perform; it just won't be done in the same way as full-stepping or half-stepping.  Rather than fully turning on and fully turning off the electromagnetic coils with the logic high and logic low voltages, what microstepping does is turn the coils "on and off" in a sinusoidal fashion, typically with a PWM signal.

 

These sinusoidal signals will be out of phase with each other in such a way (the phase difference depends if you are using a unipolar or bipolar stepper motor, and the capability of your system board) so that as one coil is getting more energized the other coil is getting less energized and vice versa.

 

Let me know if you have any more questions.

 

Thanks,

JColvin

Link to comment
Share on other sites

Hi 1116345,

 

I am not familiar with FPGAs so I won't be able to completely answer your question, but I do see a few things that will likely need some adjusting.

 

Within your code right after you begin the process(S), you have a line that says

 

 

elsif ( comp2: while ( S(N)= '1')loop )   then --for S(N) < max value --

I do not think that the "comp2: while ( S(N) = '1')loop ) then" will ever leave here because of the while loop that you have. The reason for this is once S(N) = '1', you never change the value of N so this condition of S(N) = '1' will be true indefinitely. Yes, it is within an elseif statement, but I don't think you will actually get out of the while loop so that you can reach the end of the elseif.

 

Another bit is that I think (again, I'm not familiar with FPGAs) is that you don't have a "then" & "end" associated with the aforementioned while loop.  This is probably why you have the two errors that say

 

# Error: COMP96_0019: comparator.vhd : (22, 18): Keyword 'then' expected.

# Error: COMP96_0019: comparator.vhd : (22, 41): Keyword 'end' expected.

 

The final thing that I am seeing is that you have too many "end if" statements. I do not know if they contribute to any of the errors that you are seeing, but after taking a look at hamster's example code on running a stepper motor, the way he uses if's, elseif's, and end if's suggests that you do not need an end if for each elseif.  

 

As for the other errors, I personally do not know what the problem might be since I have not coded an FPGA, but hopefully this gives you a place to start debugging your code.

 

Let me know if you have any more questions.

 

Thanks,

JColvin

Link to comment
Share on other sites

Hi 1116345,

 

One problem I do see is that you have no clock, the best that your design can do is map 'N' bits of input (in S) to 3 bits of output in Z. As there is no local signals the entity has no internal state, unless you infer latches, which is usually bad.

 

The 'generic' N acts like a compile time constant, and can only be used to indicate the size of the S input. You can't/shouldn't modify it.

 

If you could describe what you want it achieve (in either code or English) we will nudge you in the right direction.

Link to comment
Share on other sites

Thanks Mr JColvin and Mr Hamster 

I am stuck with these if-elsif...Actually using my basics of C programming, I tried to write these codes...I attached a flowchart above and what I did was converting the latter into codes...What I want to program is that I have 7 values from 7 light sensors...I am comparing the values such that the light sensor will maximum value among the others thus causing the motor to rotate till that particular sensor is at its maximum value. Sensor 5 and sensor 6 are for the seasonal change in angle.....I actually want to design a solar tracker.

Link to comment
Share on other sites

Here's something that has a passing resemblance to your code, and is structurally correct

 

library IEEE;
use IEEE.STD_LOGIC_1164.all;
 
entity comparator is 
   generic (N : integer := 6);
   port(S : in STD_LOGIC_VECTOR(N-1 downto 0);
        Z : out STD_LOGIC_VECTOR(2 downto 0));
end comparator;
 
architecture comparator of comparator is 
   begin
   
process(S)
   begin 
 
comp1:for N in 0 to 4 loop
         if  S(N) < S(N-1) then
            N <= N+1;
         elsif a = 1 then         
comp2:      while ( S(N)= '1') loop
               Z(0) <= '1';
            end loop comp2; 
         elsif N = 4 then
            Z(1) <= '1';
         else 
            N <= N+1;
         end if;
      end loop comp1;
 
      if S(5) > S(2) then
        Z(2) <= '1';
      end if;
   end process;
end comparator;
Link to comment
Share on other sites

Oh, now I think I understand your intent - does this look like what you actually need?

 

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
 
entity sun_tracker is
    Port ( -- Inputs from the sensors, as 8-bit unsigned binary signals
           sensor_far_left     : in  STD_LOGIC_VECTOR (7 downto 0);
           sensor_left         : in  STD_LOGIC_VECTOR (7 downto 0);
           sensor_center_left  : in  STD_LOGIC_VECTOR (7 downto 0);
           sensor_center       : in  STD_LOGIC_VECTOR (7 downto 0);
           sensor_center_right : in  STD_LOGIC_VECTOR (7 downto 0);
           sensor_right        : in  STD_LOGIC_VECTOR (7 downto 0);
           sensor_far_right    : in  STD_LOGIC_VECTOR (7 downto 0);
           -- Outputs to drive the motor
           motor_go_left       : out  STD_LOGIC;
           motor_go_right      : out  STD_LOGIC);
end sun_tracker;
 
architecture Behavioral of sun_tracker is
 
begin
 
   --- Your code goes here, to decide which output to turn on (motor_go_left or motor_go_right)
 
end Behavioral;
 
If so, given this framework, can you explain how you want it to actually work (e.g. how should it decide which direction to turn the motor?)
 
PS. It actually sounds better suited to being implemented in a micro controller (e.g. chipKIT, Arduino) than an FPGA
Link to comment
Share on other sites

Thanks Sir,

For the motor, I thought I would use PWM to control its speed but I do not think its a good idea...and i dnt knw if microstepping can be done...I wanted to rotate the solar panel by 1 degree untill the particular sensor is at its maximum....Actually I am using 7 sensors which are not on the solar panel but are on a separate platform...This enables to handle more than 1 solar panel with least number of sensors..But this also increases the difficulty as I am unable to design how to make the 2 motors rotate :( if you can help, I would be grateful..

Link to comment
Share on other sites

Hi 1116345,

 

In terms of rotating the motor via pwm, that technique will work just fine; microstepping is also (at it's root) a type of pwm signal.  However, it is generally applied towards stepper motors as opposed to servo or DC motors.  What kind of motor were you intending to use?

 

After seeing your intended application, there are a couple of mechanical designs that we need to consider.  If I understanding your project correctly, you want your solar panel to rotate to whichever light sensor on your second platform is receiving the most light. This can be done, especially with your case/ if else statements to have each of the individual motors rotate in the appropriate direction. However, you would need to make sure that your solar tracker is oriented in the exact same direction as your 7 sensors or is calibrated in such a way so that it rotates to the correct sensor angle for maximum solar efficiency. The easiest way to do this (in my opinion) is through trial and error with some sort of artificial light source.

 

You probably have already thought of this, but you'll also want to make sure that your light sensors have a wide range of light sensing capability and/or are spaced far enough apart; it would be rather awkward if three different sensors all tied for their maximum value.

Link to comment
Share on other sites

Hi 1116345,

 

How will you sense the direction that the panels are facing? There needs to be some sort of feedback, even if it is just limit switches to indicate when the end of travel has been reached.

 

If you can accurately point the panels, maybe you should just use a real time clock and a bit of math to work out where the sun should be, and point them that way...

Link to comment
Share on other sites

Hello JColvin and Hamster,

I was thinking about the clock and position of sun and some calculations but then there is no use of sensors...it becomes a chronological tracker... My problem is that my sensors being on a separate platform, its difficult to make the solar panel accurate...

Link to comment
Share on other sites

Hello again,

I was thinking of using microstepping....but it seems much more complicated than half and full steps...

 

for full steps:

when "00" => dout <= "1000"

when "01" => dout <= "0100"
when "10" => dout <= "0010"

when "11" => dout <= "0001"

 

 
for half steps:
when "000" => dout <= "1000"
when "001" => dout <= "1100"
when "010" => dout <= "0100"
when "011" => dout <= "0110"
when "100" => dout <= "0010"
when "101" => dout <= "0011"
when "110" => dout <= "0001"
when "111" => dout <= "1001"
 
for microsteps (16 steps):
when "0000" => dout <= "1000"
when "0001" => dout <= 
when "0010" => dout <= "1100"
when "0011" => dout <= 
when "0100" => dout <= "0100"
when "0101" => dout <= 
when "0110" => dout <= "0110"
when "0111" => dout <= 
when "1000" => dout <= "0010"
when "1001" => dout <= 
when "1010" => dout <= "0011"
when "1011" => dout <= 
when "1100" => dout <= "0001"
when "1101" => dout <= 
when "1110" => dout <= "1001"

when "1111" => dout <= for full steps: 

when "00" => dout <= "1000"
when "01" => dout <= "0100"
when "10" => dout <= "0010"
when "11" => dout <= "0001"
 
 
 
its seems that this is not possible :( and am sorry to bother u people on such an occasion.....By the way Merry Christmas to all :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...