Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Timer Counter Question
Goto page Previous  1, 2
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Jul 28, 2017 11:11 pm    Post subject: Reply with quote

In my country we have a say "Rome was not build at once" Wink
Try understand how counters/timers can be configured to count/measure freq before you say ARM Wink

Code:
$regfile = "m8def.dat"

'CONNECT SIGNAL INTO THE PORTD.4 (T0 INPUT)

$Crystal=8000000
$hwstack=64
$swstack=32
$framesize=128


Config Timer0 = Counter , Edge = Rising                'no prescale
Enable Timer0                                          'enable counting 256 overflow
On Timer0 Timer0_isr                                   'when Time rich 256 jump Interrupt will be fired
Enable Timer0                                          'allow this interrupt

'now we need 1second timer
Config Timer1 = Timer , Prescale = 256 , Compare_a = Disconnect , Compare_b = Disconnect , Clear_timer = 1
 Compare1a = 31249                                     '1000ms @8MHz/256  =1s
Enable Compare1a : On Compare1a Timer1_isr

Dim Overflows As Byte , Copy_overflows As Byte , Copy_of_timer As Byte
Dim Its_time As Byte , Helpd As Dword

Enable Interrupts

Do
 If Its_time = 1 Then
  Helpd = Copy_overflows
   Shift Helpd , Left , 8                              'multiply overflows by 256x times quicly
  Helpd = Helpd + Copy_of_timer                        'add rest of pulses
  Print "Freq=" ; Helpd ; "Hz"
 Its_time = 0
 End If

Loop


Timer0_isr:                                            'timer count 256/overflow
 Incr Overflows                                        'count 256`s
Return


Timer1_isr:                                            'every second
Copy_of_timer = Timer0
 Copy_overflows = Overflows
  Overflows = 0
    Its_time = 1
Return
 
Back to top
View user's profile Visit poster's website
Goorman

Bascom Member



Joined: 12 Jul 2017
Posts: 13

PostPosted: Sat Jul 29, 2017 7:58 pm    Post subject: Reply with quote

Hi EDC
ARM is just a wish. Very Happy
A good way to measure, but I think with this method I will lose PWMs, isn’t it?
Thanks for your code.
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
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
You cannot attach files in this forum
You cannot download files in this forum