Shop OBEX P1 Docs P2 Docs Learn Events
A faster way? - Page 2 — Parallax Forums

A faster way?

2»

Comments

  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-07-11 20:38
    RichardF said...
    I need a method which finds the highest of 8 frequencies coming in from my 8 TSL230 sensors and records which sensor was highest. My first cut at this is simple logic but it may not be the fastest way. freqx is simultaneously updated from 4 cogs running ctra and ctrb. freqx and CameFrom are global variables and will be used to·direct my PEBOT towards the brightest light.

    PUB ComCen
    ·HighFreq := 0
    ·CameFrom := 0
    ·repeat
    ·· if freq1 > HighFreq
    ···· HighFreq := Freq1
    ···· CameFrom := 1
    ·· if freq2 > HighFreq
    ···· HighFreq := Freq2
    ···· CameFrom := 2
    ·· if Freq3 > HighFreq
    ···· HighFreq := Freq3
    ···· CameFRom := 3
    ·· if freq4 > HighFreq
    ···· HighFreq := Freq4
    ···· CameFrom := 4
    ·· if Freq5 > HighFreq
    ···· HighFreq := Freq5
    ···· CameFrom := 5
    ·· if freq6 > HighFreq
    ···· HighFreq := Freq6
    ···· CameFrom := 6
    ·· if Freq7 > HighFreq
    ···· HighFreq := Freq7
    ···· CameFrom := 7
    ·· if freq8 > HighFreq
    ···· HighFreq := Freq8
    ···· CameFrom := 8····

    Would appreciate finding· more efficient/faster code keeping it in Spin.
    Thanks,
    Richard
    It looks like you have another routine that gets your frequencies and assigns them to·some variables. And then you have this method to figure out the high freq/cog.

    My question: why not set the high freq/cog when you actually do the sampling? Then this·routine·might devolve down to a simple conditional in the sampling code.
  • RichardFRichardF Posts: 168
    edited 2007-07-11 21:15
    Holy cow, gentleman,
    I just returned from a 3 day vacation to Canada's McGregor Bay, and feel bad that you all have been working so hard while I was gone to speed up my little "find max and which one is max" code. You have given me a lot to digest and learn, and I thank you for it. In my PEBOT application of just maneuvering to changes in light intensity, as opposed to the detect a flashbulb project, I don't think the speed of finding the max freq will turn out to be that important, but it was so obviously a question that needed to be asked, so I asked. I am glad I did; it gives me a chance to keep learning, and keeps you guys from getting bored.

    Fred,
    I use 4 cogs for detection from 8 sensors (a and b ctrs), one cog to find max freq and camefrom, one cog to take the max freq and came from and turn it into steering commands for the wheel motors, and one cog to drive the wheels using pulse width. Cog 0 gets it all started and updates the LCD. In othe overall scheme of things, I bet this is the fastest and most efficient way to do this application, because it represents parallel processing at its best. Since I am not worrying about battery life (I can recharge the bot anytime, why not use all 8 cogs; that·is why we bought the Propeller, right?
    Thanks,
    Richard

    Post Edited (RichardF) : 7/11/2007 9:27:33 PM GMT
Sign In or Register to comment.