• 0

Pins On The Pmodmaxsonar


Go to solution Solved by hamster,

Question

A customer asked me this question:

 

hi
 
I'm facing a problem while using DIGILENT BASYS2 SPARTEN 3E board. How can a sonar unit(external hardware) giving digital output pulses can be connected to the pmods. How are the 4 pmods in the board connected.
 
With thanks and regards
Aparna
 
 
Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
  • Solution

I don't have a PMODmaxsonar, but reading the reference manual is seems that you only need to connect pins 4, 5 and 6 to the BASYS2 (PWM output, GND and Vcc). You can connect the other pins but it does not seem to be essential. You should be careful with pin 1, as it is an analogue output - I suggest you configure the relevant FPGA pin as an input to prevent excessive power usage 

 

So they should be configured as follows (assuming you are using PMOD JA):

   JA1 - Input - ignored, it is the Analogue output

   JA2 - Input with pull-up, or an output set to '1', to enable the sonar module.

   JA3 - Input - Ignored - it is the serial data stream from the PMODsonar

   JA4 - Input - the PWM distance signal.

   GND - Ground

   Vcc   - 3.3V

 

Distance can then be obtained by counting the length of the PWM input pulse.

 

   if rising_edge(clk) then
      if JA4_sampled = '1' then
         counter <= counter + 1;
      elsif counter > 0 then
         pulse_length <= counter;
         counter <= (others => '0');
      end if; 
     -- Sample the PWM signal into a register, to avoid problems with an async signal.
     JA4_sampled <= JA4;
   end if;

 

You can actually avoid a lot of math required to convert a 'count' into a distance. In the manual it says that the pulse with is 147µs per inch, and if your FGA design is running at 100MHz you can do this:

 

   if rising_edge(clk) then
      if JA4_sampled = '1' then
         if counter = 14699 then
            -- every 147us add an inch to the distance to the target
            inches <= inches + 1;
            counter <= (others => '0');
         else
             counter <= counter + 1;
          end if;
      elsif counter > 0 or inches > 0 then
         -- set the output then reset the counters
         range   <= inches;
         counter <= (others => '0');
         range   <= (others => '0');
      end if; 
     -- Sample the PWM signal into a register, to avoid problems with an async signal.
     JA4_sampled <= JA4;
   end if;
 
And then your "range" output is the range in inches, without needing to use any complex math
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now