Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Getting The Program Counter in C

Getting The Program Counter in C

2005-12-01 by Terry Slocum

I'm trying to track down a bug in an existing program. I believe it is 
getting stuck in a loop. Once the error occurs the only way to restore 
communication is to reset the processor. It would help a lot if I could 
locate the place in the code where it is getting stuck. I would like to 
be able to store the Program Counter, Hardware Stack Pointer and Data 
Stack Pointer (Y Register) in EEPROM so I can output them the next time 
the processor boots. The problem is that the code is in C. I am not 
sure how to get a value from a hardware register and store it in a C 
variable. I am using the CodeVisionAVR compiler.  Any ideas?  

Terry

Re: [AVR-Chat] Getting The Program Counter in C

2005-12-04 by James Washer

Did you ever get an answer to this?

Seems to me you want to use either the WDT, or an external interrupt. Exactly what will be in the stack will depend on what compiler/library routines you are using.. but you should be able to determine this by looking some disassembled ISRs. Once you determine the relative stack location in the ISR, you should have no trouble storing (or displaying) the previous PC

 - jim
On Thu, 01 Dec 2005 19:34:55 -0000
"Terry Slocum" <tslocum@pacbell.net> wrote:
Show quoted textHide quoted text
> I'm trying to track down a bug in an existing program. I believe it is 
> getting stuck in a loop. Once the error occurs the only way to restore 
> communication is to reset the processor. It would help a lot if I could 
> locate the place in the code where it is getting stuck. I would like to 
> be able to store the Program Counter, Hardware Stack Pointer and Data 
> Stack Pointer (Y Register) in EEPROM so I can output them the next time 
> the processor boots. The problem is that the code is in C. I am not 
> sure how to get a value from a hardware register and store it in a C 
> variable. I am using the CodeVisionAVR compiler.  Any ideas?  
> 
> Terry
> 
> 
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
>

RE: [AVR-Chat] Getting The Program Counter in C

2005-12-04 by Larry Barello

The only way to get the PC is to interrupt the processor.  The PC will be on
the stack upon entry into the ISR.  WDT will reset the processor and you
will lose your PC. 

The simplest way to debug something like this is a hardware debugger: JTAG
or ICE200 (if it is a really old chip!).  The $30-40 for a clone JTAG
debugger makes it an essential tool.  Something I do a lot is host on a
bigger chip (m128) and use JTAG to get the algorithms working. Then port to
the target chip which with the AVR is no work at all as virtually all chips
are a subset of the bigger chips so 100% compatible code can be written.  At
that point 99% of the code was working so the remaining bit was easily
debugged via churn & burn.

Alternatively you can poke characters to an USART or twiddle bits on an I/O
port to narrow down the location of the hang.  If you have space, formatted
printf's at critical points can illuminate what is going on (e.g. a loop
counter not incrementing, or something like that).

