Hi Guys,
Anyone got any good tricks for creating a variable frequency output from a 18F Pic.
I would like to have a range of frequencies between 500Hz to 3kHz, I dont need any specific values, just a range of steps.
I also after about 50% duty but anything close will do.
The PWM module only allow you to change Prescaler to three settings.
Is there a known method of changing the Period overflow and Duty values, to vary the overall freq and keep a rough 50% pwm?
I would like to do it via the PWM component, rather than discreate lines of FC creating an oscillating output pin, since there are lot of other process going on and keeping the the timing tight for a software PWM could be tricky.
Thanks, J.
How to Create a variable frequency output
Moderator: Benj
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: How to Create a variable frequency output
You can use a timer interrupt to keep timing correct.Jay Dee wrote:I would like to do it via the PWM component, rather than discreate lines of FC creating an oscillating output pin, since there are lot of other process going on and keeping the the timing tight for a software PWM could be tricky.
For example I created a Variable Frequency Generator 500Hz to 5KHz (100 Hz Steps)
If you are interested in it then if you post a flowchart with your target and clock settings, I can then convert it to FC7.
I could even give PWM component a bash?
Martin
Re: How to Create a variable frequency output
Hi Martin,
Thanks for that, I did not follow all of it ! but it certainly triggered an idea for the use of interrupts, which was a great shout.
For anyone else playing along, attached is a very simple Interrupt based fixed-frequency output signal.
An interrupt macro counts up to a rollover value, on rollover, an output pin has its state flipped.... this repeats creating a 50% frequency output signal.
Change the value of TmrRollOver and you can change the Frequency. //EDIT// This is correct file now, with a tweak to increase stability!
Thanks, it was just the nudge I needed to find a solution.
J.
Thanks for that, I did not follow all of it ! but it certainly triggered an idea for the use of interrupts, which was a great shout.
For anyone else playing along, attached is a very simple Interrupt based fixed-frequency output signal.
An interrupt macro counts up to a rollover value, on rollover, an output pin has its state flipped.... this repeats creating a 50% frequency output signal.
Change the value of TmrRollOver and you can change the Frequency. //EDIT// This is correct file now, with a tweak to increase stability!
Thanks, it was just the nudge I needed to find a solution.
J.
Last edited by Jay Dee on Tue Aug 14, 2018 7:38 pm, edited 1 time in total.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: How to Create a variable frequency output
Thanks for the alternate PWM method Martin,
FYI, I previously posted the wrong file, swapped for correct one, which has also been tweaked to improve stability.
Its based on a PIC 18F2580 with 20Mhz Crystall so would need relevant tweaks if anyone wanted to use it on a alternate chip or clock freq. J.
FYI, I previously posted the wrong file, swapped for correct one, which has also been tweaked to improve stability.
Its based on a PIC 18F2580 with 20Mhz Crystall so would need relevant tweaks if anyone wanted to use it on a alternate chip or clock freq. J.