Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 2nd April 2007, 12:06 AM   (permalink)
Default

Yes, it will be 1.6uS. Have you added code to zero timer1 in your interrupt as I suggested earlier.

Mike.
Pommie is offline  
Reply With Quote
Old 2nd April 2007, 03:26 AM   (permalink)
Default

20Mhz, therefor Instruction frequency = FOSC / 4
Thats 5,000,000 instructions a second

Remembering that TMR1 increments per instruction, but with a prescaler, therefor

1:1 = 200nS
1:2 = 400nS
1:4 = 800nS
1:8 = 1600nS

Edit: - I missed your post pom, sorry
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net

Last edited by gramo; 2nd April 2007 at 03:30 AM.
gramo is offline  
Reply With Quote
Old 2nd April 2007, 06:47 AM   (permalink)
Default

Quote:
Yes, it will be 1.6uS. Have you added code to zero timer1 in your interrupt as I suggested earlier.

Mike.
Now see on math.
x is the value of TIMER1, elapsed b/w two Low to High Edges.


I add zero zero value into TIMER1L and TIMER1H every time at startup of the loop..

Now on ur suggestion i will add zero zero value into TIMER1L and TIMER1H on interrupt.
Ayne is offline  
Reply With Quote
Old 2nd April 2007, 08:17 AM   (permalink)
Default

What is the minimum range of traditional Tacho Meters???
I am asking this because i never see any tachometer. and here is no posibility to see the ranges of a traditional Tacho Meter.

Now i made some changes in my program and it is runing Smoothly. But code i will paste here with improved efficiency later.
Ayne is offline  
Reply With Quote
Old 2nd April 2007, 04:43 PM   (permalink)
Default

Quote:
Received: R03314

Received: R03314

Received: R03313

Received: R03312

Received: R03313

Received: R03314

Received: R03314

Received: R03312
My readings are right.
but they are roling near and near.... It is right!!

Ur sugestions
Ayne is offline  
Reply With Quote
Old 2nd April 2007, 05:04 PM   (permalink)
Default

Personally I wouldn’t consider using a RPM meter in the manner you have. It is by far too open for errors from noise etc.

Sampling over a time period produces a rather accurate average of the signal. You can calculate the period and frequency quite easily afterwards, knowing that you are dealing with an average over a time frame - containing more than 1 sample.

A single pulse could be slightly deformed, or noise on the circuit could make it appear to go longer, giving a result that could be a couple of 100% out when dealing with fast signals. Circuits near or a part of motor circuits will be subject to a lot of noise thanks to the continuous EMF/EMI produced by the motor.

Sampling from PORTC on a PIC would be another great advantage, especially if signals are not square pulse, but rather ac/sine types. PORTC has built Schmitt triggers on every pin
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net

Last edited by gramo; 2nd April 2007 at 05:57 PM.
gramo is offline  
Reply With Quote
Old 2nd April 2007, 06:18 PM   (permalink)
Default

Code:
program RPM_Counter


' variables declaration
Dim i, j, UART_Byte, Over_Flow, Averaging As Byte
Dim Digit as Byte[5]
Dim T As Longint
Dim Capture As word absolute $15
Dim RPM, Period As Longint

'sub procedure procedure_name ' procedures declaration
sub procedure interrupt               'On

 if TestBit(PIR1,CCP1IF) = 1 then     'Capture mode Interrupt Flag

 Inc(i)
 Select case i
 Case 1
   T1CON.TMR1ON = 1

 Case 2
  PIE1.CCP1IE  = 0
  T1CON.TMR1ON = 0
  T            = (Over_Flow * 65535) + Capture
  i            = 0
  TMR1H        = 0
  TMR1L        = 0
  Over_Flow    = 0

  End Select

  PIR1.CCP1IF = 0
 end if

 if TestBit(PIR1,TMR1IF) = 1 then     'TMR1 Interrupt Flag
  Inc(Over_Flow)
  PIR1.TMR1IF = 0
 end if

end sub

Sub procedure Delay_10
 Delay_ms(10)
End Sub
'end sub


'sub function function_name ' functions declaration

'end sub
main:                       ' main program body
 Delay_10                   'Delay 10 milisecond For Stability in Supply
 Delay_10                   'Delay 10 milisecond For Stability in Supply
 TRISC   = 255              ' PORTC all Inputs
 PORTC   = 0                ' PORTC = 0
 PIR1    = 0                'individual flag bits for the peripheral interrupts
 T1CON   = %00110000        '11 = 1:8 Prescale value, Timer1 On bit Disabled
 CCP1CON = %00000101        '0101 = Capture mode, every rising edge
                            '0111 = Capture mode, every 16th rising edge
 INTCON  = %11000000        'GIE, PEIE Enabled
 PIE1    = %00000001        'CCP1 Interrupt Disabled & TMR1 Overflow Interrupt Enabled
 Averaging    = 0

 USART_init(19200) ' initialize USART module

