28317 Linescan Sensor Module
B.ASHISH
Posts: 28
I want to interface the TSL 1401 -DB LINE SCAN SENSOR MODULE using the Propeller microcontroller.I used the datasheet of TSL1401R-LF and this is the code which I used.
CON
resolution = 256
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
BASE_PIN=0
OBJ
pst : "Parallax Serial Terminal"
VAR
long Stack[16]
PUB main | i,value
DIRA[0..2]:=%110
pst.Start(115_200)
cognew(clk,@Stack)
pst.Str(String("Enter a decimal value: "))
repeat
OUTA[0]~~
waitcnt(clkfreq*0.0000001+cnt)
outa[0]~
repeat i from 1 to 128
value := INA[2]
pst.dec(value)
waitcnt(clkfreq*0.0000003232421875+cnt)
repeat i from 1 to 128
pst.dec(value)
PUB clk
repeat
outa[1]~~
waitcnt(clkfreq*0.000000125+cnt)
outa[1]~
waitcnt(clkfreq*0.000000125+cnt)
But it is displaying 83886097.Instead it should display binary values based on the intensity of light,So please help me in making this sensor to run correctly.
CON
resolution = 256
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
BASE_PIN=0
OBJ
pst : "Parallax Serial Terminal"
VAR
long Stack[16]
PUB main | i,value
DIRA[0..2]:=%110
pst.Start(115_200)
cognew(clk,@Stack)
pst.Str(String("Enter a decimal value: "))
repeat
OUTA[0]~~
waitcnt(clkfreq*0.0000001+cnt)
outa[0]~
repeat i from 1 to 128
value := INA[2]
pst.dec(value)
waitcnt(clkfreq*0.0000003232421875+cnt)
repeat i from 1 to 128
pst.dec(value)
PUB clk
repeat
outa[1]~~
waitcnt(clkfreq*0.000000125+cnt)
outa[1]~
waitcnt(clkfreq*0.000000125+cnt)
But it is displaying 83886097.Instead it should display binary values based on the intensity of light,So please help me in making this sensor to run correctly.
Comments
Welcome to the forum!
Okay, first things first:
Please edit your post.
Also, I notice that you have four other threads started with the same question. I've had them deleted so we can focus on this one.
Regarding the obvious issues in your code:
2. But, more to the point, the waitcnts in your program are unnecessary and should be removed. Spin's overhead adds way more time than is needed by the sensor chip.
3. You're addressing value as an array, but it hasn't been declared as such. Declare value in the VAR section as an array, instead of as a local variable.
Which Propeller platform are you using with the TSL1401-DB? If it's the Propeller Backpack, I can upload a driver object for you that will simplify your programming.
-Phil
The clock frequency of the microcontroller is 80MHz and that which is required for this sensor is 8MHz.
I think,there is a problem with the synchronisation.I followed the timing Diagram of TSL1401-LF datasheet.
Change your waitcnt values to something larger. Such as:
Each of the very short waitcnt values you used will cause the Propeller to wait about 54 seconds as the 32-bit clock rolls over.
The smallest waitcnt valve is larger than 700 but smaller than 1000 (I don't recall the exact number).
So this would also work.
The above will wait for 12.5 us @ 80MHz (plus some extra time for code overhead).
Edit: It looks like you're trying to generate a very fast pulse. The easiest way to do this is with counters. There's a section in the Propeller Education Kit about counters that should help. The PEK can be found in the "help" menu of the Propeller Tool.
2. I would not include pst.dec(value) inside the read loop, since it will slow it down too much. You already have a separate loop after the azquisition loop. Just use that one to read out your data.
3. You have not made adequate provision for the exposure time. I would recommend a dummy acquisition loop, followed by a delay, before the actual acquisition loop. The exposure time would be the interval between pulsing SI.
Which board are you using with your Propeller chip?
-Phil
I also think your stack is too small, I make my stack 100 now at a minimum, because I have seen random issues with that as well.
I'm not sure exactly what you are trying to do, but I have had pst issues like this and learned what I'm telling you the hard way ... take this code with a grain of salt as untested (it will compile), but the format might help you.
Maybe you can describe in detail what you want to see as an output (or to monitor), and I can tweak my code to represent that better.
This code example polls 2 pins that I have LED's alternating on and off, and checks there states.
You'll see that I have 1 cog controlling the two pins alternation, and I have the first cog (main) monitoring it and updating the pst terminal window with the state. You can tweak this code so that the clk loop controls the light sensor, or updates a global variable with the light sensors state, and then the first cog (main) checks that global variable or pin and prints update values to the pst as fast as it can. The pst can only do a maximum of 115000 bits per second, so lets say that you only send the actual numerical value plus a carriage return, that's 3 bits plus a stop bit, so that's a theoretical maximum amount of 28800 updates to the pst per second.
Either way, if you have the data changing each microsecond, which is a million times a second, you can easily see that at absolute best, the pst could only theoretically catch 1 out of every 34.7 of the 1,000,000 updates per second. Make sense?
Enjoy!
-Phil
-Phil
The 128 pixels scan is changing continuously changing with every press of the enter key.
What is the range of the sensor? and what about the focal length ?Is there an optimum focal length to achieve correct readings?
I actually want to calculate the width of an object using this sensor module and also the orientation of the object with respect to this sensor module.
I used a 3cm wide black strip on a white background for the experiments.Please help me out,to stabilise the readings of a fixed object and finally to find the width of the object.
-Phil
I am using a white paper with a BLACK STRIP OF 3CM WIDTH and observing the readings.
I want the object's orientation with respect to the sensor module
-Phil
Repeatability in the readings is not being achieved.
I have kept a black strip on a white background .
The black strip is exactly in front of the sensor module.
But 0s are being displayed in a corner.
It should display 11111111111111111110000000000011111111111111111
but sometimes it displays 111111111000011111111101101101111111111 and not in the exact position.
Please help me Sir in solving this problem.
BTW, which program are you using? The one I provided displays 11111111........11111111, not 111111110000000011111111. It may be that, in your situation, you need more than just a simple logic threshold to compare the pixel values to. You might consider a board with built-in sigma-delta ADC capabilities, such as the Propeller Backpack or even the QuickStart (which requires some soldering to activate ADC). With full ADC, you will be able to incorporate edge enhancement, which can compensate for effects such as vignetting and, to a lesser extent, variable lighting.
-Phil
[EDIT/]
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
AO = 15 ' Camera Analog Output
SI = 14 ' Camera SI
CLK = 13 ' Camera clock
LED = 3
OBJ
Sio : "FullDuplexSerialPlus"
Ls : "TSL1401Binary"
VAR '
byte image[128] ' image values
long exp ' exposure time in milli seconds
Pub Main | i
Initialize
exp := 100 ' exp milliseconds
repeat
Ls.LedOn
Ls.GetImage(@image, exp) ' Get an image
Ls.LedOff
Sio.tx(0)
Sio.str(@ruler1) ' Print rulers
Sio.tx(13)
Sio.str(@ruler2)
Sio.tx(13)
repeat i from 0 to 127
Sio.dec(image) ' Print image
Sio.tx(13)
Sio.tx(13)
Sio.dec(Ls.CountPixels(0, 127, Ls#DRK, @image)) ' Count dark
Sio.tx(9)
Sio.dec(Ls.CountPixels(0, 127, Ls#BRT, @image)) ' Count light
Sio.tx(13)
Sio.dec(LS.FindPixel(0, 127, LS#DRK, LS#FWD, @image)) ' Find dark pixel forward
Sio.tx(13)
Sio.dec(LS.FindEdge(0, 127, LS#LTOD, LS#FWD, @image)) ' Find light to dark edge forward
Sio.tx(9)
Sio.Dec(Ls.FindEdge(0, 127, LS#LTOD, LS#BKWD, @image)) ' Find light to dark edge backward
Sio.tx(13)
Sio.Dec(Ls.FindEdge(0, 127, LS#DTOL, LS#FWD, @image)) ' Find dark to light edge forward
Sio.tx(13)
i := LS.FindLine(0, 127, LS#DRK, LS#FWD, @image) ' Find dark line forward
Sio.Dec(i >> 16)
Sio.tx(9)
Sio.Dec((i & $FF00) >> 8)
Sio.tx(9)
Sio.Dec(i & $FF)
Sio.tx(13)
i := LS.FindLine(0, 127, LS#DRK, LS#BKWD, @image) ' Find dark line backward
Sio.Dec(i >> 16)
Sio.tx(9)
Sio.Dec((i & $FF00) >> 8)
Sio.tx(9)
Sio.Dec(i & $FF)
repeat until !Sio.rxcheck ' wait for key from terminal
PUB Initialize
{{ Initialize the pins direction and state. Must be called once. }}
Sio.start(31,30,0,115200) ' Rx,Tx, Mode, Baud
Ls.Init(AO, SI, CLK, LED)
DAT
ruler1 byte " 1 2 3 4 5 6 7 8 9 10 11 12", 0
ruler2 byte "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567", 0
{{
───────────────────────────────────────────┘
}}
[/EDIT]
Please edit your post, in order to preserve indentation. Also, you've said nothing so far about what kind of illumination you're using.
Thanks,
-Phil