|
|
View previous topic :: View next topic |
Author |
Message |
Malik_Pakistan
Joined: 18 Mar 2010 Posts: 3
|
Problem in making circular buffer |
Posted: Thu May 05, 2011 12:17 am |
|
|
I have written the following code to implement the circular buffer ,
code is working for the X-data space fine ,
but
for the Y-data space the same code does not work
Code: | #include <30F4013.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES WPSB16 //Watch Dog Timer PreScalar B 1:16
#FUSES WPSA512 //Watch Dog Timer PreScalar A 1:512
#FUSES PUT64 //Power On Reset Timer value 64ms
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORRES
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP
#use delay(clock=20000000)
#word CORCON = getenv("SFR:CORCON")
#word MODCON = getenv("SFR:MODCON")
#word XMODSRT = getenv("SFR:XMODSRT")
#word XMODEND = getenv("SFR:XMODEND")
#word YMODSRT = getenv("SFR:YMODSRT")
#word YMODEND = getenv("SFR:YMODEND")
signed int16 Circular_Buf[200];
#locate Circular_buf = 0xC00
signed int16 Cir[70];
#locate Cir = 0x800
struct
{
int XWM:4;
int YWM:4;
int BWM:4;
int Reserved:2;
int YMODEN:1;
int XMODEN:1;
}MODCONbits;
#locate MODCONbits = getenv("SFR:MODCON")
void main(void)
{
int i;
for (i=0;i<=40;i++)
{
Circular_buf[i]=i;
cir[i]=(i+23);
}
// setting for Y-data space , W1 is used as the pointer for circular buffer
MODCONbits.XMODEN=0; // X AGU modulus addressing enabled
MODCONbits.YMODEN=1; // Y AGU modulus addressing enabled
MODCONbits.BWM=15; // Disable bit-reveresed addressing
MODCONbits.XWM=15; // Use register W8
MODCONbits.YWM=1; //
// here I shall make a circular buffer in Y-data space , w1 will be a pointer
// i shall move the ciruclar buffer value to W0 register and
// shall view it on Mplab simulator , does not work
#asm
MOV #0xC00,W0
MOV W0,YMODSRT ;set modulo start address
MOV #0xC24,W0
MOV W0,YMODEND ;set modulo end address
MOV #0xC00,W1
NOP
DO #49,FILL ;fill the 50 buffer locations
FILL:
MOV [W1++],W0
#endasm
// setting for X-data space , W2 is used as the pointer for circular buffer
MODCONbits.XMODEN=1; // X AGU modulus addressing enabled
MODCONbits.YMODEN=0; // Y AGU modulus addressing enabled
MODCONbits.BWM=15; // Disable bit-reveresed addressing
MODCONbits.XWM=2; // Use register W8
MODCONbits.YWM=15; // Use register W9
// here I shall make a circular buffer in X-data space , w2 will be a pointer
// i shall move the ciruclar buffer value to W0 register and
// shall view it on Mplab simulator , work properly
#asm
MOV #0x800,W0
MOV W0,XMODSRT ;set modulo start address
MOV #0x824,W0
MOV W0,XMODEND ;set modulo end address
MOV #0x0000,W0 ;W0 holds buffer fill value
MOV #0x800,W2 ;point W1 to buffer
DO #49,FIlLL ;fill the 50 buffer locations
FIlLL:
//MOV W0,[W1++] ;fill the next location
MOV [W2++], W0 ;fill the next location
#endasm
} |
i write the data in the two location
1) y-data space
2) x data space
when i implement the code for the x-data space the pointer automatically set to the initial value after the last value.
but in case of Y-data space it does not do so
I am checking the output on Mplab Simulator |
|
|
Malik_Pakistan
Joined: 18 Mar 2010 Posts: 3
|
|
Posted: Thu May 05, 2011 12:27 am |
|
|
can some one help me where I am making mistake ?? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed May 11, 2011 4:00 pm |
|
|
mistake one:
using Assembler inline ??
i see this
signed int16 Circular_Buf[200];
IE: 400 bytes of space in the buffer
but then you INIT (?)
with an 8 bit integer in the first 40 bytes
even tho you declared a signed int16 for the buffer space (?)
then
its just an inscrutable MESS of ridiculous assembler insert
and NO Modulo wrap code ever seen
WHY ????? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed May 11, 2011 5:16 pm |
|
|
As much as I enjoy cutting code in assembler for the past 25 years, WHY don't you just use and modify the circular buffer routines that CCS supplies in the example(s) in the examples folder?
You could have this done in less than an hour AND all in C code! |
|
|
|
|
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 vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|