OT: Reformatted update on table call problem

I have not found either a simulator or an emulator; only the debug via the use of that debug header monster. The IDE "help" file (like all so-called help files) does not.

Reply to
Robert Baer
Loading thread data ...

AN556, page 3 and I quote: "The user either has to be cautious as to where in a page the Table resides or has to monitor page roll-over and add it to the PCLATH ahead of the computed GOTO." Does not that imply that rollover will not happen unless one diddles PCLATH?

Reply to
Robert Baer

From ASM listing: 00038 ; From AN556 page 3, EXAMPLE 5:

0080 00039 org 0x80 ;code location page 0 0080 3002 00040 movlw HIGH Table 0081 008A 00041 movwf PCLATH 00042 ; movlw ptrlo,F MPASM 5.41 AN556CHK.ASM 10-12-2015 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00043 00044 0082 3020 00045 movlw ptrlo 0083 22FF 00046 call Table 0084 2086 00047 CALL DISPL 00048 ; Does NOT work; see 0x00, 0xFF, 0xFF, 0xFF 0085 2810 00049 GOTO start

00071 ; From AN556 page 3, EXAMPLE 4:

02FF 00072 org 0x02ff ;Table, end of page 2 02FF 080A 00073 Table: MOVF PCLATH,W 0300 2086 00074 CALL DISPL 0301 30A5 00075 MOVLW 0xA5 0302 2086 00076 CALL DISPL 0303 2810 00077 GOTO start 0304 0782 00078 addwf PCL,F 0305 3441 00079 retlw d'65' 0306 3442 00080 retlw d'66' 0307 3443 00081 retlw d'67'
Reply to
Robert Baer

There has to be some kind of cheat WRT PCLATH, otherwise the following would definitely NOT work: ORG 0x100 MOVLW HIGH(TAB1) MOVWF PCLATH ; the program would NOT continue to the ; next line if PCLATH acted on/in next ; instruction cycle... MOVF prtlo,W CALL TAB1 ;--- ORG 0x0700 TAB1: MOVLW HIGH(TAB1_DATA) ADDWF ptrhi,W MOVWF PCLATH MOVLW LOW(TAB1_DATA) ADDWF ptrlo,W BTFSC STATUS,C INCF PCLATH,F MOVWF PCL,F ; --- ORG 0x0800 TAB1_DATA: RETLW ...

Reply to
Robert Baer

You have confused PCH with PCLATH.

The program does continue to the next line because PCLATH is *not* the high part of the program counter. It is a latch that is only copied to the high part of the program counter in special conditions. Those are, a call, goto, or where pcl is the destination of an instruction.

Please read section 4.3 of the datasheet (page 30 DS40044G).

piglet

Reply to
piglet

When they talk about rollover they refer to what happens after the arithmetic to PCL not to the normal incrementing of program counting that ocuurs after each instruction.

Please read section 4.3 of the datasheet (page 30 DS40044G).

piglet

Reply to
piglet

What happens to the return address that was pushed to the stack at 0083, where is it popped off by a return instruction?

Or in other words please tell how instructions at 0304, 0305, 0306, 0307 will get a chance to execute?

Hint: please look at 0303

piglet

Reply to
piglet

I use mplab ide v8.92. Under the the tab "debugger" go to "select tool" then select MPLAB SIM. That is the inbuilt software simulator and you can single step thru your dissassembly listing with F7 key. Use the "view" tab to open additional windows on file, stack, etc etc.

piglet

Reply to
piglet

You can lead a horse to water but you can't make it think!

--
Regards, 
Martin Brown
Reply to
Martin Brown

Thanks.

Reply to
Robert Baer

Still does not explain the AN556 error(s).

Reply to
Robert Baer

Those are placeholders only. Note that,at line 83, the CALL Table does not work (one sees 0x00,

0xFF, 0xFF, 0xFF etc).
Reply to
Robert Baer

This is going to take some learning. Where are the "instructions" for using this beast? ? Run to brake-point would be nice, continue another nice..

I notice that PCH does not exist ("not available").

Thanks.

Reply to
Robert Baer

Here are some tutorials and other information on the IDE and software simulator/debugger. Some may be for older versions but should be fine for the most basic operation:

formatting link
(from

2001)

formatting link
(For MPLABX and C)

formatting link
(IDE 6.6)

formatting link
(from 2008)

formatting link
(2009)

formatting link

formatting link
(MPLABX 2011)

It would be very helpful to study and understand the finer points of the IDE and simulator, and the basic operation of the Microchip devices. PICs are very powerful, especially newer versions, and with such power comes responsibility to know their capabilities and the tools to program them. It is a steep learning curve, but well worth the effort. Otherwise, perhaps it would be good to use the Arduino or BASIC stamp or other simplified platforms.

Paul

Reply to
P E Schoen

Thanks! Fortunately, i had about half of those, so saved download time.

Reply to
Robert Baer

It would also help to know just what you are trying to do, and why you chose the device you are using and why you are programming in assembler. At one point it seemed you were making a sine table, and elsewhere it seemed like an ASCII look-up. For a sine table and similar math functions, it may be better to use an actual sine function, or a table with a few data points and cubic spline* (or similar) interpolation to get good accuracy. There are always trade-offs between code size and complexity, and speed, however.

Here is a link to a sine table implementation:

formatting link

Other resources:

formatting link

Paul

*Here is a simple spline function in C

/***************************************************************************** This spline function returns a floating point y value for the given x_value n is the number of points in the input array

*****************************************************************************/

float spline( float x_val, int n, float *x, float *y )

{ float y_val = 0; float num, den; int i,j;

for (i=0; i

Reply to
P E Schoen

The device was chosen by someone else; i am stuck with it. Use of tables is necessary because the actual waveform(s) will be complex and arbitrary; the sine (triangle and square) waves were for reference.

Reply to
Robert Baer

It seems odd that someone else can make a design decision to use a particular microcontroller and (presumably) hardware design, yet require you to provide the code to make it work.

For arbitrary waveforms, it seems that perhaps a separate EEPROM might be good for storage of the waveform data. It could even be clocked into a D/A converter which is generally much better for waveform generation than PWM, which is the usual method for microcontrollers.

It's a common trap to become focused on a particular methodology to accomplish a given task, when something else might be much more efficient or superior by virtue of various metrics.

Paul

Reply to
P E Schoen

Happens all the time. In the real world, there are often other system (and sometimes political/business) constraints that determine the hardware used.

If the micro is already there, the same thing can be done with the micro, of course.

It's also common to not include all of the constraints when stating a problem.

Reply to
krw

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.