Difference: TCS3200 (3 vs. 4)

Revision 42022-05-17 - UliRaich

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

TCS3200 Color Sensor

Introduction

Line: 58 to 58
 

Towards reading the frequency of the OUT signal

In order to better understand the TCS3200 it is necessary to get a feeling for the frequencies it emits. In order to measure this frequency, we must be able to set the filter and the frequency divider. This is done in the program filter_and_freq.py. The test program sets debugging mode, and it writes and reads back the filter and frequency divider settings.

Changed:
<
<
Measuring the frequency
>
>

Measuring the frequency

 
Changed:
<
<
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 (_cbf 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
>
>
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
  duration =_end_tick - _start_tick
Line: 75 to 75
 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.

Added:
>
>

Timeouts

  There is still a problem with the meas_freq.py program.
The code:
Added:
>
>
 
    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.

Changed:
<
<
Calibration
>
>

Calibration

  -- Uli Raich - 2022-05-16

Comments

 
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