Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Arduino Mega Timer/Counter0 Not working

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
snow

Bascom Member



Joined: 28 Jun 2005
Posts: 145
Location: Ashburton / Mid Canterbury / New Zealand

newzealand.gif
PostPosted: Mon Jul 13, 2015 10:12 am    Post subject: Arduino Mega Timer/Counter0 Not working Reply with quote

Hi All
I must be overlooking something real simple. I cant get the Timer/Counter0 to work on the Arduino Mega as a counter


Code:


'-----------------------------------------------------------
'                   Counter testing
'                              21-june-15
'Version 1. .
'Testing to read the timer/counter0 on the proto board

'-----------------------------------------------------------

$regfile = "m2560def.dat"
$crystal = 8000000                                                              ' used crystal 8MHZ frequency
$hwstack = 32                                                                   ' default use 32 for the hardware stack
$swstack = 10                                                                   ' default use 10 for the SW stack
$framesize = 40


'---******* setup LCD pinouts ******----
Config Lcdbus = 4
Config Lcd = 16x2
Config Lcdpin = Pin , Db4 = Porte.3 , Db5 = Portg.5 , Db6 = Porte.5 , Db7 = Porte.4 , E = Porth.4 , Rs = Porth.3
Config Lcd = 16 * 2
Display Off
Cls
Cursor Off
Waitms 100
Display On
'---*** Finishing setting up LCD Pinouts ***----

Config Timer0 = Counter , Edge = Rising , Prescale = 1
Enable Timer0
Start Timer0
Enable Interrupts

Do
     Cls
     Lcd "Count: " ; Timer0
     Waitms 100

Loop

End
 

It just seem to run all the time with no pulse input even when i tie pin 38 of the baord low

Cheers
Snow
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 839
Location: France

france.gif
PostPosted: Wed Jul 15, 2015 7:12 pm    Post subject: Reply with quote

hello,


If you post here it means that it is on an Arduino mega2560 ? so why Crystal 8Mhz ???
in this case indicated you must update
$regfile = "m2560def.dat"
$crystal = 16000000
$hwstack = 40 ' mini
$swstack = 16 ' mini
$framesize = 40 ' mini
You have lots of ram, use them for the stacks

an lcd display is a relatively slow
CLS and waitms 100 is a little short for a change
use locate x, Y: lcd Spc (4) to clear only the number

Off display
CLS
Off cursor
Waitms 100
Display On
all this is useless

Config Lcdbus = 4
Config Lcd = 16 x 2 are not necessary, they are the default value.

test the display with
CLS
Locate 1.1: lcd "hello word"
Locate 2.1: lcd "Hello!"
wait 2
CLS
then your program
-----------------------------------------------------------
very long ago I played with counters on an M8
Here is the program


CLS
Config Timer0 = Counter, Edge = Rising
Tcnt0 = 0
Do
Enable Counter0 ' allows timer0
Enable Interrupts
Locate 1, 1: Lcd "register:"; Tcnt0 ' number of rotation

If <>0 Then Gosub Suite2 Tcnt0 ' or: one ovf0 suite
Loop
End ' end program

Suite2:
Disable Counter0 ' otherwise the prog is blocked, it cannot do anything in the gosub
K = K + 1
Locate 2, 1: Lcd "counter:"; K
Tcnt0 = 0 ' for the TCNT0 <>condition 0
Waitms 100 'no cls !
Return

bon courage
JP
Wink
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Page 1 of 1

 
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