caramoan tour package

caramoan tour package

Author Topic: frequency counter using PIC's RTCC  (Read 12049 times)

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #40 on: July 14, 2008, 12:41:24 AM »

since prescaler is 8-bit, the line

Code: [Select]
frequency = ((unsigned long)get_timer0()<<8) + prescaler;

should be

Code: [Select]
frequency = ((unsigned long)get_timer0()<<8) || prescaler;

but the actual 8-bit prescaler is not readable. Also, hindi ba fixed ang value ng prescaler (256)? Hindi na yata kailangan ang line na  prescaler--; sa loob ng do while loop


PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #40 on: July 14, 2008, 12:41:24 AM »

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #41 on: July 14, 2008, 12:49:04 AM »
after, disabling the input you have to perform the self-clocking to read the prescaler value

Code: [Select]
T0IF = 0;
while(!TOIF)
{
output_high(input_gate);
output_low(input_gate);
n++;
}

then followed by

Code: [Select]
frequency = ((unsigned long)get_timer0()<<8) || (255 - n);
//display frequency to LCD

PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #41 on: July 14, 2008, 12:49:04 AM »

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #42 on: July 14, 2008, 01:32:11 AM »
since prescaler is 8-bit, the line

Code: [Select]
frequency = ((unsigned long)get_timer0()<<8) + prescaler;

should be

Code: [Select]
frequency = ((unsigned long)get_timer0()<<8) || prescaler;

but the actual 8-bit prescaler is not readable. Also, hindi ba fixed ang value ng prescaler (256)? Hindi na yata kailangan ang line na  prescaler--; sa loob ng do while loop




lolz mali pala, dapat

Code: [Select]
frequency = ((unsigned long)get_timer0()<<8) | prescaler;
logical OR pala yun hehe  ;D
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #42 on: July 14, 2008, 01:32:11 AM »

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4180
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #43 on: July 14, 2008, 07:32:39 AM »
sir paranz ok lang din yung "+",

I think many are confused between the prescaler na configurable sa timer peripheral(divide by n) against prescaler value. Imagine nyo na lang ang prescaler is simple binary counter yung ikinuconfigure natin eh kung saang output ng counter ikakabit ang input ng TMR0,

e.g. kung divide by 2 sa output ng 1st digit
divide by 4 sa output ng 2nd digit and so on.

pero yung counter, since counter xa eh may value din xa, yun yung iniaad natin sanakuha nating TMR0, kaya dapat fixed na devide by 256 ang configuration natin.makukuha natin ang value ng prescaler by self clocking then counting the number of pulses bago magincrement ang timer0 ng 1, then we use the formula 256 - # of pulses.

Code: [Select]
while(true)
{
   //initialize
   prescaler_counter = 0;
   set_timer0(0);

   //getting TMR0 Value
   output_float(input_gate);          //enable input
   delay_ms(200);                       //gating time
   output_low(input_gate);           //disable input

   oldTMR0 = get_timer0();
   frequency = oldTMR0 * 256;  //pwede ring "frequency = oldTMR0 << 8;"
 
   //getting the prescaler value
   while(oldTMR0 == newTMR0)      //test if tmr0 has incremented
   {
      output_high(input_gate);       //self clocking
      output_low(input_gate);

      prescaler_counter++;            // count until TMR0 incremented

      newTMR0 = get_timer0();

   }
   frequency += (256 - prescaler_counter);
       
   display_reading();
}
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #43 on: July 14, 2008, 07:32:39 AM »

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #44 on: July 14, 2008, 07:59:32 AM »
ah ok, ganun pala ang self-clocking. :D
pag-aralan ko muna kung ano'ng pinagkaiba nya dun sa code ko..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #44 on: July 14, 2008, 07:59:32 AM »

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4180
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #45 on: July 14, 2008, 08:06:20 AM »
lagyan mo pala ng konteng nops
in between

 
Code: [Select]
    output_high(input_gate);       //self clocking
      output_low(input_gate);

baka hindi makilala ng input.

If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #46 on: July 14, 2008, 08:10:37 AM »
pwede na ang isang NOP? ???
Code: [Select]
output_high(input_gate);       //self clocking
delay_cycles(1);                 // NOP  (4 osc clock)
output_low(input_gate);
delay_cycles(1); 
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4180
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #47 on: July 14, 2008, 08:13:16 AM »
not sure ??? check mo scope kung makikita mo tumaas yung output, kung hindi eh ibig sabihin kulang pa.

for testing gawin mo na marami muna.
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #48 on: July 14, 2008, 08:27:43 AM »
ganito nga pala yung setup ko ng timer0:
Code: [Select]
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_256);prescaler: divide by 256
trigger: external low-to-high

mas appropriate yung low-to-high na trigger point keysa sa high-to-low 'no? ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: frequency counter using PIC's RTCC
« Reply #49 on: July 14, 2008, 08:37:11 AM »
Code: [Select]
//getting TMR0 Value
   output_float(input_gate);          //enable input
   delay_ms(200);                       //gating time
   output_low(input_gate);           //disable input


