Saturday, February 5, 2011

Wedneday week 4

The color sensor i built was nice, but now we need a way to interface it and do something useful.We modified our circuit to produce a single signal line to interface with the VEX PIC microcontroller. The options were to use the original code and output 2 digital signals (1 or 0) or output an analog signal using a single 3 pin connector. I chose the latter. I modified my code to produce a PWM out signal depending on the color the sensor "sees".
The old output section of the code looked like this:
nocolor:
 serout 0,N2400,("nocolor",13,10)
 high 4,5
goto main

red:
 serout 0,N2400,("red",13,10)
 low 4
 high 5
goto main

blue:
 serout 0,N2400,("blue",13,10)
 high 4
 low 5
goto main

green:
 serout 0,N2400,("green",13,10)
 low 4,5
goto main
I modified it to look like this:
RED:
 pwmout 2, 99, 0  ; Set the Ouput to 0V
goto main

GREEN:
 pwmout 2, 99, 125  ' Set the Output to 1.5 V
goto main

BLUE:
 pwmout 2, 99, 250  ' Set the Outut to 3 V
goto main

NONE:
  pwmout 2,99,400   ' Set the Output to 5V
goto main
The vex brain's sensor ports don't recognize PWM inputs directly, but by adding a capacitor on the PWM signal line, we can change the signal into a (mostly) continuous voltage which the brain can interpret as analog signal. The duty cycle of the PWM signal determines voltage. My next step was to put it all on perfboard so it's nice and compact. After doing this, I'm done! I now have a sensor for our vex robot!

No comments:

Post a Comment