FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    Proteus8.9 simulation STM32407ZGT6 series 009_PWM multi-way adjustable duty cycle output

     

    "I. open the file (you can download it with the text and open it 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) uint32_ t gt_ fig(u8 sts){ if(1== sts) return TIM_ GetCapture1(TIM4); if(2== sts) return TIM_ GetCapture2(TIM4); if(3== sts) return TIM_ GetCapture3(TIM4); if(4== sts) return TIM_ GetCapture4(TIM4); } void st_ fig(u8 sts, uint32_ t gt){ if(1== sts) TIM_ SetCompare1(TIM4, gt); if(2== sts) TIM_ SetCompare2(TIM4, gt); if(3== sts) TIM_ SetCompare3(TIM4, gt); if(4== sts) TIM_ SetCompare4(TIM4, gt); } int main(void) { u16 psc=840, per=600, idc[4]= {500, 200, 300, 400}; u16 umd, pwmval=0; u8 status= 0, dir= 1; int gtln= 0; char *wd, *wds, lnslt[5]={'_', ' A', 'B', 'C', 'D'}; 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""); LED0= LED1= LED2= 1; Pwm_ Init(psc, per); TIM_ SetCompare1(TIM4, idc[0]); TIM_ SetCompare2(TIM4, idc[1]); TIM_ SetCompare3(TIM4, idc[2]); TIM_ SetCompare4(TIM4, idc[3]); Uprint ("" control chip stm32f407zgt6_ 008_ PWM simulation begins\ r\n""); delay_ ms(100); while(1) { wd[0]=lnslt[status]; wd[1]= 0; Uprint ("" arm runtime... Duty cycle ""); uprint(wd); Uprint ("line adjustable status: \ R \ n" "); if(1==ReadKey(GPIOC, 0x0080)) { status++; delay_ ms(20); if(status> 4) status= 0; wd[0]=lnslt[status]; wd[1]= 0; Uprint ("" line adjustment status... Duty cycle ""); uprint(wd); Uprint ("line adjustable status: \ R \ n" "); } if(1==ReadKey(GPIOC, 0x0010)) { LED0= 1; pwmval= gt_ fig(status); gtln= nmtoa(wds, 10, pwmval); if(status>0){ if(per< (pwmval+ 50)) { Uprint ("line adjustment, duty cycle reaches the highest value... \ R \ n" "); st_ fig(status, (per+ 1)); } else{ LED0= 1; pwmval= gt_ fig(status); gtln= nmtoa(wds, 10, pwmval); umd= pwmval +50; Uprint ("line adjustment, duty cycle from" "); uprint(wds); Uprint ("" increase by 50 ""); uprint("" ...\r\n ""); st_ fig(status, umd); } } } if(1==ReadKey(GPIOC, 0x0020)) { LED1= 1; delay_ ms(20); pwmval= gt_ fig(status); gtln= nmtoa(wds, 10, pwmval); Uprint ("" arm runtime... Duty cycle ""); uprint(wd); Uprint ("line adjustment by" "); uprint(wds); Uprint ("" clear ""); uprint("" ...\r\n ""); st_ fig(status, 0); } if(1==ReadKey(GPIOC, 0x0040)) { LED2= 1; pwmval= gt_ fig(status); gtln= nmtoa(wds, 10, pwmval); if(pwmval> 50) umd= pwmval -50; else umd= 1; Uprint ("line adjustment, duty cycle from" "); uprint(wds); Uprint ("" reduce by 50 ""); uprint("" ...\r\n ""); st_ fig(status, umd); } LED0= LED1= LED2= 0; delay_ ms(100); } } Timer. C code: #include ""mfuncs.h"" #include ""timer.h"" #include ""led.h"" void PWM_ GPIO(void){ GPIO_ InitTypeDef GPIO_ InitStructure; RCC_ AHB1PeriphClockCmd(RCC_ AHB1Periph_ GPIOB, ENABLE); GPIO_ InitStructure.GPIO_ Pin = GPIO_ Pin_ 5|GPIO_ Pin_ 6|GPIO_ Pin_ 7|GPIO_ Pin_ 8|GPIO_ Pin_ 9; GPIO_ InitStructure.GPIO_ Mode = GPIO_ Mode_ AF; GPIO_ InitStructure.GPIO_ OType = GPIO_ OType_ PP; GPIO_ InitStructure.GPIO_ PuPd = GPIO_ PuPd_ NOPULL; GPIO_ InitStructure.GPIO_ Speed = GPIO_ Speed_ 100MHz; GPIO_ Init(GPIOB, &GPIO_ InitStructure); GPIO_ PinAFConfig(GPIOB, GPIO_ PinSource5, GPIO_ AF_ TIM3); GPIO_ PinAFConfig(GPIOB, GPIO_ PinSource6, GPIO_ AF_ TIM4); GPIO_ PinAFConfig(GPIOB, GPIO_ PinSource7, GPIO_ AF_ TIM4); GPIO_ PinAFConfig(GPIOB, GPIO_ PinSource8, GPIO_ AF_ TIM4); GPIO_ PinAFConfig(GPIOB, GPIO_ PinSource9, GPIO_ AF_ TIM4); } //PWM timer configuration void Pwm_ Init(u16 TimerPrescaler, u32 TimerPeriod) { PWM_ GPIO(); TIM_ TimeBaseInitTypeDef TIM_ TimeBaseStructure; TIM_ OCInitTypeDef TIM_ OCInitStructure; RCC_ APB1PeriphClockCmd(RCC_ APB1Periph_ TIM4 , ENABLE); TIM_ TimeBaseStructure.TIM_ Prescaler = TimerPrescaler-1; // Clock prescaled frequency TIM_ TimeBaseStructure.TIM_ CounterMode = TIM_ CounterMode_ Up; // Count up TIM_ TimeBaseStructure.TIM_ Period = TimerPeriod-1; // The value of the auto reload register TIM_ TimeBaseStructure.TIM_ ClockDivision = 0; TIM_ TimeBaseStructure.TIM_ RepetitionCounter = 0; // Repeat register to automatically update PWM duty cycle TIM_ TimeBaseInit(TIM4, &TIM_ TimeBaseStructure); TIM_ OCInitStructure.TIM_ OCMode = TIM_ OCMode_ PWM1; TIM_ OCInitStructure.TIM_ OutputState = TIM_ OutputState_ Enable; TIM_ OCInitStructure.TIM_ OutputNState = TIM_ OutputNState_ Enable; // Enable this channel output TIM_ OCInitStructure.TIM_ OCPolarity = TIM_ OCPolarity_ Low; // Set complementary output polarity TIM_ OCInitStructure.TIM_ OCNPolarity = TIM_ OCNPolarity_ High; // Enable complementary output

     

     

     

     

    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