Home > other >  About the number hair fixed pulse frequency PWM method
About the number hair fixed pulse frequency PWM method

Time:09-17


1. The use of two timer2. Send A PWM timer, another timer cycle is 1 ms B;
3. A timer interrupt flag inside judgment, is the current acceleration or deceleration, or is uniform, flags to A timer interrupt, B B timer interrupt to add and subtract frequency values inside at the same time in A other main loop function of timer ARR assignment (can guarantee the change frequency values of "real time");
4. So the question comes, in so doing, the data transfer between two interrupt will have a problem? Such as the sign bit will change and so on, wait for a great god,

CodePudding user response:

Simple to use a global variable

CodePudding user response:

reference 1st floor xuweiwei1860 response:
simple with a global variable

The elder brothers, good easy ah, you say,,

CodePudding user response:

refer to the second floor qq_31195831 response:
Quote: refer to 1st floor xuweiwei1860 response:

Simple to use a global variable

The elder brothers, good easy ah, you say,,

I did open two timers, respectively in the interrupt handler set the gpio 0 and 1, the main function of the calculation of frequency and then modify the timer timing time, really easy

CodePudding user response:

reference xuweiwei1860 reply: 3/f
Quote: refer to the second floor qq_31195831 response:

Quote: refer to 1st floor xuweiwei1860 response:

Simple to use a global variable

The elder brothers, good easy ah, you say,,

I did open two timers, respectively in the interrupt handler set the gpio 0 and 1, the main function of the calculation of frequency and then modify the timer timing time, really easy to

What you do is turn,,,
What I said is PWM timer function, but also do deceleration
If there is not the same thing don't reply,,, thank god

CodePudding user response:

Do you want to do PWM inverter, B timers do frequency conversion, A PWM?

Global variables, pay attention to take the keyword volatile, and then, if reading and writing, be don't add critical OuDeJia unlock, if you can, try not to use,

CodePudding user response:

reference 5 floor lr2131 reply:
do you want to do PWM inverter, B timer do inverter, PWM A do?

Global variables, pay attention to take the keyword volatile, and then, if reading and writing, be don't add critical OuDeJia unlock, if you can, try not to use,

Why want to add a volatile keyword, and need not have what distinction, could you explain it

CodePudding user response:

refer to 6th floor qq_31195831 response:
Quote: refer to the fifth floor lr2131 reply:

Do you want to do PWM inverter, B timers do frequency conversion, A PWM?

Global variables, pay attention to take the keyword volatile, and then, if reading and writing, be don't add critical OuDeJia unlock, if you can, try not to use,

Why want to add a volatile keyword, and need not have what distinction, could you explain it


Give you a summary, a global variable, in a multi-threaded or similar to the "multi-threaded" read and write access, should add the key word. No, read "dirty data" phenomenon,
Multi-threaded since don't have to say more, on the single chip microcomputer operating system, you should have know used multithreading,
But if we don't on any operating system, interrupt and the interrupt, interrupt and the main can understand into the nature of the "multi-threaded",

Why do you want to add voaltile, this is a microcontroller embedded engineer must be clear, otherwise often planted more head also don't know is what reason,

Without volatile, the compiler will use global variables optimization to register, and sometimes the optimization to the cache, different threads on a visit to this global variable, or thread reads is the original address of the global variables, some threads access is the thread on the optimized register or cache, if thread staggered access, can appear the phenomenon of reading dirty data, causing the program to process gradually into the error,

CodePudding user response:

refer to 7th floor lr2131 response:
Quote: refer to the sixth floor qq_31195831 response:

Quote: refer to the fifth floor lr2131 reply:

Do you want to do PWM inverter, B timers do frequency conversion, A PWM?

Global variables, pay attention to take the keyword volatile, and then, if reading and writing, be don't add critical OuDeJia unlock, if you can, try not to use,

Why want to add a volatile keyword, and need not have what distinction, could you explain it


Give you a summary, a global variable, in a multi-threaded or similar to the "multi-threaded" read and write access, should add the key word. No, read "dirty data" phenomenon,
Multi-threaded since don't have to say more, on the single chip microcomputer operating system, you should have know used multithreading,
But if we don't on any operating system, interrupt and the interrupt, interrupt and the main can understand into the nature of the "multi-threaded",

Why do you want to add voaltile, this is a microcontroller embedded engineer must be clear, otherwise often planted more head also don't know is what reason,

Without volatile, the compiler will use global variables optimization to register, and sometimes the optimization to the cache, different threads on a visit to this global variable, or thread reads is the original address of the global variables, some threads access is the thread on the optimized register or cache, if thread staggered access, can appear the phenomenon of reading dirty data, causing the program to process gradually into the error,


Thank you very much, I see the

CodePudding user response:

refer to 7th floor lr2131 response:
Quote: refer to the sixth floor qq_31195831 response:

Quote: refer to the fifth floor lr2131 reply:

Do you want to do PWM inverter, B timers do frequency conversion, A PWM?

Global variables, pay attention to take the keyword volatile, and then, if reading and writing, be don't add critical OuDeJia unlock, if you can, try not to use,

Why want to add a volatile keyword, and need not have what distinction, could you explain it


Give you a summary, a global variable, in a multi-threaded or similar to the "multi-threaded" read and write access, should add the key word. No, read "dirty data" phenomenon,
Multi-threaded since don't have to say more, on the single chip microcomputer operating system, you should have know used multithreading,
But if we don't on any operating system, interrupt and the interrupt, interrupt and the main can understand into the nature of the "multi-threaded",

Why do you want to add voaltile, this is a microcontroller embedded engineer must be clear, otherwise often planted more head also don't know is what reason,

Without volatile, the compiler will use global variables optimization to register, and sometimes the optimization to the cache, different threads on a visit to this global variable, or thread reads is the original address of the global variables, some threads access is the thread on the optimized register or cache, if thread staggered access, can appear the phenomenon of reading dirty data, causing the program to process gradually into the error,


The summary is very good, I want to say I tend to use the register keyword,

CodePudding user response:

references 9 f pcalling response:
Quote: refer to 7th floor lr2131 response:

Quote: refer to the sixth floor qq_31195831 response:

Quote: refer to the fifth floor lr2131 reply:

Do you want to do PWM inverter, B timers do frequency conversion, A PWM?

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related