6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 28, 2024 6:14 pm

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed Mar 01, 2023 2:36 pm 
Offline

Joined: Wed Mar 01, 2023 2:33 pm
Posts: 20
Hello,

I have build Ben Eater's circuit of 6502.
I have written a LCD program for 4bit mode and it works. But along with that, I am trying to toggle PORTB, pin0 and it is not working.
Can anyone please look into the code and point out what is wrong?

Thanks


Attachments:
delay_timer.S [2 KiB]
Downloaded 98 times


Last edited by claw on Thu Mar 02, 2023 5:29 am, edited 1 time in total.
Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 01, 2023 3:13 pm 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 325
You have print_msg exiting directly to loop, skipping the write to DDRB (and also the write to PORTA). Port B will never switch to an output.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 01, 2023 3:24 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1467
Location: Scotland
claw wrote:
Hello,

I have build Ben Eater's circuit of 6502.
I have written a LCD program for 4bit mode and it works. But along with that, I am trying to toggle PORTB, pin0 and it is not working.
Can anyone please look into the code and point out what is wrong?

Thanks


your print_msg loop jumps past the initialiser for the toggle loop, so DDRB is never initialised.

What you could do is change the

reset:

code to initialise BOTH ports, so

Code:
reset:
  lda #$FF
  sta DDRA
  sta DDRB


Also, what's the clock speed?

Your delay_loop will execute 256 (outer) * 256 (inner) = 65536 times. The inner loop will take 5 clock cycles per loop, so that's 256 * 5 cycles, the outer loop will add another 5 clock cycles per execution of the inner loop, so you're looking at 256 * 5 + 256 * 5 = about 1.6 million clock cycles give or take. At 1Mhz, well that's just over 1.5 seconds, but in the Khz range of the Ben eater thing? A very very long time. Try reducing the ldy and ldx instructions to single digit numbers...

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 3:08 am 
Offline

Joined: Wed Mar 01, 2023 2:33 pm
Posts: 20
Thanks very much for your inputs. It works now.
I am wondering how I overlooked this trivial mistake.

And yes, the clock is 1Mhz. I am just experimenting with the delay.
I will switch to the timers for the delay shortly. However, on a side note, the delay is not 1.6 seconds as you have mentioned!.
It blinks as if the delay is around 250 to 500ms! - but that is not the topic for my concern!!!

Thanks for your time guys.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 3:23 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
claw wrote:
It blinks as if the delay is around 250 to 500ms!

I took a quick stab at it and arrived at ~ 327 ms @ 1 MHz. Now, back to our regularly scheduled program ...

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 4:45 am 
Offline

Joined: Wed Mar 01, 2023 2:33 pm
Posts: 20
Thanks Mike.
I think your calculations should be correct.

I am actually surprised to see lots of activity in this forum! I thought forums are dead in this age.

I am looking forward to tinker more on the 6502 and custom SBCs!


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 5:20 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8403
Location: Midwestern USA
claw wrote:
Thanks very much for your inputs. It works now.
I am wondering how I overlooked this trivial mistake.

Even experienced programmers can make mistakes like that. Long, long ago, I chased a bug in a program for the better part of an afternoon, a frustration that was not soon forgotten. The mistake was a classic head-slapper: a TXA instruction that should have been TAX. Yep! Nothing more than a boneheaded typo. And, no, I'm not dyslexic. :D

The bad thing about assembly language is it’s quite unforgiving. A worse thing about assembly language is you can end up drowning in a bowl full of spaghetti. The good thing about assembly language (aside from speed of execution) is it forces you to be attentive to the details. In my experience, the best high-level programmers are those who started at the bottom, so to speak, meaning writing assembly language programs. They are the ones who have learned to pay attention to the tedious minutia in a way that both coaxes best performance from a system and reduces the tendency for bugs to erupt.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 5:28 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8520
Location: Southern California
claw wrote:
I thought forums are dead in this age.

How so?  Most of the forums I'm on are very active.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 7:16 am 
Offline

Joined: Wed Mar 01, 2023 2:33 pm
Posts: 20
GARTHWILSON wrote:
claw wrote:
I thought forums are dead in this age.

