CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Generating 5kHz - 100kHz square wave

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
picj1984



Joined: 01 Mar 2010
Posts: 47

View user's profile Send private message

Generating 5kHz - 100kHz square wave
PostPosted: Tue Oct 03, 2017 2:27 pm     Reply with quote

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: 1719
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Oct 03, 2017 2:36 pm     Reply with quote

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: 47

View user's profile Send private message

PostPosted: Tue Oct 03, 2017 2:39 pm     Reply with quote

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: 47

View user's profile Send private message

PostPosted: Tue Oct 03, 2017 3:42 pm     Reply with quote

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: 5960
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Oct 03, 2017 5:29 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group