On this part, interrupts must be disabled for it may cause jitter and may add small errors on the reading.
Also, take note that delay_ms(200) may not be *ACCURATELY* 200ms and depends on the compiler.
You could do the delay in assembly and count the cycles manually.
The Cebuano Geek

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: frequency counter using PIC's RTCC
« Reply #50 on: July 14, 2008, 08:41:15 AM »
pwede na ang isang NOP? ???
Code: [Select]
output_high(input_gate);       //self clocking
delay_cycles(1);                 // NOP  (4 osc clock)
output_low(input_gate);
delay_cycles(1); 

This is OK.
NOPs are important if when changing the outputs fast using BSF/BCF as above.  This is due to PIC's inherent READ-MODIFY-WRITE problem.  On PIC18, this is not present if the LAT registers are used instead of setting the I/O directly.
The Cebuano Geek

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #51 on: July 14, 2008, 08:58:36 AM »
lagyan mo pala ng konteng nops
in between

 
Code: [Select]
    output_high(input_gate);       //self clocking
      output_low(input_gate);

baka hindi makilala ng input.


pwede na rin walang NOP, since the T0CKI can easily read even up to 50Mhz digital signal



sir paranz ok lang din yung "+",


oo nga pala. ty  ;)
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #52 on: July 14, 2008, 09:06:41 AM »

mas tama pala binigay na code ni glutnix sa self-clocking

Code: [Select]
while(oldTMR0 == newTMR0)
hindi kasi pwede yung binigay ko na sa CCS C, for hitech lang yun hehe  ;D

Code: [Select]
while(!T0IF)
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4180
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #53 on: July 14, 2008, 09:21:11 AM »
yup at saka hindi overflow aabangan natin kundi yung change (incerement by 1) sa timer0.

Well on the second thought overflow pa rin un, hehehe, overflow ng prescaler not the timer,hehehehe
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #54 on: July 14, 2008, 09:31:31 AM »
yup at saka hindi overflow aabangan natin kundi yung change (incerement by 1) sa timer0.

Well on the second thought overflow pa rin un, hehehe, overflow ng prescaler not the timer,hehehehe

ah oo nga pala, you are correct  ;)

hehe hidni ko napansin ah, basta overflow  ;D
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #55 on: July 14, 2008, 11:06:05 AM »
paki-clarify naman nung table na nasa AN592 "Frequency Counter Using PIC16C5X"
Quote
tama ba yung nasa last row nung table? ??? typographical error? ??? o ganyan talaga? ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4180
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #56 on: July 14, 2008, 11:11:09 AM »
alam ko nacheck ko na dati assembly nito, tama po yan, as you may have notice way below clock frequency na ang input frequency, ibang method/technique ang ginamit nya pagsukat, aralin ko po ulet ha.
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #57 on: July 14, 2008, 01:21:38 PM »
.. tama po yan, as you may have notice way below clock frequency na ang input frequency, ibang method/technique ang ginamit nya pagsukat..
ah ok.. kala typo error lang.. hehe  :D

   btw, glutnix_neo,
   masarap ba yung Fruitas shake na binili mo kaninang lunch time?  ::)
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4180
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #58 on: July 14, 2008, 01:28:23 PM »
nyahahaha, kilala mo na ko ha, ako nakita kita minsan hindi ko matandaan kung sino,hehehe
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #59 on: July 15, 2008, 08:28:19 AM »
pa-check uli ng code ko.. nilagyan ko na ng auto-range..
ok naman, automatic na nagbabago na ang kanyang range,
pero di ko sure kung ito ang pinaka-efficient:
Code: [Select]
while(true)
   {
      prescaler_counter = 0;
      oldTMR0 = get_timer0();
      sprintf(str2," Hz");
      if(get_pulses(1)==0)
      {
         if(get_pulses(5)==0)
         {
            if(get_pulses(50)==0)
            {
               if(get_pulses(200)==0)
               {
                  oldTMR0 = get_pulses(1000);
               }
               else{ oldTMR0 = get_pulses(200); sprintf(str2," Khz100to10"); }
            }
            else{ oldTMR0 = get_pulses(50); sprintf(str2," Khz1Kto100"); }
         }
         else{ oldTMR0 = get_pulses(5); sprintf(str2," Mhz10to1"); }
      }
      else{ oldTMR0 = get_pulses(1); sprintf(str2," Mhz50to10"); }
           
      do
      {
         output_high(input_gate);       //self clocking
         delay_cycles(1);
         output_low(input_gate);
         delay_cycles(1);
         prescaler_counter++;            // count until TMR0 incremented
      }while( get_timer0()==oldTMR0 && prescaler_counter<=256); 
      frequency = ((unsigned long)oldTMR0<<8) + (256 - prescaler_counter) - 1;
     
   display_reading();
   }
Code: [Select]
unsigned int get_pulses(unsigned char gate_time)
{
   set_timer0(0);
   output_float(input_gate);
   delay_ms(gate_time);
   output_low(input_gate);
   return get_timer0();
}

di ko muna nilagay yung technique for measuring frequency at the lowest range..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #59 on: July 15, 2008, 08:28:19 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com