BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Sat Jan 20, 2018 7:46 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Connecting TCS230-DB to Bot Board 2
PostPosted: Wed Jan 09, 2013 8:24 pm 
Offline
New User

Joined: Wed Jan 09, 2013 7:57 pm
Posts: 4
Hi, this is my first post so please be patient. I try to connect the color sensor TCS230 but i have got a little problems with taking data from OUT of the sensor... I wrote program that i thought will save number of pulses recived from sensor to correct vaiable, but it won't work.

here is my hardware:
Bot Board 2 with Atom 28(i guess... because i don't know how to check it)
basic micro IDE 02.2.1.1
USB to serial connection
Taos TCS230

here is the way i connected it:
TCS230----------->Bot Board 2
S0-3-------------->P1-4
Vdd and 5V-------->5V
LED---------------->P0
GND--------------->GND...
OUT--------------->P8 and this one is the one I'm not sure about...

here is the code:
Code:
input p8
Out    CON p8
S0     con p1
S1     con p2
S3     CON p4
S2     CON p3
LED    CON p0
time   CON 50
RED    VAR Word
GREEN  VAR Word
BLUE   VAR Word
red=0
blue=0
green=0



Start:
   HIGH  LED
   high s1
   low s0
   
MainLp:
   GOSUB  Color
   pause 100
   if red>20 then czer
   pause 100
   if blue>1 then nieb
   pause 100
   if green>1 then ziel
   pause 100

GOTO  MainLp

Color:
   low  S2
   LOW  S3
   COUNT  Out, time, RED
   pause 3000
   HIGH  S3
   COUNT  Out, time, BLUE
   pause 3000
   HIGH  S2
   COUNT  Out, time, GREEN
   pause 3000
RETURN

czer:
   low led
   pause 100
   Sound 9,[800000\392]
   return
   
nieb:
   low led
   pause 100
   Sound 9,[20000\392]
   return
   
ziel:
   low led
   pause 100
   Sound 9,[80000\392]
   return


I wrote the strange function in the end of the code becouse my debugger doesn't work very well. It loses data... When i use such a comand:

Code:
debug ["I want all this come back to me",13]
pause 100


It gives me back something like
Quote:
I a c oo tm


but I dont really care. I need this sensor work.
Big thanks for any help.


Top
 Profile  
 
 Post subject: Re: Connecting TCS230-DB to Bot Board 2
PostPosted: Wed Jan 09, 2013 9:59 pm 
Offline
New User

Joined: Wed Jan 09, 2013 7:57 pm
Posts: 4
I've made a little change and it works a little better, i mean it make a signal so i guess it counts pulses. I've connected OUT--------->p18 (ax2) and i made appropriate changes to code.


Top
 Profile  
 
 Post subject: Re: Connecting TCS230-DB to Bot Board 2
PostPosted: Wed Jan 09, 2013 10:44 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
Let us know if you still need help. Is sounds like you may have it working now so I will wait until you reply.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Connecting TCS230-DB to Bot Board 2
PostPosted: Wed Jan 09, 2013 11:20 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
One thing I noticed is that your code in the mainloop does:
Code:
   if red>20 then czer
 

Which does a simple goto.

But when you look at czer
Code:
czer:
   low led
   pause 100
   Sound 9,[800000\392]
   return


It does a return. But there was no gosub so the program is likely to fault or go to some random place...

Good Luck
Kurt


Top
 Profile  
 
 Post subject: Re: Connecting TCS230-DB to Bot Board 2
PostPosted: Thu Jan 10, 2013 11:58 am 
Offline
New User

Joined: Wed Jan 09, 2013 7:57 pm
Posts: 4
Thanks for replays :)

I think it works but i still need to check if it works in the way i thought.

Refering to KurtEck replay:

I didn't know what is a diffrence between gosub or goto and i thought it makes no diffrence either i use goto or gosub. But now i will check the program with gosub.

Thanks once again. I will write more about my project soon :D


Top
 Profile  
 
 Post subject: Re: Connecting TCS230-DB to Bot Board 2
PostPosted: Thu Jan 10, 2013 4:27 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Yes there are differences between a goto and gosub.

A goto simply changes the location of where the next line of code is executed from. Once there it has no memory of how it got there...

Whereas a gosub, takes the location of the next command after where the gosub and remembers it, by pushing it onto a stack and then changes the location of the next command executed to the label you mentioned (like the goto). Then when you get to a return statement, it sets the address for the next command to be executed to where you last remembered (pops the address off the stack). So you need to keep the execution of gosub and return matched otherwise you will either return to garbage, or continue to add stuff onto the stack until it runs out of space and corrupts memory...

Hope that helps
Kurt


Top
 Profile  
 
 Post subject: Re: Connecting TCS230-DB to Bot Board 2
PostPosted: Sun Jan 20, 2013 4:12 pm 
Offline
New User

Joined: Wed Jan 09, 2013 7:57 pm
Posts: 4
Hi again.
Unfortunately I made a misatke... When I heard beep i thought It was caused by signal from sensor but it was just a signal from analog input, if it's passible ;/ When i changed examined element or remove it from sensor sight i still got the same value. What changes sholud I make in the code or how i should connect the sensor to make it work in right way?

I checked the signal from sensor on oscilloscope and it changes when i put diffrent colores in the frontof it. It gives digital signal with frequency depend of examined color.

Now i connect OUT to pin 8. I really have no idea what i do wrong...


Top
 Profile  
 
 Post subject: Re: Connecting TCS230-DB to Bot Board 2
PostPosted: Sun Jan 20, 2013 6:37 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
I noticed looking at the datasheet that they use different timings for different colors, not sure if that makes any difference. But from the PDF they have:
Code:
ut CON 7
S3 CON 0
S2 CON 1
LED CON 5
pRED CON 15
pGREEN CON 12
pBLUE CON 9
RED VAR Word
GREEN VAR Word
BLUE VAR Word
Start:
  HIGH LED
  MainLp:
  GOSUB Color
  DEBUG "R", DEC3 RED
  DEBUG " G", DEC3 GREEN
  DEBUG " B", DEC3 BLUE
  DEBUG CR
  GOTO MainLp
Color:
  LOW S2
  LOW S3
  COUNT Out, pRED, RED
  HIGH S3
  COUNT Out, pBLUE, BLUE
  HIGH S2
  COUNT Out, pGREEN, GREEN
  RETURN


In cases like this, I would have a tendency to have a program like this start off printing out the different color values, probably using serout to S_OUT and see if they change. Note: I would probably have it check to see if it changes before I print again...
(i.e. I don't use the debug command as running under debug often messes up timings and the like)

urt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO