FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    Proteus8.9 Simulation STM32407ZGT6 Series 008_PWM Output

     

    "One, Open the file (which can be downloaded and placed in the document)( (as shown in Figure 1 below) Figure 1 2、 Adjust the virtual device and save the project file as( (as shown in Figure 2, 3 and 4 below) Figure 2 Figure 3 Figure 4 3、 Click the source code tab( (as shown in Figure 5 below) Figure 5 4、 Edit the codes of main. C, timer. C, timer. H, key. C, key. H, led. C and led. H, as shown in proteus8.9 simulation stm32407zgt6 Series 001 (as shown in Figure 6 below) Figure 6 5、 Main. C code: /* Main.c file generated by New Project wizard * Author: Ziegler Yin * Created: Thursday January 16 2020 * Processor: STM32F407ZGT6ZGT6 * Compiler: GCC for ARM */ #include ""mfuncs.h"" #include ""delay.h"" #include ""usart.h"" #include ""led.h"" #include ""key.h"" #include ""TImer.h"" #define RT(A , B) (A> 300)? ( B= 0): ( B=1) int main(void) { u16 pwmval=0; u8 dir=1; NVIC_ PriorityGroupConfig(NVIC_ PriorityGroup_ 2);// Set system interrupt priority group 2 delay_ init(168); // Initialization delay function uart_ init(9600);// The baud rate of initialization serial port is 115200 LED_ Init(); KEY_ Init(); Uprint ("" Hello everyone\ r\n""); Let's build a ventilator\ r\n""); Uprint ("" control chip stm32f407zgt6_ 008_ PWM simulation begins\ r\n""); LED0= LED1= LED2= 1; TIM4_ PWM_ Init(500-1,840-1); // 84m / 84 = 1MHz counting frequency, reload value 500, so PWM frequency is 1m / 500 = 2KHz TIM_ SetCompare1(TIM4, pwmval); While (1) / / the comparison value is incremented from 0-300 to 300 and then decremented from 300-0. The loop { Uprint ("" arm runtime... \ R \ n ""); if(1==ReadKey(GPIOC, 0x0010)) { LED0= 1; Uprint ("" duty cycle increase... \ R \ n ""); if(dir) pwmval+=10; RT(pwmval , dir); } if(1==ReadKey(GPIOC, 0x0020)) { LED1= 1; Uprint ("" duty cycle reset... \ R \ n ""); if(dir) pwmval= 0; RT(pwmval , dir); } if(1==ReadKey(GPIOC, 0x0040)) { LED2= 1; Uprint ("" duty cycle reduction... \ R \ n ""); if(dir) pwmval-=10; RT(pwmval , dir); } TIM_ SetCompare1(TIM4, pwmval); delay_ ms(100); LED0= LED1= LED2= 0; } } Timer. C code: #include ""mfuncs.h"" #include ""timer.h"" #include ""led.h"" void TIM4_ PWM_ Init(u32 arr,u32 psc) { // In this part, you need to manually modify the IO port settings GPIO_ InitTypeDef GPIO_ InitStructure; TIM_ TimeBaseInitTypeDef TIM_ TimeBaseStructure; TIM_ OCInitTypeDef TIM_ OCInitStructure; RCC_ APB1PeriphClockCmd(RCC_ APB1Periph_ TIM4, ENABLE); // TIM4 clock enable RCC_ AHB1PeriphClockCmd(RCC_ AHB1Periph_ GPIOB, ENABLE); // Enable portb clock GPIO_ PinAFConfig(GPIOB, GPIO_ PinSource6, GPIO_ AF_ TIM4); // Gpiob6, 7 and 8 are multiplexed into timer 4 GPIO_ PinAFConfig(GPIOB, GPIO_ PinSource7, GPIO_ AF_ TIM4); // Gpiob6, 7 and 8 are multiplexed into timer 4 GPIO_ PinAFConfig(GPIOB, GPIO_ PinSource8, GPIO_ AF_ TIM4); // Gpiob6, 7 and 8 are multiplexed into timer 4 GPIO_ InitStructure.GPIO_ Pin = GPIO_ Pin_ 6| GPIO_ Pin_ 7| GPIO_ Pin_ 8; // GPIOB6, 7, 8 GPIO_ InitStructure.GPIO_ Mode = GPIO_ Mode_ AF; // Reuse function GPIO_ InitStructure.GPIO_ Speed = GPIO_ Speed_ 100MHz; // Speed 100MHz GPIO_ InitStructure.GPIO_ OType = GPIO_ OType_ PP; // Push pull multiplex output GPIO_ InitStructure.GPIO_ PuPd = GPIO_ PuPd_ UP; // Pull up GPIO_ Init(GPIOB, &GPIO_ InitStructure); // Initialize PB TIM_ TimeBaseStructure.TIM_ Prescaler= psc; // Timer frequency division TIM_ TimeBaseStructure.TIM_ CounterMode= TIM_ CounterMode_ Up; // Count up mode TIM_ TimeBaseStructure.TIM_ Period= arr/ 5; // Automatic reload value TIM_ TimeBaseStructure.TIM_ ClockDivision= TIM_ CKD_ DIV1; TIM_ TimeBaseInit(TIM4, &TIM_ TimeBaseStructure);// Initialization timer 4 // Initialize TIM4 Channel1 PWM mode TIM_ OCInitStructure.TIM_ OCMode = TIM_ OCMode_ PWM1; // Select timer mode: Tim pulse width modulation mode 2 TIM_ OCInitStructure.TIM_ OutputState = TIM_ OutputState_ Enable; // Compare output enable TIM_ OCInitStructure.TIM_ OCPolarity = TIM_ OCPolarity_ Low; // Output polarity: Tim output is relatively low polarity TIM_ OC1Init(TIM4, &TIM_ OCInitStructure); // Initialize the peripheral tim14 according to the parameters specified by T TIM_ OC1PreloadConfig(TIM4, TIM_ OCPreload_ Enable); // Enable TIM4 preload register on CCR1 TIM_ TimeBaseStructure.TIM_ Prescaler= psc; // Timer frequency division TIM_ TimeBaseStructure.TIM_ CounterMode= TIM_ CounterMode_ Up; // Count up mode TIM_ TimeBaseStructure.TIM_ Period= arr/ 2; // Automatic reload value TIM_ TimeBaseStructure.TIM_ ClockDivision= TIM_ CKD_ DIV1; TIM_ TimeBaseInit(TIM4, &TIM_ TimeBaseStructure);// Initialization timer 4 // Initialize TIM4 Channel1 PWM mode TIM_ OCInitStructure.TIM_ OCMode = TIM_ OCMode_ PWM1; // Select timer mode: Tim pulse width modulation mode 2 TIM_ OCInitStructure.TIM_ OutputState = TIM_ OutputState_ Enable; // Compare output enable TIM_ OCInitStructure.TIM_ OCPolarity = TIM_ OCPolarity_ Low; // Output polarity: Tim output is relatively low polarity TIM_ OC1Init(TIM4, &TIM_ OCInitStructure); // Initialize the peripheral TIM1 according to the parameters specified by T TIM_ OC2PreloadConfig(TIM4, TIM_ OCPreload_ Enable); // Enable TIM4 preload register on CCR1 TIM_ TimeBaseStructure.TIM_ Prescaler= psc; // Timer frequency division TIM_ TimeBaseStructure.TIM_ CounterMode= TIM_ CounterMode_ Up; // Count up mode TIM_ TimeBaseStructure.TIM_ Period= arr; // Automatic reload value TIM_ TimeBaseStructure.TIM_ ClockDivision= TIM_ CKD_ DIV1; TIM_ TimeBaseInit(TIM4, &TIM_ TimeBaseStructure);// Initialization timer 14 // Initialize TIM4 Channel1 PWM mode TIM_ OCInitStructure.TIM_ OCMode = TIM_ OCMode_ PWM1; // Select timer mode: Tim pulse width modulation mode 2 TIM_ OCInitStructure.TIM_ OutputState = TIM_ OutputState_ Enable; // Compare output enable TIM_ OCInitStructure.TIM_ OCPolarity = TIM_ OCPolarity_ Low; // Output polarity: Tim output is relatively low polarity TIM_ OC1Init(TIM4, &TIM_ OCInitStructure); // Initialize the peripheral TIM1 4oc1 according to the parameters specified by T TIM_ OC3PreloadConfig(TIM4, TIM_ OCPreload_ Enable); // Enable TIM4 preload register on CCR1 TIM_ ARRPreloadConfig(TIM4, ENABLE); // ARPE enable TIM_ Cmd(TIM4, ENABLE); // Enable TIM4 } Timer. H code #ifndef _ TIMER_ H #define _ TIMER_ H #include ""sys.h"" void TIM4_ PWM_ Init(u3

     

     

     

     

    List all Question

    Nickname

    Email

    Questions

    Our other product:

    Professional FM Radio Station Equipment Package

     



     

    Hotel IPTV Solution

     


      Enter email  to get a surprise

      fmuser.org

      es.fmuser.org
      it.fmuser.org
      fr.fmuser.org
      de.fmuser.org
      af.fmuser.org ->Afrikaans
      sq.fmuser.org ->Albanian
      ar.fmuser.org ->Arabic
      hy.fmuser.org ->Armenian
      az.fmuser.org ->Azerbaijani
      eu.fmuser.org ->Basque
      be.fmuser.org ->Belarusian
      bg.fmuser.org ->Bulgarian
      ca.fmuser.org ->Catalan
      zh-CN.fmuser.org ->Chinese (Simplified)
      zh-TW.fmuser.org ->Chinese (Traditional)
      hr.fmuser.org ->Croatian
      cs.fmuser.org ->Czech
      da.fmuser.org ->Danish
      nl.fmuser.org ->Dutch
      et.fmuser.org ->Estonian
      tl.fmuser.org ->Filipino
      fi.fmuser.org ->Finnish
      fr.fmuser.org ->French
      gl.fmuser.org ->Galician
      ka.fmuser.org ->Georgian
      de.fmuser.org ->German
      el.fmuser.org ->Greek
      ht.fmuser.org ->Haitian Creole
      iw.fmuser.org ->Hebrew
      hi.fmuser.org ->Hindi
      hu.fmuser.org ->Hungarian
      is.fmuser.org ->Icelandic
      id.fmuser.org ->Indonesian
      ga.fmuser.org ->Irish
      it.fmuser.org ->Italian
      ja.fmuser.org ->Japanese
      ko.fmuser.org ->Korean
      lv.fmuser.org ->Latvian
      lt.fmuser.org ->Lithuanian
      mk.fmuser.org ->Macedonian
      ms.fmuser.org ->Malay
      mt.fmuser.org ->Maltese
      no.fmuser.org ->Norwegian
      fa.fmuser.org ->Persian
      pl.fmuser.org ->Polish
      pt.fmuser.org ->Portuguese
      ro.fmuser.org ->Romanian
      ru.fmuser.org ->Russian
      sr.fmuser.org ->Serbian
      sk.fmuser.org ->Slovak
      sl.fmuser.org ->Slovenian
      es.fmuser.org ->Spanish
      sw.fmuser.org ->Swahili
      sv.fmuser.org ->Swedish
      th.fmuser.org ->Thai
      tr.fmuser.org ->Turkish
      uk.fmuser.org ->Ukrainian
      ur.fmuser.org ->Urdu
      vi.fmuser.org ->Vietnamese
      cy.fmuser.org ->Welsh
      yi.fmuser.org ->Yiddish

       
  •  

    FMUSER Wirless Transmit Video And Audio More Easier !

  • Contact

    Address:
    No.305 Room HuiLan Building No.273 Huanpu Road Guangzhou China 510620

    E-mail:
    [email protected]

    Tel / WhatApps:
    +8618078869184

  • Categories

  • Newsletter

    FIRST OR FULL NAME

    E-mail

  • paypal solution  Western UnionBank OF China
    E-mail:[email protected]   WhatsApp:+8618078869184   Skype:sky198710021 Chat with me
    Copyright 2006-2020 Powered By www.fmuser.org

    Contact Us