View previous topic :: View next topic |
Author |
Message |
picj1984
Joined: 01 Mar 2010 Posts: 73
|
Generating 5kHz - 100kHz square wave |
Posted: Tue Oct 03, 2017 2:27 pm |
|
|
Hello,
I've found this forum incredibly useful in the past and I tried hard to find an answer to my design problem, but haven't come across anything.
I'm trying to generate a square wave from 5kHz to 100kHz (roughly) and have at least 1000 discrete steps between the two.
The processor I'm using is a PIC16F1825, but I'm happy to use anything. I'm running it at 32MHz.
I can almost get there using Timer1 but it's just not that useful above 40kHz or so because the steps between frequencies get so big. It pitters out at about 70kHz. It almost works for me.
I've also tried just using a PWM module, which would work beautifully, but since I'm forced (I think) to use timer2 for that, I only have an 8 bit timer there so there's not enough steps.
I can copy and paste code if necessary. The code I'm writing is working, it's just that I'm not how to approach this strategically. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Oct 03, 2017 2:36 pm |
|
|
What resolution do you want at 100kHz?
Can you get enough steps by using PWM and changing the pre-scaler?
Mike |
|
|
picj1984
Joined: 01 Mar 2010 Posts: 73
|
|
Posted: Tue Oct 03, 2017 2:39 pm |
|
|
Mike Walne wrote: | What resolution do you want at 100kHz?
Can you get enough steps by using PWM and changing the pre-scaler?
Mike |
I think I have something like 200 steps from 7.81kHz to 125kHz just changing the PRx value.
If the PRx value could be 16bits somehow instead of 8 bits it'd word perfectly for me (i.e. if I could use timer1 instead of timer2 for the PWM stuff). |
|
|
picj1984
Joined: 01 Mar 2010 Posts: 73
|
|
Posted: Tue Oct 03, 2017 3:42 pm |
|
|
I just discovered NCO (numerically controlled oscillator) I think that is what I'm looking for. I'll switch chips. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Tue Oct 03, 2017 5:29 pm |
|
|
These days there's a PIC with just the peripherals you need, at a price that is easy on the wallet , unlike 25 years ago.....
Some days I wonder WHO uses some of the 'obsucre' peripherals though.
Jay |
|
|
|