Board STM32F407 BLACK.
Did so, but at least 1 microsecond. It should be faster !
void setup()
{
timer.pause();
timer.setPeriod(1);
timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);
timer.setCompare(TIMER_CH1, 1);
timer.attachCompare1Interrupt(timer_interrrupts);
timer.refresh();
timer.resume();
}
void timer_interrrupts()
{
if (digitalRead(PA2) == true)
digitalWrite (PA2, LOW);
else
digitalWrite (PA2, HIGH);
}
Add this line to setup() to generate PWM signal on a timer channel pin:
pinMode(OUTPUT_TIMER_CHANNEL_PIN, PWM);You would probably need to set the clock PLL so the board ran at 160MHz so the timer can have a divider of 4.
I included the line pinMode(PA1, PWM) in setup().
What code is necessary to enter into
void timer_interrrupts()
{
???
}
for this to work ?
Whether correctly I understood You that it is necessary to do so ?
timer.setPrescaleFactor(4);
If not, tell me how to do it. I really need the PWM frequency is much faster than 1 MHz!
E.g. on the F103, with 8 bit resolution, max PWM rate will be 72/256 = approx 280 Khz is max PWM rate
On the F4 with 160 Mhz clock rate and 8 bit resolution PWM that only gives you a PWM freq 625 kHz
None of these boards will give you a PWM of period of 1Mhz. Except perhaps if you extremely overclock the processor to 256Mhz, and I’m not sure if anyone has successfully done that.
I think you’ll need to use something like a FPGA to achieve the sort of performance you are looking for
I need a simple generator of rectangular pulses
And without the use of PWM it is possible to obtain a high speed of generation ?
I am investigating the issue, but it seems that major rework is necessary.
You have written conflicting requirements.
You said 25nS interval. Which is possible using he F4 processor.
You also said 1MHz PWM, which is not possible ( assuming 8 bit PWM resolution)
I think you need to explain what you are trying to do, and why….
I need to generate a square signal of 1 bit (output either 0 or 1 ) with high frequency using a timer.
The frequency of generation needs the most high , more than 1 MHz
Image https://yadi.sk/i/O_BCSslH3Qheba
( Tell me on what site to upload images so that they appear on the forum in the topic)
#define timer Timer5
#define TIMER5_CH1_PIN PA0
void setup()
{
pinMode(TIMER5_CH1_PIN, PWM);
gpio_set_af_mode(TIMER5_CH1_PIN, 2);
timer.pause();
timer.setPrescaleFactor(1); // use 42MHz internal clock
timer.setOverflow(2); // output ~21MHz signal (48ns period)
timer.setCompare(TIMER_CH1, 1); // 50% duty cycle: 24ns low + 24ns high
timer.refresh();
timer.resume();
}
So what is needed is a 20Mhz square wave.
I am very grateful for Your invaluable help in the study of this beautiful microcontroller STM32F407 !
It is not a rectangular generator, but I think this is what I need and will work fine from me !
Code I liked it, but I have a few questions for You:
1. I have not found information on the forum about the line gpio_set_af_mode(TIMER5_CH1_PIN, 2);
What does it do and what does the digit 2 ?
2. Is it possible to assign a different pin out ? For example PA2 ? I tried but I not working. How can I change ?
3. Is it possible to obtain even greater frequency generator, for example 84 or 100 or 168 MHz ?
I would be very grateful if You could help me with these newbie .
[acronis – Mon Dec 18, 2017 1:02 pm] –
…
3. Is it possible to obtain even greater frequency generator, for example 84 or 100 or 168 MHz ?
…
Probably not directly, but there are several ways you can double the frequencies you *can* generate, so long as you don’t mind adding a bit of extra hardware, for example with a couple of flip flops.
.. although I’m not sure if the humble CD4528 would be fast enough for your application, so you may have to do a bit of googling to find something suitable.
You could also look at the ad9851 dds signal generator, controlled by the STM32F103 of course
https://www.ebay.com/sch/i.html?_sacat= … dds&_frs=1
What is the purpose of this square wave?
Thanks for Your hint, but I’m not good friends with the construction of schemes and I don’t want to use any external components , and I want to only microcontroller .
The more code that has prompted dear sevestrong works fine.
Just want to deal with those questions that I wrote that I understood as with it to work correctly.
We are developing an interesting project to measure the percent alcohol.
To modify the desired generation.
First generated signal , and then analyze the response by the ADC of the microcontroller.
By the way ADC has me very helped sevestrong
[acronis – Mon Dec 18, 2017 1:02 pm] –
3. Is it possible to obtain even greater frequency generator, for example 84 or 100 or 168 MHz ?
If you just need a square wave, it should be possible to to output the system clock (up to 168MHz) via the MCO pins but I can’t provide you the technical details..
Cheers, E.
And where can I see information ?
https://yadi.sk/i/C05IOvNy3Qijun
[acronis – Mon Dec 18, 2017 1:02 pm] –
It is not a rectangular generator, but I think this is what I need and will work fine from me !
Well, it must be a square-wave signal, because it is a digital output PWM signal from timer 5 compare channel 1.
[acronis – Mon Dec 18, 2017 1:02 pm] –
gpio_set_af_mode(TIMER5_CH1_PIN, 2);
hmmm . But it’s not .Why …
With the oscilloscope
InitMCO1();I updated the library today to your last on F4.
on the previous version, this code worked fine – but now gives an error
invalid conversion from 'int' to 'gpio_af_mode' [-fpermissive]
gpio_set_af_mode(TIMER5_CH1_PIN, GPIO_AFMODE_TIM3_5);#include <Adafruit_TFTLCD_16bit_STM32.h>
Adafruit_TFTLCD_16bit_STM32 tft;
#define timer Timer5
#define TIMER5_CH1_PIN PA0
void setup()
{
tft.reset();
tft.begin(0x9341);
tft.setTextSize(1);
tft.setRotation(1);
tft.setTextColor(BLUE);
tft.fillScreen(BLACK);
pinMode(TIMER5_CH1_PIN, PWM);
// gpio_set_af_mode(TIMER5_CH1_PIN,GPIO_AFMODE_TIM3_5);
gpio_set_af_mode(TIMER5_CH1_PIN, (gpio_af_mode)2);
timer.pause();
timer.setPrescaleFactor(1); // use 42MHz internal clock
timer.setOverflow(2); // output ~21MHz signal (48ns period)
timer.setCompare(TIMER_CH1, 1); // 50% duty cycle: 24ns low + 24ns high
timer.refresh();
timer.resume();
}
void loop() {
tft.println("Test");
}
My previous commit erroneously removed the predefined Timer instances.
I re-added them now.
Please check out my repo again.
(In the future please pay attention to the warnings printed by the Arduino IDE in the message window!)
Everything works as before !
Thank You!
