Qaisar Azeemi
Full Member level 5
- Joined
- Feb 11, 2011
- Messages
- 315
- Helped
- 16
- Reputation
- 32
- Reaction score
- 15
- Trophy points
- 1,298
- Location
- Peshawar, Pakistan, Pakistan
- Activity points
- 3,829
In this application, the PIC 16F84A operated as a frequency
counter which can read frequencies from 10 Hz to 30 MHz. It
is used the method of measuring the 24-bits (3-bytes) counter
value from the prescaler, TMR0 (timer 0 module) and some
other registers, such as Option Register. The basic hardware
for the measurement circuit is depicted in Fig. 2. It consists of
the frequency input at TMR0 or TOCKI (pin3 in a PIC
16F84A). This pin is connected to RA3 and the input
frequency is connected to TOCKI through a 470Ÿ resistor.
TMR0 is configured to measured the input frequency, at
RA4 of the PIC 16F84A. The input frequency is “gated” for a
precise duration of time. Before starting this precise “gate”,
TMR0 is cleared and the RA3 pin is configured as an input.
The precise “gate” is implemented in software as an accurate
delay. A 24-bit value of the input frequency is now saved in
TMR0, Registers and 8-bit prescaler. By concatenating the
calculated value and the original value from TMR0 (256-N),
the 24-bit value for the frequency is determined.
//Timer 0 will count and Timer 1 will measure 1 second time using interrupts ; mikro=16f877a
// OUTPUTS
#define led PORTB.F2 // simple blinking led to show the system is working
sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
//=======End LCD Connections=============================================
unsigned int x=0,frq=0, cnt=0;
void interrupt()
{
if(PIR1.TMR1IF)
{
T1CON.TMR1ON=0; //stop
TMR1L=0XEE; // <------------- reload the timer
TMR1H=0X85;
if(cnt>=4)
{
led=~led;
frq=1;
cnt=0;
x=tmr0;
tmr0=0;
}
//frq=1;
PIR1.TMR1IF=0; // <------------- clear the timer interrupt flag
}
}
void main()
{
OPTION_REG=0xA0; // for timer 0; NO presscaller; counter mode at T0CKI
T1CON=0X60; // 1:8 prescallar, timer off
ADCON1=0x07; // adc reg initialization ; changes port a to digital I/O
INTCON=0x80; // globle interrupt enabled
TMR1L=0xEE;
TMR1H=0x85;
T1CON.TMR1ON=1; // timer on
PIR1.TMR1IF=0;
TRISA.f4=1;// making ra4 as input
x=0;
frq=0;
lcd_init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT); //*/
Lcd_Out(1,1,"Frequency");
while(1)
{
if(frq==1)
{
Lcd_Out(2,2,X);
Lcd_Out_CP("Hz");
frq=0;
}
}
}
//Timer 0 will count and Timer 1 will measure 1 second time using interrupts ; mikro=16f877a
// OUTPUTS
#define led PORTB.F2
sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
//=======End LCD Connections=============================================
unsigned int frq=0, cnt=0;
unsigned short G=0;
unsigned char op[12];
void interrupt()
{
if(PIR1.TMR1IF)
{
T1CON.TMR1ON=0; //stop
TMR1L=0XEE; // <------------- reload the timer
TMR1H=0X85;
cnt++;
if(cnt>=4)
{
led=~led;
frq=1;
cnt=0;
G=tmr0;
tmr0=0;
}
//frq=1;
PIR1.TMR1IF=0; // <------------- clear the timer interrupt flag
T1CON.TMR1ON=1;
}
}
void main()
{
OPTION_REG=0xA0; // for timer 0; NO presscaller; counter mode at T0CKI
T1CON=0X60; // 1:8 prescallar, timer off
ADCON1=0x07; // adc reg initialization ; changes port a to digital I/O
INTCON=0xc0; // globle & prephral interrupt enabled
TMR1L=0xEE;
TMR1H=0x85;
PIR1.TMR1IF=0;
PIE1.TMR1IE=1;
T1CON.TMR1ON=1; // timer on
TRISA.f4=1;// making ra4 as input
TRISB.f2 = 0; //o/p
cnt=0;
G=0;
frq=0;
lcd_init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT); //*/
Lcd_Out(1,1,"Frequency");
while(1)
{
if(frq==1)
{
shortToStr(G,op);
Lcd_Out(2,2,op);
Lcd_Out_CP("Hz");
frq=0;
}
}
}
void interrupt()
{
if(PIR1.TMR1IF)
{
T1CON.TMR1ON=0; //stop
TMR1L=0XEE; // <------------- reload the timer
TMR1H=0X85;
cnt++;
if(cnt>=4)
{
led=~led;
frq=1;
cnt=0;
G=tmr0;
tmr0=0;
}
//frq=1;
PIR1.TMR1IF=0; // <------------- clear the timer interrupt flag
T1CON.TMR1ON=1;
}
}
if(cnt>=4)
{
led=~led;
frq=1;
cnt=0;
G=tmr0;
tmr0=0;
}
A search on Google and on edaboard should provide loads of helpful information:
https://www.edaboard.com/threads/201375/
https://www.edaboard.com/threads/180221/
http://www.pic-tronics.com/Frequency-Counter-Using-PIC16F877A.php
http://sites.google.com/site/ehobbyprojects/make-a-simple-frequency-counter
http://hackedgadgets.com/2006/06/14/frequency-counter-using-a-pic/
http://www.google.com/search?hl=en&...86.13j2j5j1.21.0.les;..0.0...1c.1.CSmFcAmbIHQ
You have to use i2c or spi external eeprom like 24LC or 25LC series eeprom and use i2c or spi library and write the code.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 #include <16F877A.h> #DEVICE ADC=10 #fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT #use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #include "lcd.c" #define ARRAY_SIZE 7 int search,i,vals,found; float value1,value; float l; const float k[]={100,121,125,156,256,350,352}; const float j[]={410,420.5,450.6,485.2,600.5,854.6,905.8}; int main(void) { set_tris_c(0xff); set_tris_b(0x00); while(1) { lcd_init(); delay_us(200); set_timer1(0); setup_timer_1(t1_external | T1_DIV_BY_1); delay_ms(1000); setup_timer_1(T1_DISABLED); value=get_timer1(); value1=value; if(input(PIN_C4)!=1) { for ( i =0,found=-1;i <ARRAY_SIZE ; i++) if((value1<= j[i])&&(k[i]<=value1)) { l=(0.1*i)+7.0; printf(lcd_putc,"\f%2.1d", i); delay_ms(3500); printf(lcd_putc,"\f%2.1f", l); printf(lcd_putc,"\%%"); delay_ms(3500); } } }
A search on Google and on edaboard should provide loads of helpful information:
https://www.edaboard.com/threads/201375/
https://www.edaboard.com/threads/180221/
http://www.pic-tronics.com/Frequency-Counter-Using-PIC16F877A.php
http://sites.google.com/site/ehobbyprojects/make-a-simple-frequency-counter
http://hackedgadgets.com/2006/06/14/frequency-counter-using-a-pic/
http://www.google.com/search?hl=en&...86.13j2j5j1.21.0.les;..0.0...1c.1.CSmFcAmbIHQ
Hello Tahmid,can you plz help me to understand why on your blog of SPWM generation for
TBL_POINTER_SHIFT = TBL_POINTER_NEW >>8;with that value of shifting less than 8 the simulation shows error even in implementation the signal are not very nice like the one you posted on your blog??
All that is explained in this tutorial:
Demystifying The Use of Table Pointer in SPWM - Application in Sine Wave Inverter
https://tahmidmc.blogspot.com/2013/02/demystifying-use-of-table-pointer-in.html
Hope this helps.
Tahmid.
I read it but now I have a problem I want to control the H_Bridge with 20KHz but its generation I decided imossible because I am not coming to get but the calculations I did I refered to your blog and I think that I am right with;can you plz help me to get that value of 20KHz?
Also the signal of C and D on your circuit me I am getting the difference to it can you help me to know where the error is.(when I generate other signals not 20KHz I am getting a signal different to what you posted).
Help plz.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?