Hi expert,
Wants understand how to generate a signal of 7000hz by the pwmout mbed's library,
I read a lot of explainations but i can't find a simple sample code with a good explaination.
Thanks
Hello!
PwmOut - Handbook | mbed should give you a few pointers:
#include "mbed.h" PwmOut led(LED2); int main() { // specify period first, then everything else led.period(0.00014285f); // 1.4285e-4 second period is 7kHz led.write(0.50f); // 50% duty cycle while(1); // led flashing }
Thanks for the code albanrampon but how did the fraction of second could be calculate ? i have some difficulty to understand this point
This function wants the period:
After all it isnt a big probleme to know
it, have the right tools to do it, is enough !
https://www.unitjuggler.com/convertir-frequency-de-Hz-en-s%28p%29.html?val=7000
Explained like this is very easy ! thank you
Is that solution could be apply to a LPC810 serie ?
I have seen that i must use the timer to produce the same effect on my chip.
If this is not possible , I will use it a 555 to produce the desired signal . But I wish have an answer to this question. thank you
I know this is absolutely overkill. You could use the SCT - it's overqualified for this task.
The SCT has a built-in state-machine, which you can use for changing the state from 1 to 0 and from 0 to 1.
You can then make an event, that happens when the state changes to 0, and another event when the state changes to 1.
Each event can for instance change the state of a pin.
I do not know how mbed code for this would look, though.
The function I gave is using the mbed libraries.
You could look at the mbed library and extract the code used from them to make it work on your MCU.
Otherwise, if you ask on NXP forums or look in the examples, you can probably get code you can customize to run on one of the timers, whether the SCT module or the multi-rate timer.