1
\$\begingroup\$

I want to interface TCS3200 color sensor with STM32f746ZG. Since the TCS3200 outputs a frequency based on the amount of light received, I need some way to count the number of pulses for different colors to determine a color.

In CubeMX, I set PF6(s0) PF7(s1) PF8(s2) PF9(s3) and TIM2 ch1 input capture as (out) of the sensor. Frequency for timer 2, I selected to be 84MHz with prescalar 83 which will bring it to 1MHz (I am not sure whether I should do this or not). I also enabled TIM2 global interrupt in nvic window. Next, I activated TIM6 to measure time of 5s (timer f=84MHz, prescalar=41999 and counterperiod = 9999).

I have doubt about how to use these two timers inside the while loop, which HAL library functions to use here and how to use.

CubeMX is the source code generator and the IDE is Kiel5. Following is my setting for output frequency scaling and filter type outside the main function. If I am wrong, please correct me.

void TCSFREQ()

      {
    HAL_GPIO_WritePin(GPIOF,  s0_Pin,GPIO_PIN_SET);
     HAL_GPIO_WritePin(GPIOF,  s1_Pin,GPIO_PIN_RESET);
   }

void TCSRED()

      {
    HAL_GPIO_WritePin(GPIOF,  s2_Pin,GPIO_PIN_RESET);
     HAL_GPIO_WritePin(GPIOF,  s3_Pin,GPIO_PIN_RESET);
   }

void TCSBLUE()

      {
    HAL_GPIO_WritePin(GPIOF,  s2_Pin,GPIO_PIN_RESET);
     HAL_GPIO_WritePin(GPIOF,  s3_Pin,GPIO_PIN_SET);
   }

void GREEN()

      {
    HAL_GPIO_WritePin(GPIOF,  s2_Pin,GPIO_PIN_SET);
     HAL_GPIO_WritePin(GPIOF,  s3_Pin,GPIO_PIN_SET);
   }

void TCSCLEAR()

      {
    HAL_GPIO_WritePin(GPIOF,  s2_Pin,GPIO_PIN_SET);
     HAL_GPIO_WritePin(GPIOF,  s3_Pin,GPIO_PIN_RESET);
   }

Correct me if there is something wrong above.

As I am new to microcontrollers, I am struggling with how to count the number of pulses in a time period (let's say 5s). It would be nice if you would help me with my problem or suggest some alternative solution.

How do I count the no of pulses from output of that sensor?

\$\endgroup\$
  • \$\begingroup\$ alternative solution dfrobot.com/wiki/index.php/TCS3200_Color_Sensor_(SKU:SEN0101) \$\endgroup\$ – Sunnyskyguy EE75 Jan 9 '18 at 16:09
  • \$\begingroup\$ Timers in interrupt mode, work independently of the while loop! If your question is about how to configure timers to measure a pulse in input capture mode, you can start with some example libraries. ST provided several example libraries, for you stm32f7cube is relevant. \$\endgroup\$ – charansai Jan 9 '18 at 22:33
  • \$\begingroup\$ Please write a specific question so it's clear to others what question you want answered. \$\endgroup\$ – laptop2d Jan 11 '18 at 3:59
  • \$\begingroup\$ @laptop2d ..how to count no of pulses from output of that sensor? \$\endgroup\$ – Asim A Qayyum Jan 11 '18 at 16:16

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.