ReStart:
 PIE1.CCP1IE  = 1           'CCP1 Interrupt Enable bit

 do
 Delay_10

 if TestBit(PIE1,CCP1IE) = 0 then
 Goto Convert_RPM
 End if

 Inc(j)
 loop until j = 27

 Goto ReStart

Convert_RPM:
 Period = T

 RPM = 37500000 / Period   'Convert Time Period in Round/Minute

Into_Digit:
 Digit[0] = RPM Div 10000 mod 10
 Digit[1] = RPM Div 1000  mod 10
 Digit[2] = RPM Div 100   mod 10
 Digit[3] = RPM Div 10    mod 10
 Digit[4] = RPM           mod 10

UsartWrite:
   Usart_Write(0x52)                   ' "R" For indication of RPM
   For j = 0 To 4 step 1
   UART_Byte = Digit[j] + 48           ' Add 48 for converting into ASCII
   Usart_Write(UART_Byte)
   Next j
   Usart_Write(0x0D)                   'CR
   Usart_Write(0x0A)                   'LF

Goto ReStart
end. ' end of program
Above Program is runing
Complier MikroBasic.
Output on Serial Port (PORTC.6, PORTC.7)
Sensor Input on PORTC.2
_______________
Muhammad Ahmed
Ayne is offline  
Reply With Quote
Old 2nd April 2007, 06:29 PM   (permalink)
Default Poling.

Plz vote..

U Prefer??? for RPM Count and why.

1. Sampling over a time period

OR

2. Measuring the Period of a Square Wave



If i use No.1(Sampling over a time period) method then what should be the time for sampling???
Ayne is offline  
Reply With Quote
Old 2nd April 2007, 06:43 PM   (permalink)
Default

Quote:
Originally Posted by Ayne
If I use No.1(Sampling over a time period) method then what should be the time for sampling???
The time period depends on the RPM your measuring, and a comfortable error factor if you miss one or two cycles each sample.

For example, your input is 100Hz, and you sample for 100mS, so you should receive 10 "pulses". But what if you started sampling mid-way through, then you could miss a pulse, or read an 'extra' pulse, for this example you "miss" a pulse - ie - you sampled 9 Pulses. Now you have to scale your result up by 10, and then by 60 to give RPM, as you only sampled 1/10th of a second.

Your result would be 5940 RPM (1% Error), But the correct answer should be 6000RPM. Notice that a single error at 100Hz with a 100mS sample rate will scale accordingly to your sample time.

The work around - use a longer sample time. In this case 500mS. Now the same thing happened - you missed a cycle for some reason (you read 499 samples instead of 500). Now your RPM will read 5988 (0.2% Error).

With a single sample, you could be out by much much more than 0.2% - 1% error, infact depending on the application, you could be out by near 100%, if not more on some samples.

By all means, if the signal is a clean square wave, and you know there is not going to be any noise or read errors, then single sample. But that’s not the case for most applications
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline  
Reply With Quote
Old 2nd April 2007, 10:31 PM   (permalink)
Default

Well done, to get steady readings like that where your error is less than 0.1% is fantastic.

Mike.
Pommie is offline  
Reply With Quote
Old 30th April 2007, 02:59 PM   (permalink)
Default

Is there anywhere I can get an example of this code in ass.? I'm trying to wrap my head around the "time between pulses/ tmr overun" subject, but its kind of difficult when its in an unfamiliar format. For now I don't really need any lcd or display, just how to get the result. I don't want a gimme, just a point in the right direction with a good description if at all possible. I haven't started implementing it any but it is the next step in my project.
hotrodhed120 is offline  
Reply With Quote
Old 30th April 2007, 04:07 PM   (permalink)
Default

Or maybe a code flow chart would be a good visual aid.
hotrodhed120 is offline  
Reply With Quote
Old 1st May 2007, 01:40 PM   (permalink)
Default

Hi hotrodhed120.
Above described method is measuring the Time Periode B/W Two edges.
and doing some math with that time and knowing the RPM.

Where r u confusing on which step??

OR

What r u trying to do may i help u.
Ayne is offline  
Reply With Quote
Old 2nd May 2007, 01:52 PM   (permalink)
Default

basically the same thing for RPM but I am writing in assembly.
I'm a bit fuzzy on the counting the tmr overrun to calculate frequency.
Or maybe I just need an overall description of what the program is doing step by step in plain engrish.? (assm.?)
I found microchips source code but I would like to understand what is actually going on and why as the program progresses, as I am a self taught newbie. Any help would be great.
hotrodhed120 is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Dual counter bananasiong Micro Controllers 45 24th March 2007 02:49 AM
How we can do it in Assembly..Help Needed Ayne Micro Controllers 37 29th December 2006 05:49 PM
PIC16f877A Project help Alex Ng Micro Controllers 5 26th July 2006 07:47 AM
[help] Power consumption issue on bullet counter project * Lanzer Electronic Projects Design/Ideas/Reviews 13 26th August 2005 06:06 AM
PROJECT: Bowling Pin Counter - 7 Segment Displays FLCARM1964 Electronic Projects Design/Ideas/Reviews 1 14th April 2005 01:56 AM



All times are GMT. The time now is 06:16 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.