Joined: 28 Jun 2005 Posts: 200 Location: Ashburton / Mid Canterbury / New Zealand
Posted: Mon Jul 13, 2015 10:12 am Post subject: Arduino Mega Timer/Counter0 Not working
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
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
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