View previous topic :: View next topic |
Author |
Message |
mototest2
Joined: 24 Dec 2006 Posts: 53
|
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
Posted: Fri Jan 22, 2016 6:18 pm Post subject: |
|
|
If you have some Mega lying around, you might try this.
I use to measure low frequency (<1Hz) with resolution of about 30, so 1Hz will be displayed as ~30 on the LCD (approximately, I have not calculated the timer1 gate time yet). Better resolution requires longer counting times, can be achieved by lowering the "crystal" frequency (no crystal required here).
I modified this :
http://rn-wissen.de/wiki/index.php?title=Beispiel_Drehzahlmessung_mit_RN-Control
for measuring low frequencies with some reasonable resolution.
Code: |
$regfile = "m32def.dat"
$crystal = 4000000 'can be set by fuse
$baud = 9600
$hwstack = 32
$swstack = 32
$framesize = 32
Config Int0 = Falling
Dim Zaehlerirq0 As Long , Timervorgabe As Word '3036
Dim Impulseprosekunde As Long
Dim ___lcdno , X As Byte '40x2 Zeichen Display. Umschaltbyte für E1<>E2, die Variable ___lcdno darf nicht verändert werden!
Timervorgabe = 1
Config Lcd = 40 * 2 'Anzeigemodus 40 x 2 Zeichen E2 = Portc.4 ,
Config Timer1 = Timer , Prescale = 1024
Config Portd.2 = Input 'Trigger input
....(see sorce)
|
|
|
Back to top |
|
|
mototest2
Joined: 24 Dec 2006 Posts: 53
|
Posted: Fri Jan 22, 2016 6:24 pm Post subject: |
|
|
in normal atmega I know how make it, but I want use hardware timer for calculate frequency as in link which I wrote
Code: | 'Config Tcd0 = Normal , Prescale = E1 , Event_source = E1 ,Event_action = Freq |
|
|
Back to top |
|
|
JC
Joined: 15 Dec 2007 Posts: 585 Location: Cleveland, OH
|
Posted: Thu Jan 28, 2016 3:56 am Post subject: |
|
|
For high frequencies, one can count the number of pulses per given period of time, (1 second, 0.1 Second, 10 Seconds, etc).
For low frequencies it is often better to count the period of the waveform, and then calculate the frequency.
It is best to let the Timer/Counter hardware module do the pulse width measurement for you, using the input capture mode.
JC |
|
Back to top |
|
|
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|