EM2019WSP06/Implementierungsdetails

Aus Verteilte Systeme - Wiki
< EM2019WSP06
Version vom 15. März 2020, 16:35 Uhr von Mmait001 (Diskussion | Beiträge) (→‎Color Sensing)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

Source Code

Source Code can be found here

Implementations hints

PWM

In order to use the PWM Service from the Zephyr OS, some steps should be done:

-Enable PWM. This can be done in the .conf file project, or on the board .defconfig file. The first option is the best practice according to the Zephyr Documentation.

# Enable PWM
CONFIG_PWM=y 
# Enable PWM of Timer 2
CONFIG_PWM_STM32_2=y


- Enable the Hardware part of the Microcontroller. This can be done in the .overlay file of the project or in the .dts file of the board. Again the first option was choose.

&timers2 {
	status = "okay";
    pwm {
		status = "okay";
	};
};

This two steps are necessary for the use of the PWM Service of the Zephyr OS. And they worked fine in other boards like the nRf52, but for the ST Nucleo F446RE it did not. Other steps were needed:

-In the Zephyr Os: go to "/zephyr/boards/arm/nucleo_f446re/pinmux.c"

Here the connection between the Board Pin and the Board PWM Chanel need to be done:

#ifdef CONFIG_PWM_STM32_2
	{STM32_PIN_PA0, STM32F4_PINMUX_FUNC_PA0_PWM2_CH1},
#endif

"/zephyr/include/dt-bindings/pinctrl/stm32-pinctrl-common.h" // pinout of the board, STM32_PIN_PA0 can be found here.

"/zephyr/drivers/pinmux/stm32/pinmux_stm32f4.h" // pin multiplexing helper, STM32F4_PINMUX_FUNC_PA0_PWM2_CH1 can be found here.

Color Sensing

The function color_get(), returns the color detected.

color_t color_get()
{
	red = us_get(red_f);
	k_sleep(10);
	green = us_get(green_f);
	k_sleep(10);
	blue = us_get(blue_f);
	k_sleep(10);
	if (red > 80 && green < 35 && green > 20) {
		return RED;
	} else if (red < 40 && blue < 40 && green < 20) {
		return BLUE;
	} else {
		return CLEAR;
	}
}

Note that the values for determinate a color (80, 35, 20)(40,40,20), are not fix. These values worked on a specific environment, and depending on the light or distance this values will change and so should the values on the function too. Green Color can be added.