If none of the above is practical, then you can code a trace routine in an
ISR.  A periodic timer would be convinient.  You need to get the stack
pointer into an index register and then access the PC on the stack. You
could get fancy and have a circular buffer in EEPROM so you keep track of
the last 100 samples (and spread the load around) and an input you control
tracing with (0 = trace, 1 = don't trace).  Then unwind the stack and return
as a normal ISR. That way you can "sample" where the code was when it got
hung.

This could be done in C, but would be simpler in assembly:

ISR:
	Sbic	PINx.pin
	Rjmp	YourRegularISR	; control trace with I/O pin
	Push	r24-31
	In	r24, SREG
	Push 	r24
	In	r28, SPL
	In	r28, SPH
	Ld	r24, Y+9	; PCL
	Ld	r25, Y+10	; PCH (check these offsets)
	...
	; do whatever EEPROM stuff you want
	; since you have the stack pointer you could even save
	; that as well as SREG, etc.  If you know the CV stack 
	; layout you might even be able to print a trace of all
	; the calls to the point of hanging, etc.

	Pop	r24
	Out	sreg, r24
	Pop	r31-24
	Rjmp	YourRegularISR
-----------
Larry Barello
www.barello.net


| -----Original Message-----
| From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
| Of James Washer
| Sent: Saturday, December 03, 2005 8:36 PM
| To: AVR-Chat@yahoogroups.com
| Subject: Re: [AVR-Chat] Getting The Program Counter in C
| 
| Did you ever get an answer to this?
| 
| Seems to me you want to use either the WDT, or an external interrupt.
| Exactly what will be in the stack will depend on what compiler/library
| routines you are using.. but you should be able to determine this by
| looking some disassembled ISRs. Once you determine the relative stack
| location in the ISR, you should have no trouble storing (or displaying)
| the previous PC
| 
|  - jim
| On Thu, 01 Dec 2005 19:34:55 -0000
| "Terry Slocum" <tslocum@pacbell.net> wrote:
| 
| > I'm trying to track down a bug in an existing program. I believe it is
| > getting stuck in a loop. Once the error occurs the only way to restore
| > communication is to reset the processor. It would help a lot if I could
| > locate the place in the code where it is getting stuck. I would like to
| > be able to store the Program Counter, Hardware Stack Pointer and Data
| > Stack Pointer (Y Register) in EEPROM so I can output them the next time
| > the processor boots. The problem is that the code is in C. I am not
| > sure how to get a value from a hardware register and store it in a C
| > variable. I am using the CodeVisionAVR compiler.  Any ideas?
| >
| > Terry
| >
| >
| >
| >
| >
| >
| >
| > Yahoo! Groups Links
| >
| >
| >
| >
| >
| >
| 
| 
| 
| 
| Yahoo! Groups Links
| 
| 
| 
| 
|

Re: [AVR-Chat] Getting The Program Counter in C

2005-12-04 by Dave Hylands

HI,

On 12/4/05, Larry Barello <yahoo@barello.net> wrote:
> The only way to get the PC is to interrupt the processor.  The PC will be on
> the stack upon entry into the ISR.  WDT will reset the processor and you
> will lose your PC.

Every time you call a subroutine, the PC is pushed onto the stack.
Therefore you should be able to write a simple assembler function like
this:

GetPC:
    pop r24
    pop r25
    push r25
    push r24
    ret

I haven't tested the above, bbut I think that I got the order right
r24=LSB, r25=MSB

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

Driving Oscilloscope CRT like Memory Mapped Graphic Display

2005-12-05 by Arif YILMAZ

Hello to all Experts,

I would like to refer to your information about oscilloscope CRTs. I
have to use a crt do display waveforms like an oscilloscope but having
really big problem with this sacred device. 
I used already available crt driver circuit with transistors and my
waveform seem very stable and nice when I inspect it on a scope, however
I cant get such stable view when I look into the CRT display I am trying
to drive.  The waveform flickers when I touch CRTs shield, its focus is
lost when I move the waveform vertically etc.  i.e. there are problems
with the physics of the device.
	I generally have focusing and grounding problems and also it is
very sensitive to noise for example,  from a pulse signal generated
somewhere else in the system. 

	Well, I would like to hear your experience on such issues, and I
really would like to know if there is already available chips to drive
such problemmatic device ,
	 and if there is any available chips to drive it like a
monochrome Graphic display? 
And also manuals tutorials on CRTs would be helpful, 

Thank you for your interest in advance...
Arif

Re: [AVR-Chat] Driving Oscilloscope CRT like Memory Mapped Graphic Display

2005-12-05 by Jim Wagner

Hello, Arif -

The very first question is about your CRT. Is it a
raster-scan device (like a monitor or TV) or is it XY (like
a real oscilloscope). I have some experience in this area
as I did some design of oscilloscope circuits at Tektronix,
though many years ago.

Jim


---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Re: [AVR-Chat] Driving Oscilloscope CRT like Memory Mapped Graphic Display

2005-12-06 by Mike

Arir,

To me, without knowing all the details, it sounds like Power Supply issues
as all symptoms can be effected by the power supply. That gives you a commom
factor. At least it's a place to start. Using your trouble shooting O-scope
and voltage meters you should be able to track it down.

1. Focus Voltage -- Does it change when symptom occurs?  ( Power supply
weak?) Meter time here.
2. The pulse generated in the system can be noise in the power supply as
well. Scope the Power supply lines to see, if you see it there you can trace
it back to the source or temprarly filter it out. If it's a new design,
decouping suppresion caps may not have been used or the selection may be
incorrect. The power supply lines is where that sign can sneak into the
whole system.
3. The wave form flickering could be noise on the the signal circuits
induced from the power supply to them. Scope those   power supply lines.
4. Typically when losing focus when moving the displayed wave form from the
center of the CRT , the deflection plates need more power to do that. (ie.
loss of focus if trace is move away from the center of the CRT), I would
again suspect something with the power supply in. If the trace can be moved
back to the center of the CRT and it regains focus, that's a hint.
5. The --- Noise--- you mention, if you have confirmed that the noise is
patternized, what circuits are common to it if you have ruled out that it's
not getting in the power supply. ( Don't forget your harmonics here )

Typically Focus and Anode voltages are Higher voltages in the past were
separate supplies from the circuit supplies. However, today most low
voltages for the circuits are flyback derived, so separating the two is not
as easy.

You stated you suspect Ground issues, this could be, Remember Ground is the
return path for the Power Supply (Which means it is a part of Power Supply.
Solid Grounds are a must for all power supplies. Don't forget there can be
multiple grounding points incorperated into a system, which may not have a
common point.

If a problem wiht your device seems to big to understand, break it down into
smaller pieces that you can understand.

Divide and Conquer.

Good Luck and Regards,
Mike Benoit




----- Original Message -----
From: "Arif YILMAZ" <arif.yilmaz@bilten.metu.edu.tr>
To: <AVR-Chat@yahoogroups.com>
Sent: Monday, December 05, 2005 12:41 AM
Subject: [AVR-Chat] Driving Oscilloscope CRT like Memory Mapped Graphic
Display
Show quoted textHide quoted text
> Hello to all Experts,
>
> I would like to refer to your information about oscilloscope CRTs. I
> have to use a crt do display waveforms like an oscilloscope but having
> really big problem with this sacred device.
> I used already available crt driver circuit with transistors and my
> waveform seem very stable and nice when I inspect it on a scope, however
> I cant get such stable view when I look into the CRT display I am trying
> to drive.  The waveform flickers when I touch CRTs shield, its focus is
> lost when I move the waveform vertically etc.  i.e. there are problems
> with the physics of the device.
> I generally have focusing and grounding problems and also it is
> very sensitive to noise for example,  from a pulse signal generated
> somewhere else in the system.
>
> Well, I would like to hear your experience on such issues, and I
> really would like to know if there is already available chips to drive
> such problemmatic device ,
> and if there is any available chips to drive it like a
> monochrome Graphic display?
> And also manuals tutorials on CRTs would be helpful,
>
> Thank you for your interest in advance...
> Arif
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>

Re: [AVR-Chat] Driving Oscilloscope CRT like Memory Mapped Graphic Display

2005-12-06 by Jim Wagner

Arir -

Here is some more information about CRTs. 

Magnetic susceptability (interferance) is very common with
CRT. Most manufacturers put a metal magnetic shield over
the tube. Often, it is a special metal (one has a trade
mark of "mu-metal", I believe). With home TVs, the color
ones are more critical for external magnetic fields. There
is usually a "degaussing" circuit that demagnetizes the CRT
every time it goes on or off. 

There is a big trade-off between accelerating voltage and
many other things. The spot becomes brighter with higher
voltage. But the beam becomes more "stiff". This means that
it takes a higher deflection voltage (if it is electostatic
deflection).  It is common practice to run the deflection
plates near ground to make connection to circuitry easier.
This means two supplies, however, one for the cathode and
one for the screen. It is common to use high-frequency
oscillators for the high voltage (that is, switching power
in modern terms). Because the voltage is quite high
(5-10Kv), the transformers tend to be difficult to make. 

All of these factors (and many more, including weight and
size) have contributed to the modern trend of using LCD for
oscilloscope displays. 

Jim
---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

RE: [AVR-Chat] Driving Oscilloscope CRT like Memory Mapped Graphic Display

2005-12-07 by Arif YILMAZ

Thank you Mike and Jim, 
I am driving the crt in XY  mode I don't use any raster actually I used
a previously available schematics for the tube,   the power supply may
have problems as you stated, I previously inspected those signals and,
tube is driven with 1400 volts anode-cathode voltage, however there is
about 20 volt ripple on it because it uses typical diode -capacitor
voltage doubler circuit stages to obtain 1400 V from a 170 AC winding of
the transformer. Other parts of the circuit also use 7815 Voltage regs.
Etc. and their output seems very clean when inspected on the scope, , X
and Y deflection amplifiers have transistor stages, and they produce
very stable x and y signals  ie. Horizontal, vertical, 
When I inspect the tube datasheet I see different anode terminals like
A1 A2 A3 , and single cathode terminal, 

By the way, I showed special care to ground loops in the board and still
there may be problems you may be right, also routed its signals with at
least 36 mils width, and 72 mils for ground signals. 
I am now inspecting the board but not very sure if it is going to help, 

Do you think tube pyhsics are so intolerant to 20 V ripples on the
anode voltage?  The flickers when signal is moved upwards are due to
it?, I will   put a high voltage capacitor there...
Show quoted textHide quoted text
-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On
Behalf Of Jim Wagner
Sent: Tuesday, December 06, 2005 9:08 PM
To: AVR-Chat@yahoogroups.com
Subject: Re: [AVR-Chat] Driving Oscilloscope CRT like Memory Mapped
Graphic Display


Arir -

Here is some more information about CRTs. 

Magnetic susceptability (interferance) is very common with
CRT. Most manufacturers put a metal magnetic shield over
the tube. Often, it is a special metal (one has a trade
mark of "mu-metal", I believe). With home TVs, the color
ones are more critical for external magnetic fields. There
is usually a "degaussing" circuit that demagnetizes the CRT every time
it goes on or off. 

There is a big trade-off between accelerating voltage and
many other things. The spot becomes brighter with higher voltage. But
the beam becomes more "stiff". This means that it takes a higher
deflection voltage (if it is electostatic deflection).  It is common
practice to run the deflection plates near ground to make connection to
circuitry easier. This means two supplies, however, one for the cathode
and one for the screen. It is common to use high-frequency oscillators
for the high voltage (that is, switching power in modern terms). Because
the voltage is quite high (5-10Kv), the transformers tend to be
difficult to make. 

All of these factors (and many more, including weight and
size) have contributed to the modern trend of using LCD for oscilloscope
displays. 

Jim
---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------



 
Yahoo! Groups Links

Re: [AVR-Chat] Driving Oscilloscope CRT like Memory Mapped Graphic Display

2005-12-07 by Jim Wagner

Arif -

The tube should be fairly tolerant of ripple on the high
voltage. There is proabably something else going on.

Watch out for your transformer! It can generate a magentic
field that effects the tube.

Jim


On Wed, 7 Dec 2005 11:45:19 +0200
 "Arif YILMAZ" <arif.yilmaz@bilten.metu.edu.tr> wrote:
> Thank you Mike and Jim, 
> I am driving the crt in XY  mode I don't use any raster
> actually I used
> a previously available schematics for the tube,   the
> power supply may
> have problems as you stated, I previously inspected those
> signals and,
> tube is driven with 1400 volts anode-cathode voltage,
> however there is
> about 20 volt ripple on it because it uses typical diode
> -capacitor
> voltage doubler circuit stages to obtain 1400 V from a
> 170 AC winding of
> the transformer. Other parts of the circuit also use 7815
> Voltage regs.
> Etc. and their output seems very clean when inspected on
> the scope, , X
> and Y deflection amplifiers have transistor stages, and
> they produce
> very stable x and y signals  ie. Horizontal, vertical, 
> When I inspect the tube datasheet I see different anode
> terminals like
> A1 A2 A3 , and single cathode terminal, 
> 
> By the way, I showed special care to ground loops in the
> board and still
> there may be problems you may be right, also routed its
> signals with at
> least 36 mils width, and 72 mils for ground signals. 
> I am now inspecting the board but not very sure if it is
> going to help, 
> 
> Do you think tube pyhsics are so intolerant to 20 V
> ripples on the
> anode voltage?  The flickers when signal is moved upwards
> are due to
> it?, I will   put a high voltage capacitor there...
> 
> 
> 
> 
> 
> 
> 
> -----Original Message-----
> From: AVR-Chat@yahoogroups.com
> [mailto:AVR-Chat@yahoogroups.com] On
> Behalf Of Jim Wagner
> Sent: Tuesday, December 06, 2005 9:08 PM
> To: AVR-Chat@yahoogroups.com
> Subject: Re: [AVR-Chat] Driving Oscilloscope CRT like
> Memory Mapped
> Graphic Display
> 
> 
> Arir -
> 
> Here is some more information about CRTs. 
> 
> Magnetic susceptability (interferance) is very common
> with
> CRT. Most manufacturers put a metal magnetic shield over
> the tube. Often, it is a special metal (one has a trade
> mark of "mu-metal", I believe). With home TVs, the color
> ones are more critical for external magnetic fields.
> There
> is usually a "degaussing" circuit that demagnetizes the
> CRT every time
> it goes on or off. 
> 
> There is a big trade-off between accelerating voltage and
> many other things. The spot becomes brighter with higher
> voltage. But
> the beam becomes more "stiff". This means that it takes a
> higher
> deflection voltage (if it is electostatic deflection).
>  It is common
> practice to run the deflection plates near ground to make
> connection to
> circuitry easier. This means two supplies, however, one
> for the cathode
> and one for the screen. It is common to use
> high-frequency oscillators
> for the high voltage (that is, switching power in modern
> terms). Because
> the voltage is quite high (5-10Kv), the transformers tend
> to be
> difficult to make. 
> 
> All of these factors (and many more, including weight and
> size) have contributed to the modern trend of using LCD
> for oscilloscope
> displays. 
> 
> Jim
>
---------------------------------------------------------------
> The Think Different Store
> http://www.thinkdifferentstore.com/
> For All Your Mac Gear
>
---------------------------------------------------------------
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 
> 
> 
> ------------------------ Yahoo! Groups Sponsor
> --------------------~--> 
> Get Bzzzy! (real tools to help you find a job). Welcome
> to the Sweet Life.
> http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/dN_tlB/TM
>
--------------------------------------------------------------------~->
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 

---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.