Shop OBEX P1 Docs P2 Docs Learn Events
Low Resolution vision — Parallax Forums

Low Resolution vision

LustInBlackLustInBlack Posts: 22
edited 2008-03-14 01:30 in Propeller 1
I'm currently on my first project on the propeller..


I have problems, since I'm new to this mcu, I have some issues..


I have a 8-bit Shift register that select between 8 photosensors, it select a photosensor, then
with a sigma/delta ADC get the value of the photosensor..

This work perfectly with only one photosensor..

My shift register works, I tested it with leds and I see the leds being shifted across the shift register.

It then selects a photosensor, wait a bit, take a measure of the ADC and apply that value to a color
array that I output on a computer monitor (The screen is setup at 256 x 256 pixels) ..

I can visually inspect the return value... This works pretty well with one photosensor.. The value
for testing, is acceptable, and that's on a breadboard.

The problem occurs when I have 8 leds on the shift register.. It seems that the value of ALL leds
together, is the average of every led values ..

However, I do treat each value separately, since I keep the adc sample in an array, and I know what
photosensor I am currently monitoring ..

I find this a bit strange, maybe it has to do with my circuit, but as I see it, it should work..
The shift register, provide the 3.3 volts voltage source to my photosensors, the photosensors and then
connected to a voltage divider, to get between 1 and 3.3 volts output value..
The ADC is exactly as the propeller application note..

Here is the sampling code..

It's ugly for the moment, excuse that code atrocity!

It begins with the shift register DATA input High..


        mov  adc_cnt, cnt 
        add  adc_cnt, adc_cycles
        mov  nTmp2, #8
        mov  nTmp3, ColorPtr
        mov  nTmp4, SavedSample
        mov  tmp, #0
  :loop waitcnt adc_cnt, adc_cycles 
        mov     adc_sample,  phsa  
        sub      adc_sample,  tmp
        rdlong  old_sample,  SavedSample
        sub      adc_sample,  old_sample
        add      old_sample,  adc_sample
        wrlong  old_sample,  SavedSample
        wrword  adc_sample, colorptr
        ' shift to next photosensor
        add colorptr,   #2
        add SavedSample, #4
        IF_NZ and   outa, Shf_DataOFF
        IF_Z  or    outa, Shf_DataON
        IF_Z  mov   nTmp2, #8
        IF_Z  mov   colorptr,   nTmp3
        IF_Z  mov   SavedSample, nTmp4
        mov tmp,   cnt
        add tmp,   #20
        waitcnt tmp, #20
        or  outa, Shf_ClkON
        nop
        nop
        nop
        nop
        and outa, Shf_ClkOFF

        sub nTmp2, #1 wz     
                              
        waitcnt adc_cnt, #$1FF
        mov tmp, phsa
      
  jmp #:loop 


