6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri May 10, 2024 6:18 am

All times are UTC




Post new topic Reply to topic  [ 32 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Mon Nov 06, 2023 4:38 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
Cookie13! wrote:
I have read Wilson´s excellent article on Interrupts and understand most of it I think.

Congratulations.  It's one of my first writings, and since my writing has (hopefully) improved a lot since then, I keep thinking I ought to revise that one.  And I don't know if I should update the cartoons or ham it up further, maybe like with a phone on the wall with a crank on it, LOL.

Quote:
In the above discussion I am not able to see how the 25ms delay is achieved. I am also following the alfredstate procedure. I am trying to use the T1 timer of the 65c22 for the delay. One-shot mode seems to be the right way to go as we need to run down the clock for each delay period and so ACR is set accordingly. My understanding is that IFR bit 6 is set when the clock runs down. IER is not set as there is no interrupt handler programmed, if I understand this correctly. So when I comment out jsr lcd_init the program works perfectly and prints a message to the LCD but as with others only on powerup not on subsequent resets. If I activate the LCD initiation subroutine, the 6502 goes on vacation, but never sends picture postcards. 8 bit operation of the LCD. 4 bit drove me even more nuts. Hope someone can spot the error.

Since it's for the initialization when you're just bringing the computer up and there's probably nothing loaded and pressing yet, I would just go the simpler route and do software delay loops.  Good comments are posted in the "Wasting time" topic (about delays).  After it's booted up and you're loading or running the intended software, you might not want to be doing long delays in software if the computer should be doing other things while waiting instead of twiddling its thumbs, so a jiffy clock of some sort is good there.  My article on simple methods for multitasking without a multitasking OS, for systems that lack the resources to implement a multitasking OS, or where hard realtime requirements would rule one out anyway, is at http://wilsonminesco.com/multitask/ .  But again, for this application, the simplest way is fine.  When you feed display data to the LCD later, you won't be needing those delays, so it won't be a problem.

_________________
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: Mon Nov 06, 2023 9:43 am 
Offline

Joined: Tue Oct 31, 2023 10:34 am
Posts: 15
Location: Germany
BigEd wrote:
(Private messages stay in the outbox until the recipient reads them)

Thanks. I figured this may be the case but confirmation is great to have.


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 07, 2023 3:51 pm 
Offline

Joined: Tue Oct 31, 2023 10:34 am
Posts: 15
Location: Germany
GARTHWILSON wrote:
Quote:
I would just go the simpler route and do software delay loops


As you can see in the modified code i have gone for software delays. Still nothing happens if the initialisation routine is activated. I also put an LED in PORT A to check my delay routine but it is just on once the message is displayed.
Code:
PORTB = $6000
PORTA = $6001
DDRB = $6002
DDRA = $6003
T1CL = $6004
T1CH = $6005
ACR = $600B
IFR = 600D

E  = %10000000    ; 1 sends data or instruction to LCD
RW = %01000000    ; 1 is read, 0 is write
RS = %00100000   ; 1 is data register, 0 is instruction register

  .org $8000

reset:
  lda #%11111111 ; Set all pins on port B to output
  sta DDRB

  lda #%11111111 ; Set all pins on port A to output
  sta DDRA
  lda #0
  sta ACR

  ; LCD initialisation

  ;jsr lcd_init

  lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
  jsr lcd_instruction
 
  lda #%00001111 ; Display on; cursor on; blink on
  jsr lcd_instruction

  lda #%00000110 ; Increment and shift cursor; don't shift display
  jsr lcd_instruction

  lda #%00000001 ; Clear display
  jsr lcd_instruction

  lda #%10000000 ; Set DDRAM to 0 (cursor position to left)
  jsr lcd_instruction


 ldx #0
print:
  lda message,x
  beq loop
  jsr print_char
  inx
  jmp print

message:
  .asciiz "Hello, World!!"

loop:
  lda #1
  sta PORTA
  jsr delay_50ms
  lda #0
  sta PORTA
  jsr delay_50ms
  jmp loop

delay_50ms:       
  ldy #22
outer_loop:
  ldx #250
inner_loop:
  dex
  nop
  nop
  bne inner_loop  ; Branch if x not zero (9 cyclesx250 = 2250 microsecs. Repeat 22 times will give 50 ms)
  dey
  bne outer_loop
  rts
 
lcd_init:
  jsr delay_50ms
  jsr delay_50ms
  lda #%00110000 ; Special function set
  jsr lcd_instruction_1
  jsr delay_50ms
  lda #%00110000 ; Special function set
  jsr lcd_instruction_1
  jsr delay_50ms
  lda #%00110000 ; Special function set
  jsr lcd_instruction_1
  jsr delay_50ms
  rts

lcd_instruction_1:  ; Used for setting up the LCD where busy flag can't be checked
  sta PORTB
  lda #0         ; Clear RS/RW/E bits
  sta PORTA
  lda #E         ; Set E bit to send instruction
  sta PORTA
  lda #0         ; Clear RS/RW/E bits
  sta PORTA
  rts


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 07, 2023 7:43 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
Hello, Cookie13!. I've only VERY casually skimmed over your code . But FWIW...

I believe "IFR = 600D" instead ought to say IFR = $600D. Instead, you've omitted the dollar sign. But you don't seem to be referring to IFR anyway, so this won't be the cause of your trouble.

In five places I see jsr lcd_instruction. But I see no such label defined (only the label lcd_instruction_1 ). Perhaps you have simply omitted the routine lcd_instruction from the listing you've shared with us... :|

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 08, 2023 5:14 pm 
Offline

Joined: Tue Oct 31, 2023 10:34 am
Posts: 15
Location: Germany
Dr Jefyll wrote:
Quote:
you've omitted the dollar sign. But you don't seem to be referring to IFR anyway, so this won't be the cause of your trouble.


Thanks for picking the IFR thing up. I left out the lcd_instruction as it is the standard Ben Eater one. I can summarize my situation as follows:
1)If i run hello-world after start-up it functions correctly. Hello-world uses several subroutines so the stack must be working.
2)If I try anything involving a delay nothing works. Delays are required to do the the initialization by instruction. I have tried both T1 of the VIA and using a software loop. Both of these possibilities use subroutines.

