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 CCS Technical Support

comparator wave
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sifirzero1



Joined: 14 Dec 2022
Posts: 43

View user's profile Send private message

comparator wave
PostPosted: Fri Jan 13, 2023 11:19 am     Reply with quote

Can we generate 19khz square wave with 12F629 comparator? I don't know how to write the codes. Can you help me?
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 13, 2023 12:36 pm     Reply with quote

No, the comparator is an INPUT peripheral not an OUTPUT peripheral.
You'll need to choose a PIC that has a 'CCP' peripheral
or
you 'might' be able to use TIMER1 to 'toggle' an I/O pin.
Much depends on what else the PIC has to do, as it has a very small amount of memory.
sifirzero1



Joined: 14 Dec 2022
Posts: 43

View user's profile Send private message

PostPosted: Fri Jan 13, 2023 12:37 pm     Reply with quote

They produce a square wave in the datasheet.
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 13, 2023 12:52 pm     Reply with quote

It's not a 'free running square wave', like an oscillator. The comparator set's or clears the output based upon the conditions of it's 2 inputs. (it's a 'special' form of opamp ).

You cannot configure it as an ' oscillator'.

You can however configure TIMER1 with a preload of 65483, if the clock is 4MHz and that would generate an interrupt at 19KHz. Inside the ISR, you 'toggle' an I/O pin and that will have the 19KHz square wave.
Pretty sure that's the correct 'preload' value. this is from my 70 year old memory. CCS supplies lots of examples in the 'examples' folder, has to be a one or two in there.....
sifirzero1



Joined: 14 Dec 2022
Posts: 43

View user's profile Send private message

PostPosted: Fri Jan 13, 2023 12:55 pm     Reply with quote

The 19khz square wave processor we produce will not break down when other operations are performed.
sifirzero1



Joined: 14 Dec 2022
Posts: 43

View user's profile Send private message

PostPosted: Fri Jan 13, 2023 2:26 pm     Reply with quote

Can we measure frequency with timer0? Is there sample code.
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 13, 2023 4:13 pm     Reply with quote

CCS supplies an example, using timer1 you might be able to modify for timer0, though it depends on which PIC you want to use.
You can also use Google to search.
sifirzero1



Joined: 14 Dec 2022
Posts: 43

View user's profile Send private message

PostPosted: Fri Jan 13, 2023 10:34 pm     Reply with quote

Can you make an example with 12f629? thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sat Jan 14, 2023 6:25 am     Reply with quote

Take a deep breath.

It is perfectly possible to use the internal comparator as the inverting
amplifier for a simple RC oscillator. However there is really no code
involved. The frequency and operation are completely dependant on the
external RC components added. The only programming is to setup the
comparator as a two input, single output unit.
To work reliably you need to use both inputs, so you can add hysteresis.
So Cout is fed to a resistive divider feeding part of the signal back into
the C+ input. The output is then fed back via another resistor to the C-
input, with a capacitor to ground.
The only code is the single line:

setup_comparator(A0_A1_OUT_ON_A2);

It is the top circuit here:

[url]
http://hyperphysics.phy-astr.gsu.edu/hbase/Electronic/square.html
[/url]

Using the PIC comparator.

The frequency is set by the feedback resistor and the capacitor, with
the voltage this has to charge/discharge over, set by the resistive
divider. So the values of all four components tweak the value.

You can use this without the C+ input, but the frequency then depends
on the hysteresis of the PIC itself, and this varies massively from chip
to chip. So though it can work it is very unpredictable in the frequency
it gives.
sifirzero1



Joined: 14 Dec 2022
Posts: 43

View user's profile Send private message

PostPosted: Sat Jan 14, 2023 7:01 am     Reply with quote

I got the frequency. I have a little question. How can I control the frequency shift with timer0.
temtronic



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

View user's profile Send private message

PostPosted: Sat Jan 14, 2023 7:48 am     Reply with quote

hmm, never really thought about using the comparator by itself ! Sure seems like it is a waste of 1/2 the I/O pins of that PIC though.
And no 'computer control' of the frequency.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Jan 14, 2023 4:22 pm     Reply with quote

sifirzero1 wrote:
Can we measure frequency with timer0? Is there sample code.


CCS supplies code EX_FREQ.C which is not portable between PICs.
You may be able to modify it to suit your PIC.

This link may help you.

http://www.ccsinfo.com/forum/viewtopic.php?t=47375&start=0.

I don't have your PIC so I can't test it.
I have tried it on several different PICs and it works well up to MHz.

Mike
sifirzero1



Joined: 14 Dec 2022
Posts: 43

View user's profile Send private message

PostPosted: Sat Jan 14, 2023 4:32 pm     Reply with quote

Mike Walne wrote:
sifirzero1 wrote:
Can we measure frequency with timer0? Is there sample code.


CCS supplies code EX_FREQ.C which is not portable between PICs.
You may be able to modify it to suit your PIC.

This link may help you.

http://www.ccsinfo.com/forum/viewtopic.php?t=47375&start=0.

I don't have your PIC so I can't test it.
I have tried it on several different PICs and it works well up to MHz.

Mike



pic12f629 or pic12f675
sifirzero1



Joined: 14 Dec 2022
Posts: 43

View user's profile Send private message

PostPosted: Sun Jan 15, 2023 2:24 pm     Reply with quote

Mike Walne wrote:
sifirzero1 wrote:
Can we measure frequency with timer0? Is there sample code.


CCS supplies code EX_FREQ.C which is not portable between PICs.
You may be able to modify it to suit your PIC.

This link may help you.

http://www.ccsinfo.com/forum/viewtopic.php?t=47375&start=0.

I don't have your PIC so I can't test it.
I have tried it on several different PICs and it works well up to MHz.

Mike


EX_FREQ.C t0 not signal input,

I searched on the internet. correct logic makes sense. There is no frequency meter. The timer0 I need will have a clock signal input.
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 15, 2023 3:01 pm     Reply with quote

Most 'frequency counters' using PICs that I 'Googled' ,

like https://www.best-microcontroller-projects.com/pic-frequency-counter.html

use BOTH Timer0 AND Timer1.

Now if BOTH timers are available, you should be able to modify one of the dozens of frequency counters already on the Internet.

You'll have to edit the code for whatever clock speed you're running and send the result , via RS-232, to a PC terminal program. With an 8 pin PIC, -2 for power gives 6 I/O, -1 for the incoming signal, leaves 5 pins,which means you can't use an LCD module , as they need 6 or 7. You also have limited memory (code space), but it should be possible to run in that PIC.

What is the maximum frequency that you need to read ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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