Electronics > Projects, Designs, and Technical Stuff

variable frequency square wave

<< < (3/7) > >>

dpenev:
Hi Kleinstein,

Sorry for the late response. I have rushed for the SI5351 testing.
I have connected Adafrut Si5351 board to my CPU and I am able to talk to the Si5351 already.


--- Quote from: Kleinstein on May 20, 2019, 03:55:03 pm ---I don't think using an external clock to the µC timer will help. The timer output will very likely be synchronized to the µC system clock. So if it works at all the output would be with high jitter, just like a fractional divider on the µC.

--- End quote ---

I am afraid this can be the case. However I was not 100% and I have this in my todo.
Anyone having direct experience with synchronizing any of the  TMS32L4 peripheral from the external clock?


--- Quote from: Kleinstein on May 20, 2019, 03:55:03 pm ---For the combination with the Si5351, I see 3 options:
1) Use the Si5351 to provide the system clock to the µC and than use the µC timer for coarse adjust and the PLL for fine adjust.

--- End quote ---
I am trying to avoid adjusting the MCU system clock on the fly.


--- Quote from: Kleinstein on May 20, 2019, 03:55:03 pm ---2) Use the Si5351 output with an extra divider (e.g. 74HCT74 or similar). AFAIK the Si5351 only goes down to some 3 kHz.

--- End quote ---
I may actually require frequencies lower than I have initial requested in my first message. So external divider may require to be big.   


--- Quote from: Kleinstein on May 20, 2019, 03:55:03 pm ---3) Use the Si5351 for the higher frequencies and the µC internal timer for the lower ones (use different outputs or a switch/mux to choose)

--- End quote ---
This was my initial intention but I drifted in favor of having MCU post divider with the MCU timer.
Now after your message I may reconsider.
Having big flexible post counter is a benefit but if it introduce a jitter is not a solution for me.

Thank you Kleinstein once again.
Dimitar   

ogden:

--- Quote from: dpenev on May 23, 2019, 03:07:18 pm ---Anyone having direct experience with synchronizing any of the  TMS32L4 peripheral from the external clock?

--- End quote ---

External clock of stm32 timers are resynchronized to timer bus clock. It means that external clock is useless in frequency generation application. Attach: figure from ST appnote AN4776

IDEngineer:

--- Quote from: OM222O on May 20, 2019, 07:50:26 am ---why are you trying to reinvent the wheel? I haven't used the STM chips but the solution is pretty much standard. No need to use PLLs / change clock frequency, etc. Just use the built in timers. There also usually exists a compare register (I will be extremely surprised if the STM MCUs don't have this, as even the cheapest MCUs have timer compare registers! arduino as an example and their lowest end micros: ATTINY10 have this!). Knowing the clock frequency of the timer register, you set the value at the comparator register, which then causes an interrupt at that set value.
--- End quote ---
Exactly this! In fact, better than this. I too haven't worked with the STM's but in Microchip PIC's this takes about half a dozen instructions and then it's all done in HARDWARE. It uses a single timer and two CCP modules. No interrupt service routine at all. The first CCP module acts as the preloader for the timer, and the second uses one of its many Compare modes - in this case the "toggle" mode, which toggles its output pin on every match - to generate your output signal. The resulting output frequency is controlled by your selection of prescaler and comparison values. Effectively zero jitter since there's no software in the loop. Frequency accuracy, short and long term, is determined by the MCU's clock source (likely a crystal). 1MHz and down is easily achievable, and in fact you can go above 1MHz easily too.

Seriously, this could hardly be any simpler. No need for external components at all. Half a dozen lines of setup code and this would be off and running, with the MCU idling with zero workload since the hardware would be handling everything.

I share OM222O's astonishment that the STM's would not already have this capability. It's been a fundamental baseline feature of MCU's for years and years. I'm going to download an STM32 spec sheet right now and take a look, just to satisfy my curiosity. Hopefully others who are already familiar with the STM32's can chime in and resolve the question.

EDIT: I grabbed an STM32 spec sheet from https://www.st.com/resource/en/datasheet/stm32l471re.pdf. There are many devices, this appeared to be a "lesser" one. Generally the peripherals are common across a given family, differing primarily in how many of each type are on the chip, so the specs for a given peripheral in this spec sheet are likely to be common to the same peripheral in other STM32's.

Turning in our hymnals to section 3.32.2 (page 47), it describes "General-purpose timers (TIM2, TIM3, TIM4, TIM5, TIM15, TIM16, TIM17)". I skipped ahead to the description of TIM15, 16, and 17 which reads:


--- Quote ---They are general-purpose timers with mid-range features:
They have 16-bit auto-reload upcounters and 16-bit prescalers.
– TIM15 has 2 channels and 1 complementary channel
– TIM16 and TIM17 have 1 channel and 1 complementary channel
All channels can be used for input capture/output compare, PWM or one-pulse mode output.
The timers can work together via the Timer Link feature for synchronization or event chaining.

--- End quote ---

I've bolded those features that may bear directly on the question at hand. Auto-reload suggests the timers can be configured to repeat at a given, selectable frequency (e.g. they have an internal comparator register). Prescaler suggests a very wide range of frequencies can be derived from the system oscillator. Output compare suggests they can emit a signal when compare occurs. If that can't repeat on every cycle, there's also the one-pulse mode output which suggests it will pulse when compare occurs. That "one-shot" like behavior may then be driven by a second timer, via the Timer Link feature and its suggestively-named event chaining, to repeatedly generate the pulse (and in this mode, you'd be able to use the first timer to set the pulse width while the second controls the frequency, giving you an additional degree of control over the resulting output).

Sounds to me like a solution is waiting in the STM32 hardware, all that's required is some quality time with the spec sheet. Please report back!

ogden:

--- Quote from: IDEngineer on May 24, 2019, 03:50:38 pm ---I too haven't worked with the STM's but in Microchip PIC's this takes about half a dozen instructions and then it's all done in HARDWARE. It uses a single timer and two CCP modules. No interrupt service routine at all. The first CCP module acts as the preloader for the timer, and the second uses one of its many Compare modes - in this case the "toggle" mode, which toggles its output pin on every match - to generate your output signal. The resulting output frequency is controlled by your selection of prescaler and comparison values. Effectively zero jitter since there's no software in the loop. Frequency accuracy, short and long term, is determined by the MCU's clock source (likely a crystal). 1MHz and down is easily achievable, and in fact you can go above 1MHz easily too.

--- End quote ---

Are you absolutely sure that PIC or STM32 can generate any arbitrary frequency up-to 1MHz with 0.1% accuracy? Before you answer - take some time and do some math

IDEngineer:

--- Quote from: ogden on May 24, 2019, 04:10:34 pm ---Are you absolutely sure that PIC or STM32 can generate any arbitrary frequency up-to 1MHz with 0.1% accuracy?
--- End quote ---
If by "accuracy" you mean "lack of jitter", yes - the PIC's will do it because it's all in hardware. I've seen it on the scope. This isn't rocket science... it's not difficult for digital logic to stay within 1KHz on a 1MHz fundamental (which is 0.1%).

If by "accuracy" you mean "absolute frequency", as noted that's dependent upon the oscillator source and is unrelated to the choice of MCU, hardware vs. software, etc.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod