Difference: TCS3200 (8 vs. 9)

Revision 92022-07-09 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

TCS3200 Color Sensor

Introduction

Line: 90 to 90
  The white paper

white.png

Changed:
<
<

Measuring the frequency

>
>

Measuring the frequency by measurement of the time elapsed for a fixed amount of cycles

  In order to measure the frequency, the time elapsed for the detection of a number of OUT signal cycles is measured. The number of cycles to be used is set in the cycles variable. Of course, we again need getter and setter methods to control _cycles. We attach an interrupt handler to the OUT pin (_cbfwhich stands for _callback function). The number of cycles, already measured, is saved in the _cycle (without the "s"). This value is set to zero when the interrupt handler is started (connected to _cbf). When the first rising edge of the signal is seen, the current system clock in us is saved in _start_tick. For each rising edge of the OUT signal, _cycle is incremented until the value In _cycles is reached, in which case the system clock is saved in _end_tick. The duration between the start of the measurement and the moment the number of requested cycles has been seen is then
Line: 107 to 107
 This teaches us an important lesson: The time between two rising edges for the white target is just 435 us. If we change the frequency divider to 20% this time would be reduced to 43 us, which is simply too short an interval for our interrupt handler. The program can handle a 20% frequency divider setting for the black target, in which case the interval is 263 us (1000000/3800), but it will crash for the white target because it will receive new interrupts while the old ones have not been entirely treated.

If we want to read the OUT signal at full speed, then an external high speed counter is needed. Otherwise, we can fix the S0 and S1 signals to 0 and 1 respectively and therefore fix the frequency divider to 2%. This liberates 2 GPIO lines for other purposes.

Changed:
<
<

Timeouts

>
>

Timeouts

  There is still a problem with the meas_freq.py program.
The code:
Deleted:
<
<
 
    while tcs3200._end_tick == 0:
        time.sleep_ms(10)

will wait forever, if the number of cycles to be measured, is never reached. This can happen e.g. if the OUT signal is assigned a wrong GPIO pin. The problem can be solved by starting a timeout counter when the measurement is started. This counter can be used to raise an exception if reaching the _cycles limit takes too long.

timeout.py is the same program as meas_freq.py with the timeout counter added. The timeout is set to 2s. The number of cycles to be measured is set to 10000 in order to provoke the timeout.

Added:
>
>

Measuring the frequency by counting the number of cycles for a fixed measurement duration

In this case, we simply read the number of rising (or falling) edges that occur during a fixed amount of time (default 1s). The resolution may be not a good as for the method above, but it is much simpler from the programming point of view. When starting a measurement, we connect the OUT signal to an interrupt handler, triggered through the rising (or falling) edge of OUT, counting the number of times it has been called. We also start a one shot timer that disables the interrupt handler as soon as the measurement period is over.

Here we do not need timeout treatment because the timer will always trigger and we will simply read zero counts when the OUT signal does not respond.

An example is given in TCS3200_v2.py and meas_freq_v2.py.

 

Calibration

The formula for the calculation of rgb values is given by:

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback