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:
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):
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:
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.
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
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
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.
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.
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
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.