I have written a very simple program just to test delays and flash an LED on PORTA leaving any initialization of the LCD aside.
Code:
PORTB = $6000
PORTA = $6001
DDRB = $6002
DDRA = $6003




  .org $8000

reset:
  ldx #$ff
  txs

  lda #%11111111 ; Set all pins on port B to output
  sta DDRB

  lda #%11111111 ; Set all pins on port A to output
  sta DDRA
 

loop:
  lda #1
  sta PORTA
  jsr delay_50ms
  lda #0
  sta PORTA
  jsr delay_50ms
  jmp loop

delay_50ms:       
  ldy #22
outer_loop:
  ldx #250
inner_loop:
  dex
  nop
  nop
  bne inner_loop  ; Branch if x not zero (9 cyclesx250 = 2250 microsecs. Repeat 22 times will give 50 ms)
  dey
  bne outer_loop
  rts
 

 
  .org $fffc
  .word reset
  .word $0000


This also does nothing. Totally confused.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 08, 2023 6:37 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
Quote:
I left out the lcd_instruction as it is the standard Ben Eater one.
Alright, no big deal, because it sounds as if I won't need to refer to it right now anyway. But I (and many here) have zero familiarity with Ben's code, so it's generally better to include it (or at least a link to it).

Quote:
This also does nothing. Totally confused.
I don't notice any problem with your code. But as an experiment, you could try simplifying the loop as follows:

Code:
loop:
  lda #1
  sta PORTA
  ; jsr delay_50ms   ;;; commented out
  lda #0
  sta PORTA
  ; jsr delay_50ms   ;;; commented out
  jmp loop
This should cause the LED to flash at extremely high speed. To a human, the LED will appear to be steadily illuminated but at reduced brightness... *IF* the hardware is working properly. :!:

I suggest you avoid focusing too much on the code, because you could be experiencing the effects of hardware flakiness (all too common when breadboards are involved :roll: ).

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 08, 2023 6:50 pm 
Offline
User avatar

Joined: Wed Feb 13, 2013 1:38 pm
Posts: 586
Location: Michigan, USA
That code seems to be working ok on one of my boards with 1-MHz clock and with VIA at $6100..$610F rather than $6000..$600F. LED (upper left corner) is flashing nicely.


