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
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Jan 20, 2023 11:37 am     Reply with quote

He started asking for a frequency generator, then switched to talking
about measuring frequencies, but when asked how he was generating
the frequency (which is vital, since if he is using a timer, this is not
available for measurement), did not answer. At this point I gave up.
He seems to want us to answer things telepathically, rather than giving
us real data.
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 20, 2023 12:57 pm     Reply with quote

Well his request did get me to dust off my PICkit3-r1, FIND some 683s,cut code and program a 19KHz signal !

I also found some NE544s and NE5044 while looking for the PICs....turned on the EICO 950B R-C-Comparator and the 'magic eye' still works !

One of these days I suppose I should clean up the 'lab'.
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Fri Jan 20, 2023 2:35 pm     Reply with quote

It is important to measure the 18khz and 25khz range and to have a timer0 input.
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Fri Jan 20, 2023 2:39 pm     Reply with quote

https://picdevreler.wordpress.com/2017/05/11/basit-bir-frekansmetre-devresi/

There is an example but it doesn't meet my needs. It measures hz and kilohz separately.
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 20, 2023 3:21 pm     Reply with quote

Well it is possible, but a LOT easier if Timer1 could be used.
You should google 'measuring pulse width' for more options on how to code.

BTW I don't know the language that posted link is, so I can't download whatever code there is. It'd be nice to see it in English.
temtronic



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

View user's profile Send private message

PostPosted: Sat Jan 21, 2023 6:08 pm     Reply with quote

Code:

//683FC1
//test code for 25KHz frequency counter
#include <12f683.h>
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,MCLR      //basic working fuses
#use delay(internal=4M)                         //4MHz internal
#use RS232(baud=9600,xmit=pin_a4)            //data via TTL<>USb module
int8 lc=0;                              //loop counter from Timer0 interrupt
int16 f=0;                              //frequency
int8 tc=0;                              //timer0 count
#int_timer0                              //timer0 ISR
void isr_timer0(void) {                     //number of loops of 256 counts
   lc=lc+1;                            //of input to Timer0 (1 count=1 Hz )
}
//================================
void main()
{
setup_comparator(NC_NC_NC_NC);               //disable comaparators
setup_adc_ports(NO_ANALOGS);               //disable ADC pins
setup_timer_0 (RTCC_DIV_1 | RTCC_EXT_L_TO_H);   //no prescaler, external source,rising edge
enable_interrupts(GLOBAL);                  //enable interrupts
delay_ms(1500);                           //premain loop delay
printf("\n\r Timer0 frequency program \n\r");   //sign on messgae
while(TRUE)                              //do forever
  {
      lc=0;                              //loop counter
   tc=0;                              //timer0 count
   f=0;                              //frequency
   set_timer0(0);                        //preset timer0
   enable_interrupts(int_timer0);            //software 'start' for timer0
   delay_ms(1000);                        //do nothing for 1 second
   disable_interrupts(Int_timer0);            //software 'stop' for timer0      
    tc=get_timer0();                     //get tiemr0 value
   f=(lc*256) + tc;                     //calculate frequency
   printf("lc %u  tc %u  f %lu \n\r",lc,tc,f );//send to PC terminal program
   }                                  //end of forever while
} //end of main


OK, decided it was easier to cut this 'Timer0 only' code than try to 'find' the 1,000 emails that Gmail 'lost' from my account....
Considering it's running on the internal RC oscillator, the 'math' says it's within 2% accuracy, probably not the most efficient or neat code. Uses about 1/4 of ROM and 20% of RAM.

Jay
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Sun Jan 22, 2023 2:26 am     Reply with quote

Thank you so much. I will try the code as soon as possible. good luck with your work.
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 22, 2023 7:38 am     Reply with quote

I changed the sampling time to 1/2, 1/4 and 1/8th of a second, corrected the 'math' and at 1/2sec, +1% error, 1/4sec, +3% error, 1/8th, +7% error.
So, if you can live with the error (or edit the 'math'), you can sample faster then the PIC could do more than just be a frequency counter.
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Sun Jan 22, 2023 8:48 am     Reply with quote

The first value of the codes you have given is correct, there is a deviation in the next values. Calculating wrong. The codes are working very nice.
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 22, 2023 10:29 am     Reply with quote

To get real accurate results, you need to KNOW what frequency the PIC clock is operating and then adjust delay_ms(xxx) so that the 1 second 'delay' (where counting is done ), is exactly 1 second.
The internal RC is a 'nominal' 4MHz not 4.00000000 MHz, the delay_ms() function may be off, say 1/2ms, that 500usecs, so 'errors' are to be expected.
You should be able to use delay_us(xxxxxx) to get a more accurate 'delay' during the counting stage.
Also if you use a crystal cut to a 'binary' frequency, like 2.457600 MHz, you'll get better results.

What I posted was a 'quick and basic' frequency counter using Timer0, easy to copy/edit and make better.

Jay
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Sun Jan 22, 2023 1:20 pm     Reply with quote

20mhz oscillator delay_ms(986); as accurate measurement
sifirzero1



Joined: 14 Dec 2022
Posts: 37

View user's profile Send private message

PostPosted: Sun Jan 22, 2023 1:21 pm     Reply with quote

thank you so much. I understood the logic
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
Page 3 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