Page 1 of 1
Idea on how to sync and then follow a frequency.
Posted: Tue Sep 16, 2025 11:15 pm
by hippalator
Any ideas on how to sync up a 16f18877 with a particular frequency and maintaining the sync?
Re: Idea on how to sync and then follow a frequency.
Posted: Tue Sep 16, 2025 11:57 pm
by chipfryer27
Hi
You have asked a question that is a bit vague. What do you mean exactly for it to do?
You could mean take an incoming frequency and use that as the clock in, then the microcontroller will be syn'd to that, or something else entirely.
A bit more info would allow us to help better.
Regards
Re: Idea on how to sync and then follow a frequency.
Posted: Wed Sep 17, 2025 2:11 am
by hippalator
chipfryer27 wrote: ↑Tue Sep 16, 2025 11:57 pm
Hi
You have asked a question that is a bit vague. What do you mean exactly for it to do?
You could mean take an incoming frequency and use that as the clock in, then the microcontroller will be syn'd to that, or something else entirely.
A bit more info would allow us to help better.
Regards
I was wondering if I was detailed enough to get a proper answer.
I would like to monitor an input sinewave and the micro to reproduce the same sinewave and keep it in sync with the input sinewave.
Re: Idea on how to sync and then follow a frequency.
Posted: Wed Sep 17, 2025 3:39 am
by chipfryer27
Hi
With an 8-bit PIC running at 32MHZ you may struggle depending on the frequency you are sampling, plus I think the DAC is only 5-bit (I would need to check) so you may not be able to get a good reconstruction. Really depends on the frequency you wish to sample and reconstruct.
dsPIC devices are probably more suited, and if you want to be able to dive deep into the analogue world you could consider SysBlock by Matrix. Very powerful 32-bit processor that handles such things with ease. Highly recommended if you are serious about ADC.
Do note that irrespective of what you end up using, you will always have a slight phase difference between incoming wave and reconstructed. Faster the processing the lesser the difference.
Regards
Re: Idea on how to sync and then follow a frequency.
Posted: Wed Sep 17, 2025 5:00 am
by hippalator
100hz signal
Re: Idea on how to sync and then follow a frequency.
Posted: Wed Sep 17, 2025 5:36 am
by chipfryer27
Hi
Not such a problem if the "step" voltages of the DAC meet your needs.
You could use external ADC / DAC to give better resolution if required. How close to the original is required? Rhetorical question for you to think on.
Generally speaking you would need to sample at 200Hz to get a reasonable conversion for that frequency and depending on resolution that should be within the 18877 capabilities.
External conversion especially if SPI, would certainly improve results, but doable without.
Regards
Re: Idea on how to sync and then follow a frequency.
Posted: Wed Sep 17, 2025 10:27 am
by hippalator
I was thinking of using either an AD9833 or AD9851 DDS chip conected through SPI to adjust the phase to stay in sync.
I have ordered and received both the Matrix BL0011 and the BL0114 boards.
I'm a newby when it comes to programming PICs.
Went through the Matrix curriculum looking for more on programming DACs but there just isn't any.
Re: Idea on how to sync and then follow a frequency.
Posted: Wed Sep 17, 2025 2:27 pm
by chipfryer27
Hi
Those two boards will be very helpful indeed in learning to use Flowcode. I'd also recommend the BL0173 Terminal Boards which will allow you to connect "stuff" to the other unused ports (C/D/E). The BL0162 is another concideration. Although stated as a Servo board I have never used it for such but have found it to be incredibly useful in that it allows me to connect via jumpers to any pin on the port, whilst giving me VCC/Gnd connections per pin too.
The buttons / LEDs on the combo board can represent any input / output such as relay closing etc. I have similar combo boards going way back that I still use.
The Ghost is another good feature to see what's happening in real time.
Whilst FC doesn't support the DDS chips directly, there are other DAC components and the DSP sections may be helpful once you have obtained your signal via ADC. You may want to look at the SPI Master and SPI in general if you plan to control those chips serially. The 18877 should have no problem at all communicating / controlling them.
Regards
Re: Idea on how to sync and then follow a frequency.
Posted: Wed Sep 17, 2025 8:30 pm
by mnfisher
As a thought experiment..
Could you use an op-amp / differential amplifier - then adjust the output sine wave (using something like the AD9833 (see
viewtopic.php?p=11838#p11838) - and then adjust the frequency and start phase until the difference between input and output is a minimum.
This would almost be like auto-focus on some cameras - and might lead to some 'hunting' for the correct frequency? However it would require relatively little processing power to handle,
Alternatively - how often should you measure input / alter output (ie is it a constant wave or a varying signal?)
Martin
Re: Idea on how to sync and then follow a frequency.
Posted: Wed Sep 17, 2025 9:17 pm
by chipfryer27
Hi Martin
Assuming DAC is able to generate a signal that resembles the "input" sinewave, then a differential opamp may give a voltage proportional to the phase difference between the two signals. This voltage could then be used to adjust the phase of the DAC. I think the 9851 can adjust in about 11 degree steps so it might not be perfect, but could in practise be perfectly acceptable.
I don't foresee that PIC having much trouble at all.
Regards