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

comparator wave
Goto page Previous  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: 37

View user's profile Send private message

PostPosted: Mon Jan 16, 2023 12:57 am     Reply with quote

temtronic wrote:
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 ?



18khz and 20khz
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jan 16, 2023 3:18 am     Reply with quote

It is sometimes quite depressing seeing people wasting so much effort
trying to pack something into a chip, when the functions can be done
much easier in a later chip. The 629 & 675, are quite old chips. They
were replaced by chips like the 12F1840. Now in the UK, the 1840,
costs £1.34, while the 675 is 1.79. The 1840 also has better availability
(currently in stock at all the main wholesalers, while the 675 has a few
weeks back-order).
Now the 1840, has 3* the ROM, 4* the RAM, includes a PWM (which
makes generating a tone totally simple), and includes three timers,
making measuring a frequency much easier. It has several extra
peripherals as well. The capacitor sensing module, the signal modulator,
hardware UART, DAC & MSSP. Also has up to 32MHz operation on the
internal oscillator, and draws less power.
Difference between a 2002 chip and one from ten years later.
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Mon Jan 16, 2023 3:25 am     Reply with quote

Current chip is 12f629 or 12f675. I would appreciate if you share more realistic results for the solution. If you have sample frequency measurement codes, can you share them?
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jan 16, 2023 3:52 am     Reply with quote

At the moment, you keep asking for things without enough data as to
what you are already doing. You say you have the chip generating a tone,
but without details of how this is generated?. If you are using a timer
to do this (the easiest way), then which timer?. This affects what
resources are available to measure a tone. If it is a timer then the
frequency will be what you are programming on the timer. Pointless
to measure this.
temtronic



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

View user's profile Send private message

PostPosted: Mon Jan 16, 2023 8:36 am     Reply with quote

it's cold, overcast day, so I decided to 'google'...
found these..




http://www.ccsinfo.com/forum/viewtopic.php?t=21390

Both send the result via RS232 to a PC for display. You'll have to have some kind of 'serial input' to your PC.....



2nd is in CCS C, from 2004 !! He says it 'works' but has 'problems'. I suspect due to inaccurate timing, though I can't breadboard to test.

So, yes it IS possible to build a frequency counter using that PIC but as Mr. T points out, using a newer PIC is a better choice ! I understand that getting parts may be a challenge, depending on the country and location and English is not everyone's 1st language. heck at 70 I'm still trying to understand it !


Last edited by temtronic on Mon Jan 16, 2023 1:23 pm; edited 2 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jan 16, 2023 10:39 am     Reply with quote

Thing is that most methods need two timers. Now it therefore depends
on how he is doing the frequency generation he spoke about.
The chip is perfectly capable of doing one job, but putting together
multiple things runs the risk of running out of resources.... Sad
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Tue Jan 17, 2023 2:15 pm     Reply with quote

Code:

#include <12F683.h>
#fuses hs,mclr,nowdt
#use delay(clock=20m)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,bits=8,stream=PORT1)
int16 zaman=0,say=0,sayi=0;

#int_timer0
void kes()
{
set_timer0(255);
zaman++;

}

#int_timer1
void zam()
{
set_timer1(34290);
say++;

if(say == 20 )
{
say=0;
DISABLE_INTERRUPTS(int_timer0);

}
}


void main()
{

SETUP_TIMER_0(T0_EXT_H_TO_L | T0_DIV_1);
set_timer0(255);

SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(34290);

enable_interrupts(int_timer0);
enable_interrupts(int_timer1);
enable_interrupts (global);


while(true)
{


delay_ms(100);
printf("\rFrekans : %lu \n",zaman);
}
}


It measures the frequency once. It may not cause frequency change. can you help me
temtronic



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

View user's profile Send private message

PostPosted: Tue Jan 17, 2023 7:54 pm     Reply with quote

a few comments...