Attachments:
test.png
test.png [ 942.06 KiB | Viewed 1693 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 08, 2023 7:01 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
Cookie13! wrote:
This also does nothing. Totally confused.

I know it's probably just a careless idiom, but note that this is almost certainly not true! It is quite hard to get a 6502 to do nothing, unless you stop its clock. It is probably doing something, but not what you expect, and it is important to find ways to determine what that is. If you can think about it in terms of what it actually is doubt, then you're further asking the road to diagnosing why its not doing the thing you expected.

Some easy things to check when there are no external signs of activity are whether you can measure a clock signal at the CPU, whether you can see pulses on the SYNC pin, whether the addresses lines are counting up, whether you see a lot of pulses on the VPB pin. Then you can look at the VIA - is it getting its CS pins asserted? Can it see the clock and RWB?

Checking these kinds of things goes a long way towards solving these problems, and gives people here more information to help you troubleshoot with.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 08, 2023 10:05 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
When you figure it out, it will probably be one of those forehead-slappers, you know, one of those things that's so simple you don't even consider it, and instead waste days looking in the wrong places.  It happens to everyone at some point.  It could be something as simple as that the LED is in backwards, or not on the pin that you're toggling, like wrong port, pins counted wrong, or on bit 1 (because you put a 1 in PORTA, which is on bit 0, not bit 1).  The code looks ok though.  Is there anything else you didn't want to bother us with, because it doesn't seem like it's related, like maybe an interrupt set up and an ISR that's affecting X or Y without saving and restoring them?

Page 19 of the 6502 primer is about debugging.  http://wilsonminesco.com/6502primer/debug.html

_________________
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 Nov 09, 2023 9:50 am 
Offline

Joined: Tue Oct 31, 2023 10:34 am
Posts: 15
Location: Germany
Dr Jefyll wrote:
Quote:
as an experiment, you could try simplifying the loop as follows:

Good suggestion. This works at low clock speed and at 1MHz, the latter visible on oscilloscope. By the way i managed to get the version including the subroutine to work with a 50Hz clock but it would stop after a minute or 2. Strange. At 1 MHz the LED was on all the time as shown on the oscilloscope.

So it doesn't like subroutines somehow even though hello world includes them. A puzzle. I am also inclined to think there is something dodgy in the wiring but a nightmare to trace.
Thanks for the help so far.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 09, 2023 10:06 am 
Offline

Joined: Tue Oct 31, 2023 10:34 am
Posts: 15
Location: Germany
GARTHWILSON wrote:
[color=#000000]
Quote:
When you figure it out, it will probably be one of those forehead-slappers...... Is there anything else you didn't want to bother us with, because it doesn't seem like it's related, like maybe an interrupt set up and an ISR that's affecting X or Y without saving and restoring them?
 

I will read your debugging article with interest. I suspect a connection thing or some form of instability. I removed the connection between the IRQ pins on the 6502 and the VIA and took them both high. I have no interrupt handlers set up but I have to admit I would probably overlook X and Y and their status easily.
As i mentioned in another reply I got the LED to pulse with the delay subroutine only at low clock speed and only for a limited time, at 1MHz not. Taking out the subroutine it worked, so some modest progress. I look forward to slapping my forehead.

Thanks for your help.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 09, 2023 10:13 am 
Offline

Joined: Tue Oct 31, 2023 10:34 am
Posts: 15
Location: Germany
gfoot wrote:
Quote:
It is probably doing something, but not what you expect


You are right, it is doing something. Eliminating the subroutine got it to flash the LED. I suspect a connection problem somewhere but hard to figure out. Thanks for the helpful suggestions. I hope I make it as a detective. I will let you know if I find anything strange.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 09, 2023 10:20 am 
Offline

Joined: Tue Oct 31, 2023 10:34 am
Posts: 15
Location: Germany
Michael wrote:
Quote:
That code seems to be working ok on one of my boards with 1-MHz clock

Thanks, this was encouraging. Following a suggestion I eliminated the subroutine and got the same result as you. Now have to figure out why this happens. Breadboards can be a pain, unlike your nice PCB.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 09, 2023 11:26 am 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 683
Location: Potsdam, DE
In Germany we have Aisler locally; it's not significantly different in price from JLCPCB when you consider taxes and postage. Though I don't feel that the green solder resist has quite the enthusiastic vitality of the Chinese product; the boards look a little pale in comparison :D

Neil


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 09, 2023 3:06 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
Cookie13! wrote:
I got the LED to pulse with the delay subroutine only at low clock speed and only for a limited time
Only for a limited time? You mean it was working and then it stopped? I can't imagine such behavior being caused by a software problem, except maybe in a more complex scenario where interrupts are involved... and that's not the case here. So, I'd be looking for a hardware fault.

Quote:
[...] I suspect a connection problem somewhere but hard to figure out.
It's highly plausible that the trouble originates from poor connections. And if you're using a low-quality breadboard then "figuring it out" -- identifying the problem -- might be an exercise in frustration; do yourself a favor and get a decent breadboard :!: (example: one from Twin Industries)

The other hardware fault worth considering is noise issues, which can result from poor layout (eg: long wires) and/or poor use supply bypass capacitors. Are you willing to share a photo of your project? It's possible that'll quickly lead us to a resolution.

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 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: