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

Adjustable Frequency

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



Joined: 08 Sep 2020
Posts: 82

View user's profile Send private message

Adjustable Frequency
PostPosted: Mon Jan 10, 2022 4:32 am     Reply with quote

Hello Everbody

I want to produce PWM with which I can adjust the frequency with the potentiometer read from the ADC in the range of 160 hertz to 2 kHz with the PIC. How can I do this. Which processor and crystal should I use?
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 18006

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 8:27 am     Reply with quote

Depends massively on the resolution you actually want.
Chips like the 18F46J50, have a 16bit ECCP PWM, and with this at say
40MHz, you could use /62500 to give 160Hz, and /5000 to give 2KHz.
You'd probably need to use a look up table for the divisors, if you want a
linear response.
Remember there are PIC's with explicit frequency generator modules
rather than the PWM. Might be better.
temtronic



Joined: 01 Jul 2010
Posts: 8525
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 12:28 pm     Reply with quote

There's two main parts to this project, and Mr. T has replied about the 'generator' part.

The 'front end' part...
Using the ADC can be tricky !
With a 10 bit ADC, it's about 180 Hz per bit (2KHz-160 Hz) but we all KNOW that 'pots' are usually 270* rotation and very, very 'noisy' ( carbon track dust) so setting a precise frequency will be, well, impossible. And that's if you use a very stable, highly accurate Vref AND use some form of SW to reduce reading errors, in addition to very well designed PCB layout. 8-bit ADC is easy, 10 bits will challenge most designers.

Break up the project into those 2 parts. First, get the 'frequency generator' section running, say with 5-10 preset frequencies, over the entire range (160-2000). Once that is running properly, THEN tackle the pot and ADC section.
MCUprogrammer



Joined: 08 Sep 2020
Posts: 82

View user's profile Send private message

PostPosted: Wed Jan 12, 2022 2:01 am     Reply with quote

The PIC you are typing Mr T does not have 16 bit ECCP. I didn't see it on the datasheet.
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 18006

View user's profile Send private message

PostPosted: Wed Jan 12, 2022 3:44 am     Reply with quote

I think only the Q products actually allow you to use the 16bit register
for the PWM. Key is that though it supports 16bit for a lot of it's stuff
for 'reverse compatibility' the ECCP behaves like the CCP when used as
a PWM. I think it is only the chips with the separate PWM module that
allow the 16bit register to be used.
Look in the devices directory for chips that have the setup_pwm function
as opposed to the ccp functions.
However I have to repeat my comment that you'd honestly be
much better off using one of the chips with the programmable frequency
generator. Problem is that with PWM, you have to change both the period and
the duty registers, which will result in glitches when one is changed before
the other. Resolution is also not that good, and you will need a lookup table
to get a linear output change...
Look at the Q43, which is one I know does support 16bit PWM.
However this also has the NCO, which is the better solution.
MCUprogrammer



Joined: 08 Sep 2020
Posts: 82

View user's profile Send private message

PostPosted: Wed Jan 12, 2022 5:09 am     Reply with quote

Yes yes it works for me on PIC16F1779 :D Thanks.
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
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