[SOLVED] Problem with PORTB in 6522
[SOLVED] Problem with PORTB in 6522
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
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 131 times
Last edited by claw on Thu Mar 02, 2023 5:29 am, edited 1 time in total.
Re: Problem with PORTB in 6522
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.
Re: Problem with PORTB in 6522
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
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
What you could do is change the
reset:
code to initialise BOTH ports, so
Code: Select all
reset:
lda #$FF
sta DDRA
sta DDRBYour 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/
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Re: Problem with PORTB in 6522
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.
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.
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: Problem with PORTB in 6522
claw wrote:
It blinks as if the delay is around 250 to 500ms!
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)
Mike B. (about me) (learning how to github)
Re: Problem with PORTB in 6522
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!
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!
- BigDumbDinosaur
- Posts: 9427
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Problem with PORTB in 6522
claw wrote:
Thanks very much for your inputs. It works now.
I am wondering how I overlooked this trivial mistake.
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.
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!
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Problem with PORTB in 6522
claw wrote:
I thought forums are dead in this age.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Problem with PORTB in 6522
GARTHWILSON wrote:
claw wrote:
I thought forums are dead in this age.
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.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Problem with PORTB in 6522
claw wrote:
GARTHWILSON wrote:
claw wrote:
I thought forums are dead in this age.
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 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.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- BigDumbDinosaur
- Posts: 9427
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Problem with PORTB in 6522
claw wrote:
GARTHWILSON wrote:
claw wrote:
I thought forums are dead in this age.
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.
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.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: [SOLVED] Problem with PORTB in 6522
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
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
Re: Problem with PORTB in 6522
barrym95838 wrote:
claw wrote:
It blinks as if the delay is around 250 to 500ms!
This is the code:
Code: Select all
delay_loop:
ldy #$ff
delloop1:
ldx #$ff
xloop1:
dex
bne xloop1
dey
bne delloop1
rtsCode: Select all
xloop1:
dex
bne xloop1The 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/
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Re: Problem with PORTB in 6522
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?
Re: Problem with PORTB in 6522
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
-Gordon
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.