You really need to add comments to the ends of your lines of code.
we don't know WHY you're setting 'timer0 to 255', what '34290' is supposed to mean? How '20' for the variable 'say' was chosen ?
you also should have a 'title comment section', with a brief explanation of what the program is supposed to do, as well as what the 6 I/O pins of the PIC are being used for.
comments don't cost you code space and they'll help others help you !

Yes, we can see both timers are set to interrupt, but we don't know at what rate, could be 22us, 165 ms, 1 hr ?? There are online apps that we can access to quickly confirm/deny that the numbers you've chosen are correct, if we're told the interrupt rate, timer options and clock speed.

I will assume the PIC is operating at the correct speed , as you've got serial data going to a PC.

The one problem I do see is that when Timer1 ISR is 1st executed, it disabled Timer0 interrupt, so from then on Timer0 ISR is never run again.
I'm fairly sure that is NOT what you want to happen.
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Tue Jan 17, 2023 9:22 pm     Reply with quote

sifirzero1 wrote:
Code:

#include <12F683.h>
#fuses hs,mclr,nowdt
#use delay(clock=20m)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,bits=8,stream=PORT1)
int16 zaman=0,say=0,sayi=0;

#int_timer0
void kes()  //  pulsde kesme yapilacak.
{
set_timer0(255);
zaman++;

}

#int_timer1
void zam()
{
set_timer1(34290);
say++; 

if(say == 20 ) // 1saniye kesme suresi
{
say=0;
DISABLE_INTERRUPTS(int_timer0);

}
}


void main()
{

SETUP_TIMER_0(T0_EXT_H_TO_L | T0_DIV_1);
set_timer0(255);

SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(34290);

enable_interrupts(int_timer0);
enable_interrupts(int_timer1);
enable_interrupts (global);


while(true)
{


delay_ms(100);
printf("\rFrekans : %lu \n",zaman);
}
}


It measures the frequency once. It may not cause frequency change. can you help me
temtronic



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

View user's profile Send private message

PostPosted: Wed Jan 18, 2023 9:21 am     Reply with quote

OK, I see a couple comments, but not in English.

I understand English as a 2nd language is hard, but since the compiler is in English, it'd be nice if everything was in English as it makes understanding the program a lot easier.

this..

set_timer1(34290);

would be better as

set_timer1(34290); // value to create xxx us ISR

or whatever it's for.....

maybe others can help with better descriptions (comments)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 18, 2023 9:51 am     Reply with quote

temtronic,
He wants us to write code for him, to generate a 19 KHz frequency.
His current program doesn't do that. So he wants us to do it for him.
That's his whole problem, not the comments.

He writes what he wants in an obscure way:
Quote:
It measures the frequency once. It may not cause frequency
change
. can you help me

This means he wants a frequency generator. He then says:
Quote:
can you help me

So forget the comments. If you want to write the frequency generator
code for him, go ahead.
PrinceNai



Joined: 31 Oct 2016
Posts: 452
Location: Montenegro

View user's profile Send private message

PostPosted: Wed Jan 18, 2023 1:15 pm     Reply with quote

PCM programmer, where can I send my offerings? You are a god.
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 20, 2023 7:34 am     Reply with quote

Hmm.. after finding some 12f683s, I pretty sure those are 'special' and can't be programmed with a PICkit3 if using the internal oscillator...
for some reason the writing on those PICs is a lot smaller than I remember too.
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Fri Jan 20, 2023 7:38 am     Reply with quote

What I wanted was to measure the frequency meter using the timer0 input, but no one helped. Doesn't anyone know?
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 20, 2023 10:04 am     Reply with quote

hmm.. I was under the impression you need a frequency GENERATOR of 19KHz.
So I've spent a lot of time actually getting my PICkit3-R1 to identify and finally program the 12F683 as a 19KHz generator......

What is the maximum frequency you need to measure ?
There are several programs for this, they will use Timer0 and timer1 of course
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 Previous  1, 2, 3  Next
Page 2 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