Shop OBEX P1 Docs P2 Docs Learn Events
Simultaneous seed counting? — Parallax Forums

Simultaneous seed counting?

techstudenttechstudent Posts: 21
edited 2008-02-15 01:29 in Propeller 1
I am working on a seed monitor for a 12 row air corn planter, the seeds come at a rate of approx 20 per second at each row(depending on ground speed), and this is happening simultaneously at all 12 rows, The monitor should detect and display at each row if there are doubles (time between seeds is to small) and skips (if the time between seeds is to much). The other thing I want to monitor is a total count of seeds at each row for comparison purposes, to detect if a row becomes partially plugged and would have a lower count than the rest. (this count could be periodically be reset, as the purpose is just to compare to surrounding rows, and if one is lagging it should be evident after a few thousand seeds or so)

For hardware the seed sensor on the planter is Normally low (0V) and when a seed goes past, it outputs a small high pulse (5V). Thus far I am thinking of using some sort of a flip-flop arrangement to store a high when a seed goes past until the propeller scans the 12 inputs and resets the flip-flops. Also I would like to display the info on a flat screen monitor as there is not a lot of space in the tractor cab. (info on selecting a cheap rugged flat screen for use with the prop ? The monitor should be big enough to glance at while driving..)

I am pretty good with the BS2 but am fairly new to the propeller, so take it easy on me wink.gif but any info on programming/hardware would be appreciated…

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-11 19:10
    Depending on the width of your pulses, the external flip-flops may not be necessary. The Propeller has a WAITPNE instruction which will wait for any change from a given pin state. You could set up one cog dedicated just to monitoring the pins for changes and reporting the pulses, so long as one monitor/report cycle could be completed in less time than the width of a pulse. You would want to do this part in Assembly.

    -Phil
  • techstudenttechstudent Posts: 21
    edited 2008-02-11 20:01
    I will have to do some measuring and see if I can scope a pulse width, and I will also check out the WAITPNE command... I don't know much about Assembly as of yet, I am at the level of, I have studied the spin examples in the prop manual, and have gone through some of the online spin tutorials/examples, but still have much to learn... I guess if possible I am looking for a pseudo spin code to get me started, though if it is not possible/practical in spin I will have to pursue other avenues..

    Any info/comments are much appreciated...

    ''techstudent
  • OzStampOzStamp Posts: 377
    edited 2008-02-11 21:10
    Hi techstudent.

    The Propeller has 8 CPU's each CPU has 2 hardware counters..
    Not that you need the speed 20HZ is really slow..

    Look at the CTRA instructions maybe just what you need with a little input signal conditioning..as they are very fast.
    The CTRA is a set and forget function ..

    cheers ron mel oz
  • LawsonLawson Posts: 870
    edited 2008-02-12 02:32
    I've been meaning to make an object to monitor the pulse width of lots of asynchronous pulses. (for reading in pulses from RC gear) The basic thery of what I'm thinking of is to use WAITPNE to wait for a change on a pin. At that point, CNT combined with the previous and new states of the pins should allow pulse widths to be measured. (for 20Hz pulses, spin should suffice for 2-3 channels. I can then be translated to assembly for full speed)

    'setup
    mask := %00000000_00001101_00000010_00000000 'what pin am I interested in
    Old_pins := 0
    New_pins := 0
    Mark_CNT := 0
    New_pins := INA & mask
    
    repeat   'core loop of massive win
      Old_pins := New_pins  'store old pin state
      WAITPNE(Old_pins, mask, 0)   'wait for a change
      New_pins := INA & mask  'snag what's changed and mask off ignored pins
      Mark_CNT := CNT   'snag WHEN it changed
    
      'compare Old_pins to New_pins to see what pin changed state and in which direction (more than one pin may have changed)
    
      'run a state machine for each pin that changed to measure high and low pulse length (remember more than one pin may have changed)
    
      'decide what it all means and update the approprate counters in HUB ram
    



    This is a skeleton of what I'm thinking of. The key thing is that the code needs to sit waiting at the WAITPNE 99% or more of the time. Otherwise there'll be lots of jitter in the measurements.

    My two bits,
    Marty

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lunch cures all problems! have you had lunch?

    Post Edited (Lawson) : 2/12/2008 2:39:26 AM GMT
  • techstudenttechstudent Posts: 21
    edited 2008-02-12 17:28
    Hello,
    I have measured the pulse width, and found that it is irregular, as the planter has an optical sensor, so it depends on the size and orientation of the seed as it goes through the sensor, so the pulse stays high state from about 4ms to 14ms (the time it takes for the seed to cross the sensor)..
  • techstudenttechstudent Posts: 21
    edited 2008-02-12 18:00
    The CTRA command sounds intriguing, but I am having some difficulty understanding it, from what I can see is that each of the two counter modules can monitor up to two O/I pins, so if each cog has two counters 4pins could be monitored per cog, so three cogs could monitor 12 inputs, however as mentioned these counters are very fast and my pulses are rather slow, what type of signal conditioning would be needed? if i could narrow the pulses would that help? Also i was wondering the difference between POSEDGE detector and POSEDGE detector w/feedback, if anyone knows of any examples of using CTRA for pulse counting or could give a code snippit with a little explanation using the CTRA command for pulse counting would be helpful..


    The other possibility that has been mentioned is to use the WAITPNE with respect to the CNT as in the example above, also a very intriguing idea, as it would not require signal conditioning because it is waiting for a change of state. But I am wondering why spin would only suffice for 2 or 3 channels? Is this because while the cog is busy with the spin code it is temporarily distracted from monitoring inputs? Would it be possible to set a separate cog just to monitor WAITPNE, while a different cog does the computational work of seeing which pins have changed and updating according variables so that it would be possible to monitor all 12 inputs?

    Thanks for all the brainstorming, any info/comments are much appreciated...

    ''techstudent
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-12 19:47
    To use the counters, you'd need a separate cog for every two seed detectors (because each cog has only two counters). Since your pulse width is so long, the counters would be overkill for what you're trying to do. You should easily be able to count pulses from all twelve seed detectors in one cog just using assembly software. I wouldn't even bother with WAITPNE. A better alternative would be to use WAITCNT on a 500µS interval, or so:

    1. WAITCNT for next interval.
    2. Increment Time.
    3. Read current pin state.
    4. XOR with previous state so see if any pins changed.
    5. ANDN result of XOR with current state to see if any pins changed from high to low.
    6. For each pin changing from high to low:
    7. ······Increment count for that pin.
    8. ······Record Time for that pin.
    9. ······Compare Time with previous Time for that pin and record a skip or double, if necessary.
    10. For each pin not changing from high to low:
    11. ······Check time interval since last seed to make sure feeder isn't jammed.
    12. Set previous pin state to current pin state.
    13. Go To 1.

    -Phil
  • OzStampOzStamp Posts: 377
    edited 2008-02-12 21:15
    Hi
    In the object library there is a object by Jeff Martin ( Parallax engineer) it is for counting signals from Encoders. (a + b phase)
    The way I understand how that works is that if you modify his code slightly in the lookup table you should be able
    to get some results by using that object.. it is called encoder spin or similar..
    As I said that objects as it is will NOT do what you want exactly it needs some slight modifications..
    But it monitors a whole of inputs simultaneously.. similar to what Phil P explains in his post..

    cheers Ron Mel OZ.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2008-02-14 17:29
    techstudent, how do you account for vehicle speed?
  • techstudenttechstudent Posts: 21
    edited 2008-02-15 01:29
    Hello,

    Phil, thanks for the outline, that is what I was looking for, I do understand the logic, though I am not of a software background and don't know much about Assembly, but now that I've got a propeller I have a good excuse to take the time and learn..

    OzStamp, I found that object "Quadrature Encoder" I think that is the one you were referring to, it looks like it has many similarities to what I want to do, but I have much learning to do before I can fully digest the code enough to modify it for my purposes..

    Fred, to account for ground speed I will use a hall effect sensor with 6 magnets mounted on the hub, so it won't be a direct comparison in time from the previous seed, but will have to factor in the ground speed (20 seeds per second is at 4mph which is avg planting speed in avg conditions)

    I have done a lot with the BS2, but finally got a propeller proto board about a month ago, I have a machine shop, and a small plastics molding business, so I haven't had as much time on the propeller as I would like, but today I got it hooked up to the TV and was playing around with the graphics demo... wow what fun!! initially I was thinking of just using text and number for interface, but I may add some bar graphs and things as it looks pretty simple to figure out..

    As always thanks for all the inputs.....

    ''techstudent
Sign In or Register to comment.