Comments

  • RinksCustomsRinksCustoms Posts: 531
    edited 2008-03-13 05:23
    Not that i doubt your engineering abilities, but lemme get this straight...

    You have 8 "photosensors" -.. meaning photodiodes(IR), photoresistors, phototransistors ?
    and you've connected these to an 8-bit shift register (digital only) ?
    and then reading the shift register with an ADC to the prop ?

    I'm not putting you down here, just trying to clarify is all. Me personally, i like the K.I.S.S. methodology of engineering - "Keep It Simple Stupid" - Tracy Allen i believe. I'm not up on my ASM all that much, but for the real experts in here, perhaps a block diagram of this setup would help visualize, a schematic would also allow for a fresh set of eyes (EE's) to pick out a possible bug.

    I like the theory, as it wouldn't take alot of work form this base object to adapt to visual light (RGB) by reverse-bias sampling red, green and blue lense colored led's, or an adaptation to the infrared spectrum. I'd be interested in following this subject, if you'd like to keep us updated from time to time. There are a few members that can't give details because they are working on a classified project for their company, but most of us are novices/hobbyists and just like to see cool stuff being done with the prop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.
  • LustInBlackLustInBlack Posts: 22
    edited 2008-03-13 05:55
    Don't worry, no offence taken, I agree I was not quite clear!

    I'll try to simplify it ...


    I have 1 ADC channel on 2 pins of the prop (sigma/delta ADC)

    It reads a value (1 of the 8 photo Resistors) (This photo resistor is connected on the ADC)

    The photo resistors are connected to a voltage divider (actually a 1Kohm resistor on ground and one of the leg of the photo
    sensor. the other leg of the photosensor is connected to +3.3volts, WHICH is provided by the Serial In Parallel Out 8bit register,
    thus, the serial shift register acts like a power supply and selector of photosensor.. It's an 74HC164n to be exact)

    The idea here, is to switch ON only 1 photosensor at a time.. I have 8 in a row and will have 8 columns of photosensors..

    For the moment, I'm concentrating on synching the photosensor with the ADC ..

    So basicly, switch on Photosensor #1, wait for stabilisation, read ADC, wait for ADC, switch off photosensor #1 and switch
    on photosensor #2 ... Repeat ...

    On photosensor #8, I reset the sequence (this is probably where my code failed by the way) ..



    The shift register is shifted after each ADC sampling..

    10000000
    01000000
    00100000
    00010000
    00001000
    00000100
    00000010
    00000001

    The ADC have a resolution of 16bit ..

    The sampled value of the ADC is outputed on a monitor in a 8x8 grid (32bit tiles at 256 x 256 pixels)


    This will be used in a robotic application, I want to detect movement and edges..


    I also have ideas for improving the resolution of the visual "cortex" without much additional hardware..


    I also wish to put a GPS etc on this, but it's too early to elaborate on this..
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-13 07:38
    This is a nice idea however it is not going to work quite how you expected.
                            LDR
    from mux-----/\/\/\/\-----+
                                         |--------/\/\/\/\-GND
                           LDR        |
    from mux-----/\/\/\/\-----+
                                         |----to prop
    


    I think this is how you have it set up? When you turn one input on (3.3V) all the others will go low (0V). This means that you circuit ends up like this
                            LDR
           3.3V-----/\/\/\/\-----+
                                         |--------/\/\/\/\-GND
                           LDR        |
            GND-----/\/\/\/\-----+
                                         |----to prop
    


    So your actual resistance to ground does not remain constant. It will vary depending on the light on all the sensors, not just the one that is connected to the 3.3V. If you can get a multiplexer that tri-states (makes them a very high resistance) the outputs instead of setting them to 0V than you will be in business (I don't know of one but someone else here might). Your other option would be to use an analogue multiplexer.
  • AribaAriba Posts: 2,685
    edited 2008-03-13 07:53
    You can use Diodes to prevent the problem that Stevenmess describes:

    ──┐       //
      ├────────┐
      │       //  │
      ├────────╋──── ADC
      │           │  
    ──┘            
    SR             
    
    



    Andy
  • LustInBlackLustInBlack Posts: 22
    edited 2008-03-13 15:58
    Heh, I think you are quite right, I overlooked this "detail" ... freaked.gif

    I shouldn't work with the prop at 3 am in the morning during the week.. devil.gif
  • RinksCustomsRinksCustoms Posts: 531
    edited 2008-03-14 00:34
    LustInBlack said...
    Heh, I think you are quite right, I overlooked this "detail" ... freaked.gif

    I shouldn't work with the prop at 3 am in the morning during the week.. devil.gif
    LOL i can relate...
    ·The divider theory is correct. Keep the shift register, but add two "4066" analog mux's & simply have the shift register turn each channel of the mux on. Input your photoresistors (matching?) to the mux channels, then tie all output muxes to the ADC input. I can provide a schematic to what I'm talking about, but I think you know where i'm going with this.

    @Ariba - the only problem with adding diodes is that you·have a·0.6V drop across the diode.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.
  • LustInBlackLustInBlack Posts: 22
    edited 2008-03-14 01:24
    It's now working very well !!!

    It is quite encouraging.. Thanks for the Diode array idea!

    However, I have some averaging problem..

    The first photosensors show more light than the other..
    They are more sensitive than the their neighbor..
    Looks like the circuit is still problematic on this side..


    With the diodes, I had to compensate for the drop in voltage with a 1K ohm resistor in series with the
    adc-in, and switch the shift register to 5V.. That way, the prop receive maximum a 3volts signal and the
    photosensor get maximum range..

    They are quite sensitive.. It also looks like I should put some more delays so they adapt to light change..

    I have a logic bug somewhere, it takes a bad reading (all zeros), than the next reading is ok..
    Probably have to do with the array in which I set the samples and the old samples..

    I'll think about a good way to implement this feature... For the moment, it's a quick and dirty
    proof of concept..


    It's promising!

    I'll soon have 64 photosensors to measure!

    I'll probably use 2 to 4 cogs to process images, I want to achieve insane FPS...


    The next step, is a robotic head and will move to scan the horizon.. I'll then map the images in
    an external SRAM (2MegaBytes) and keep GPS position of the scene..

    I'll try to make a 2D / 3D map of the surrounding of the robot, so it can navigate and make strategy along it's
    way..


    Btw, I'm out of diodes...


    smilewinkgrin.gif
  • LustInBlackLustInBlack Posts: 22
    edited 2008-03-14 01:30
    Rinks,

    I'll look into your idea, I'm not familiar with Multiplexers yet, but it sounds good ! ..

    With a 8x8 array, I would need 16 diodes.. Sounds good to have only 4 parts!
Sign In or Register to comment.