Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] atmega16a bascom counter not work

Status
Not open for further replies.

prafful

Member level 2
Joined
Apr 3, 2011
Messages
45
Helped
28
Reputation
56
Reaction score
28
Trophy points
1,298
Location
Rajkot, India
Activity points
1,551
hi.

i want to count external pulse for my atmega16A.
here is my code

Code:
$regfile = "m16def.dat"
$crystal = 8000000

Const Tick = 10
Dim Y As Byte

Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7
Config Lcdpin = Pin , E = Porta.2 , Rs = Porta.0
Config Lcdmode = Port


Config Timer0 = Counter , Prescale = 1 , Edge = Rising

Load Timer0 , Tick

On Timer0 My_isr

Enable Timer0
Enable Interrupts

Display On
Lcd "Prafful Da Vinci"
Waitms 500


Do
Lowerline
Lcd "count" ; Timer0
Waitms 500
Cls

Loop

End

My_isr:
Load Timer0 , Tick
Y = Y + 1
Lcd Y

Return

i m giving 4 hz pulse form 555 timer circuit to my controller.

but after all, lcd only displaying TIMER0 value on lowerline.

it is not counting any external pulse.

what to do???
 

if there's no problem, counted value will be updated every 500 ms as the delay. but i usually found TCCR0 value was not fill exactly as we need. On your program, the value of TCCR0 will be &H01, but we need &H06 (maybe it's a bug of BASCOM). This &H01 means you set timer0 as timer with no presclaer. That's why you never see first line, because interrupt service called everytime when this timer overflow. Try replace Config Timer0 .... with "Tccr0=6".
 

Thanks a lot ARCH...

its a amazing suggestion i will try it soon on my mcu and tell you the result. hope it will work.

and by the way when i have look in simulation for tccr0 in above program it shows tccr0=h08 not h01.
 

Dear arch... thanks for suggestion.. i have tried with TCCR=H06 but still not showing any output.

Code:
$regfile = "m16def.dat"
$crystal = 8000000

Const Tick = 10
Dim Y As Byte

Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7
Config Lcdpin = Pin , E = Porta.2 , Rs = Porta.0
Config Lcdmode = Port


Tccr0 = 6

Reset Ddrb.0

Load Timer0 , Tick


On Timer0 My_isr

Enable Timer0
Enable Interrupts

Display On
Lcd "Prafful Da Vinci"
Waitms 500

Do
Lowerline
Lcd "count=" ; Timer0
Waitms 500
Cls

Loop

End

My_isr:
Load Timer0 , Tick
Y = Y + 1
Lcd Y

Return
 
Ok, try this :


Code Basic4GL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
$regfile = "m16def.dat"
$crystal = 8000000
 
Const Tick = 10
Dim Y As Byte
 
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7
Config Lcdpin = Pin , E = Porta.2 , Rs = Porta.0
Config Lcdmode = Port
 
Tccr0 = 6
Reset Ddrb.0
Ddrc = &HFF    'we use port C to check real value of timer
Load Timer0 , Tick
 
On Timer0 My_isr
 
Enable Timer0
Enable Interrupts
 
Display On
Upperline
Lcd "Prafful Da Vinci"
Waitms 500
 
Do
Lowerline
PortC = Timer0
Lcd "count=" ; Timer0
Waitms 500
Loop
 
End
 
My_isr:
Load Timer0 , Tick
Y = Y + 1 
UpperLine
Lcd Y
 
Return

 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top