How so?  Most of the forums I'm on are very active.

May be the ones I was on are dead (Dead in the sense, users left for some other platforms like reddit or something called discord which I don't even understand how to operate!)

I hope this forum is focusing on 6502 computer - I myself am starting on this topic though (started couple of weeks back to be honest).
I tried to build Ben Eater's 8-bit computer couple of years back (almost 60% complete). But due to the breadboard quality issue, it's still pending. Do you guys have any suggestions on good generic SBC forums where they discuss things like Ben Eater's 8-bit computer?
Since I learnt a lesson due to breadboard quality. This time for 6502, I ordered busboard BB830 ones which did not cause any problem till now.

Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 8:02 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8520
Location: Southern California
claw wrote:
GARTHWILSON wrote:
claw wrote:
I thought forums are dead in this age.

How so?  Most of the forums I'm on are very active.

May be the ones I was on are dead (Dead in the sense, users left for some other platforms like reddit or something called discord which I don't even understand how to operate!)

I've read a few things on reddit (when linked by someone else), but I got on discord at someone's recommendation (or maybe it was a request), and like you, I can't figure it out either; and then the log-in process is very long, giving me three captchas ("Select all the pictures with crosswalks," etc.).  One forum I'm on that has been in a coma for probably 15 years, because of spammers, is Phil Pemberton's 6502ag Yahoo group, which has been migrated to groups.io since Yahoo closed Yahoo groups a few years ago, but all the old messages have not been migrated over yet.  It's a listserv though, and I have most of them in email.  In an effort to stir interest, I post a couple of times a year, but almost no one else does.

Quote:
I hope this forum is focusing on 6502 computer - I myself am starting on this topic though (started couple of weeks back to be honest).
I tried to build Ben Eater's 8-bit computer couple of years back (almost 60% complete). But due to the breadboard quality issue, it's still pending. Do you guys have any suggestions on good generic SBC forums where they discuss things like Ben Eater's 8-bit computer?

I would say 6502.org and this forum are the world hub of all things 6502.  So you've come to the right place.  I have my own very extensive mostly-6502 site (linked below), as do a few others here; but 6502.org is the hub. :D

Quote:
Since I learnt a lesson due to breadboard quality. This time for 6502, I ordered busboard BB830 ones which did not cause any problem till now.

They make a good product.  I've used ones from Global Specialties too, all American ones with a lifetime warranty, and never had any connection problems.  Nevertheless, I don't do this computer stuff on breadboards.  I did make my first CMOS 65c02 computer on breadboards and didn't have any problems, in 1986 or '7, but that was with 2MHz parts and 74HC logic which is pretty tame as far as edge rates go.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 8:08 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8403
Location: Midwestern USA
claw wrote:
GARTHWILSON wrote:
claw wrote:
I thought forums are dead in this age.

How so?  Most of the forums I'm on are very active.

May be the ones I was on are dead (Dead in the sense, users left for some other platforms like reddit or something called discord which I don't even understand how to operate!)

Most forums die due to inadequate moderation that allows off-topic crud to creep in. Around here, diligent moderation has kept spammers out. Also, we try to avoid getting into hot-button things, such as politics and “my computer is better/faster/cheaper/prettier than yours” flame wars.

Quote:
I hope this forum is focusing on 6502 computer...

This place isn't called 6502.org for nothing. We try to keep chatter about Intel, Motorola and Zilog MPUs down to a dull roar. :D

Quote:
Do you guys have any suggestions on good generic SBC forums where they discuss things like Ben Eater's 8-bit computer?

I’m not aware of any such forums—this one is arguably the most useful when it comes to getting help with a 6502 unit.

A problem that has been noted—which results in people coming here seeking help—is that Mr. Eater glosses over the practical aspects of constructing a working unit and in some cases, omits information that the builder needs to complete a successful build. There is more to it than rounding up some parts and wiring things together. Usually when someone comes here looking for help after trying to build a Ben Eater unit we suggest they visit Garth’s 6502 website so they can read his 6502 primer and get some of the gaps in their knowledge filled in.

Quote:
Since I learnt a lesson due to breadboard quality. This time for 6502, I ordered busboard BB830 ones which did not cause any problem till now.

Poor-quality breadboard has sabotaged many a project. Even use of a premium-quality breadboard doesn’t guarantee anything. Those long wires can toss a ton of inductance into the circuit and prevent things from working. Things such as switching noise and ground-bounce can make what appears to be an otherwise correctly-built unit unstable or DOA.

Oops! Garth’s post appeared right before mine. So you get to read essentially the same thing twice. :D

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 9:40 am 
Offline

Joined: Wed Mar 01, 2023 2:33 pm
Posts: 20
Thanks very much for your insights, Mr. Garth and Mr. Dinosaur.

I agree that it is frustrating sometimes when Ben glosses over few things in his videos. But nevertheless, I started this hobby after seeing Ben's videos. Thanks for the 6502 primer. I will definitely go through it (given the experience you guys have on this field).

Also on the breadboard part, most frustrating is such parts like the DIP switches which smaller leads popping out randomly!

While watching Ben's videos, I was under the impression that those are the only information I have apart from the datasheets. But now, I see that this site is a gold mine and many experienced engineers both in profession and age :)


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 11:41 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1467
Location: Scotland
barrym95838 wrote:
claw wrote:
It blinks as if the delay is around 250 to 500ms!

I took a quick stab at it and arrived at ~ 327 ms @ 1 MHz. Now, back to our regularly scheduled program ...


Well I'm intrigues now - obviously my back of an envelope calculations were an order of magnitude out, so let me see if I can get it right.. Just because:

This is the code:

Code:
delay_loop:
 ldy #$ff
delloop1:
 ldx #$ff
xloop1:
 dex
 bne xloop1
 dey
 bne delloop1
 rts


So the inner loop is:

Code:
xloop1:
    dex
    bne  xloop1


The dex is 2 cycles and the bne is 3 cycles, (but only 2 on the very last one which I never bothered counting before). X in initialised at 255, so the loop count in 255, so that's 254 loops of 5 cycles and one loop of 4 cycles = 1274 cycles.

The outer loop also runs 255 times, so the inner loop will run 255 times 1274 cycles = 324870 cycles.

The outer loop also has an overhead - same as the inner loop which is 254 * 5 + 4 = 1274 cycles.

And that needs to be added (not multiplied which I did before) to the grand total giving 324870 cycles or about 1/3 of a second at 1Mhz.

(plus a tiny overhead for jsr/rts)

Phew!

FWIW: I've used the WAIT routine out of the Apple II monitor in the past for a "calibrated" delay - not really needed here but maybe worthwhile knowing about.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 12:28 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
BigDumbDinosaur wrote:
Quote:
Do you guys have any suggestions on good generic SBC forums where they discuss things like Ben Eater's 8-bit computer?

I’m not aware of any such forums—this one is arguably the most useful when it comes to getting help with a 6502 unit.

I'd mention the retrobrewcomputers forum and the VCFederation forums, as well as the Stardot forums, as being active, well-moderated, and adjacent to these interests. You'll get similar advice over on anycpu.org forums, although there are far fewer people there.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 02, 2023 12:56 pm 
Offline

Joined: Wed Mar 01, 2023 2:33 pm
Posts: 20
drogon wrote:
And that needs to be added (not multiplied which I did before) to the grand total giving 324870 cycles or about 1/3 of a second at 1Mhz.
-Gordon


I should say you have got a lot of patience. One that I always try to acquire from your generation. And I suppose your username seems to be an anagram of your name? or is it a conincidence? :)

BigEd wrote:
I'd mention the retrobrewcomputers forum and the VCFederation forums, as well as the Stardot forums, as being active, well-moderated, and adjacent to these interests. You'll get similar advice over on anycpu.org forums, although there are far fewer people there.


I went through these. vcfed is something like a collectors forum! stardot and retrobrew looks similar to this site. I feel retrobrewcomputers has some really interesting stuff though! thank you.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


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 post attachments in this forum

Search for:
Jump to: