2994 views|5 replies

931

Posts

3

Resources
The OP
 

GD32E231 DIY Competition (7) - Human infrared sensor module and music IC driver completed [Copy link]

This post was last edited by hujj on 2019-5-13 18:50 After several days of hard work, I finally successfully drove the human infrared sensor module and music IC. The picture below is the test process: This is the front of the human infrared sensor module: The human infrared sensor module is a finished product purchased online (see the figure below). It has three pins, VCC, OUT, and GND. When the sensor receives information, it outputs a high level. I connected it to the PA5 pin and enabled the interrupt at the same time. The picture below is a close-up of the module taken from the Internet: The following is the interrupt configuration code: void exti_config(void) { /* enable the clock */ rcu_periph_clock_enable(RCU_GPIOA); rcu_periph_clock_enable(RCU_CFGCMP); /* configure GPIO as input */ gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_5); /* enable and set EXTI interrupt */ nvic_irq_enable(EXTI4_15_IRQn, 1U); /* connect EXTI line to GPIO pin */ syscfg_exti_line_config(EXTI_SOURCE_GPIOA, EXTI_SOURCE_PIN5); /* configure EXTI line */ exti_init(EXTI_5, EXTI_INTERRUPT, EXTI_TRIG_FALLING); exti_interrupt_flag_clear(EXTI_5); } The following is the code for interrupt handling. I only set the mode to 9 during interrupt handling and then process it in the main loop: At this point, the hardware part of the project is basically completed, and software debugging is about to begin. void EXTI4_15_IRQHandler(void) { if(RESET != exti_interrupt_flag_get(EXTI_5)){ // gd_eval_led_toggle(LED2); mode = 9; //Establish alarm flag } exti_interrupt_flag_clear(EXTI_5); } It didn't take much effort to drive this module. The connection test was successful at one time. However, it took quite a bit of trouble to choose the music IC. In my project, I plan to use different sounds for alarms at different times. I started to plan to use multiple music ICs to complete it, but when I tested it, I found that the effect of sharing the speakers was very poor and unacceptable. It would be too troublesome to use multiple speakers at the same time. Finally, I had to use a four-tone alarm music IC (see the figure below): The following is a four-tone alarm music IC soldered on the expansion board: This music IC has two setting keys, and K2 is used to control the sound of a machine gun. I did not enable this key. K1 can be connected to floating, high level and low level. When floating, it will sound a police car siren, when connected to high level, it will sound a fire truck siren, and when connected to low level, it will sound an ambulance siren. I control it through the PA4 pin. When it is floating, set the pin to the input floating state. When it is high or low level, set it to the output state and then set the pin level. After testing, I have achieved good results. The following is the setting code:
  1. /*! \brief Alarm mode setting\param[in] type: 0=low level, 1=high level, 2=floating\param[out] none \retval none */ void alarm_type(uint8_t type) { if(type>1){ gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE,GPIO_PIN_4); //Input mode gd_eval_led_on(LED4); } else{ gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_4); gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_4); if(type==0){ gd_eval_led_on(LED2); gpio_bit_reset(GPIOA, GPIO_PIN_4); } else{ gd_eval_led_on(LED3); gpio_bit_set(GPIOA,GPIO_PIN_4); } } }
复制代码
Since this music IC will sound when powered on and stop when powered off, an electronic switch is needed to control it. I didn’t expect that this simplest transistor switch circuit took two days. At first, I just took a 3DG201 and a base current limiting resistor to weld a switch circuit. Who knows that the test did not achieve the purpose. Repeatedly changing the transistor and the base current limiting resistor did not work. The music IC could not sound normally. Finally, I had to analyze the circuit carefully and found that if you need to control the positive pole, you need to use a PNP tube, and if you need to control the negative pole, you need to use an NPN tube. I used an NPN tube to control the positive pole, so it was unsuccessful. Finally, I changed a 9015PNP tube and adjusted the base current limiting resistor to meet the requirements (see the figure below). So far, the hardware part of this project has been basically completed, and the next step is to start software debugging.



This post is from GD32 MCU

Latest reply

Why do we need to use music IC? Doesn’t the microcontroller have PWM?  Details Published on 2019-5-17 09:58
 

111

Posts

0

Resources
2
 
When I was working on the mp4 module before, I also made a switch circuit to stop the power supply of the mp4 module in order to achieve low power consumption. As a result, the sound of the mp4 module op amp was abnormal when the switch circuit was made of 8050. Later, I changed to an optocoupler IC pc817, and there was no sound at all. In the end, I had no choice but to use a huge blue optocoupler, the kind that makes a clicking sound. I wonder how much resistance you use in this 9015 circuit? I also want to try it
This post is from GD32 MCU

Comments

The pull-down resistor is 150K, and the current limiting resistor is 3.3K at first, but it can't play normally. Later, I connected a fine-tuning resistor to test, and finally chose a 1K resistance. It is recommended that you also use fine-tuning resistors to test and choose the appropriate resistance value.  Details Published on 2019-5-17 08:42
 
 
 

931

Posts

3

Resources
3
 
tinnu published on 2019-5-17 00:29 When I made the mp4 module before, I also made a switch circuit to stop the power supply of the mp4 module in order to achieve low power consumption. As a result, the switch circuit made by 8050, the mp4 module...
The pull-down resistor was 150K, and the current limiting resistor was 3.3K at first, but it could not play normally. Later, I connected a fine-tuning resistor to test, and finally chose a 1K resistance value. It is recommended that you also use fine-tuning resistors to actually test and choose the appropriate resistance value.
This post is from GD32 MCU
 
 
 

931

Posts

3

Resources
4
 
    If the resistance value of the base current limiting resistor is too large, the transistor cannot enter the saturation state and cannot function as a switch; if the resistance value is too small, it will increase the burden on the GPIO pin of the microcontroller and may even burn out the pin.
This post is from GD32 MCU
 
 
 

606

Posts

20

Resources
5
 
Why do we need to use music IC? Doesn’t the microcontroller have PWM?
This post is from GD32 MCU

Comments

231 not only has PWM, but also has two op amps, which is fully capable of driving speakers. This solution can also record sound files by itself, which is more flexible and convenient. But I have not yet set foot in these applications. In order to complete the project plan first, I will use the music IC first, and consider enabling I2S when the project is improved later.  Details Published on 2019-5-17 10:13
 
 
 

931

Posts

3

Resources
6
 
ketose posted on 2019-5-17 09:58 Why use music IC? Doesn't the microcontroller have PWM?
231 not only has PWM, but also has two op amps, which is fully capable of driving speakers. This solution can also record sound files by itself, which is more flexible and convenient. But I haven't been involved in these applications yet. In order to complete the project plan first, I will use the music IC first, and consider enabling I2S when the project is improved later.
This post is from GD32 MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list