Skip to content

Commit

Permalink
weird ring mod shit dude kinda rad, but try and sync a2d to t2 timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijay Natarajan committed Oct 12, 2017
1 parent 1e10fd1 commit 542163f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 61 deletions.
12 changes: 7 additions & 5 deletions dspic/start.X/include/proj.h
@@ -1,20 +1,22 @@
//LIMIT 16 DONT FUCK UP //LIMIT 16 DONT FUCK UP
#define NUMoBUF(a) ADCON2 |= ((a-1)<<2) #define NUMoBUF(a) ADCON2 |= ((a-1)<<2)
#define NoB 8 //ADC BUFFER #define NoB 1//ADC BUFFER
#define NoO 64//IN/OUT DATA BUFFER #define NoO 120//IN/OUT DATA BUFFER


extern void W2XS(int, volatile int **); extern void W2XS(int, volatile int **);
extern int RFXS(volatile int **); extern int RFXS(volatile int **);
extern void CLYS(volatile int **); extern void CLYS(volatile int **);


extern int modflag;

void inita2d(void); void inita2d(void);
void initPWMdac(void); void initPWMdac(void);
void clearIO(void); void clearIO(void);


void initModBuff(volatile int *,volatile int *,int,int); void initModBuff(volatile int *,volatile int *,int,int);
void setXMOD(int); void setXMOD(int);
void clearBuff(volatile int *); void clearBuff(volatile int **);
void wbyteBuff(int,volatile int *); void wbyteBuff(int,volatile int **);
int rbyteBuff(volatile int *); int rbyteBuff(volatile int **);




54 changes: 26 additions & 28 deletions dspic/start.X/main.c
Expand Up @@ -6,7 +6,7 @@
*/ */


#include "xc.h" #include "xc.h"
#include "proj.h" #include "include/proj.h"


// DSPIC30F3014 Configuration Bit Settings // DSPIC30F3014 Configuration Bit Settings
// 'C' source line config statements // 'C' source line config statements
Expand Down Expand Up @@ -35,53 +35,51 @@
#define Y_B 0x0C00 #define Y_B 0x0C00


#define DEL 32//<NoO #define DEL 32//<NoO
#define GAIN (1/2) #define GAIN (1/4)
#define FDG (1/2) #define FBG (1/4)
// //


volatile int __attribute__((address(0x0800))) * x = (volatile int *) X_B; volatile int __attribute__((address(0x0900))) * x = (volatile int *) X_B;
volatile int __attribute__((address(0x0802))) * xo = (volatile int *) X_B; volatile int __attribute__((address(0x0902))) * xo = (volatile int *) X_B;
volatile int __attribute__((address(0x0804))) * f = (volatile int *) FDB; volatile int __attribute__((address(0x0904))) * f = (volatile int *) FDB;
volatile int __attribute__((address(0x0806))) * fo = (volatile int *) FDB; volatile int __attribute__((address(0x0906))) * fo = (volatile int *) FDB;
volatile int __attribute__((address(0x0808))) * y = (volatile int *) Y_B; volatile int __attribute__((address(0x0908))) * y = (volatile int *) Y_B;
volatile int __attribute__((address(0x080A))) * yo = (volatile int *) Y_B; volatile int __attribute__((address(0x090A))) * yo = (volatile int *) Y_B;

volatile int currOut = 0;
void __attribute__((interrupt,auto_psv))_T2Interrupt (void) { void __attribute__((interrupt,auto_psv))_T2Interrupt (void) {
OC2RS = rbyteBuff(yo); OC2RS = currOut;
IFS0 &= 0xFFBF; IFS0 &= 0xFFBF;
} }


void __attribute__((interrupt,auto_psv))_ADCInterrupt (void) { void __attribute__((interrupt,auto_psv))_ADCInterrupt (void) {
int temp=0; int temp=0;
volatile int lastModB; if(modflag == 0) {
while(!(ADCON1&&0x0001)); while(!(ADCON1&&0x0001));
lastModB = XMODSRT; setXMOD(X_B);
setXMOD(X_B); for(int i=0;i<NoB; i++) {
for(int i=0;i<NoB; i++) { temp = *((&ADCBUF0)+i) >> 4;
temp = *((&ADCBUF0)+i) >> 4; W2XS(temp,&x);
W2XS(temp,&x); }
} }
setXMOD(lastModB);
IFS0 &= 0xF7FF; IFS0 &= 0xF7FF;
} }




int main(void) { int main(void) {
int currIn,currFeed,currOut = 0; int currIn,currFeed = 0;
clearIO(); clearIO();
initModBuff(x,y,10,11); initModBuff(x,y,10,11);
clearBuff(&f);
f = f + DEL; f = f + DEL;
clearBuff(f);
inita2d(); inita2d();
initPWMdac(); initPWMdac();


while (1) { while (1) {
currIn = rbyteBuff(xo); currIn = rbyteBuff(&xo);
currFeed = rbyteBuff(fo); currFeed = rbyteBuff(&fo);
currOut = currIn + GAIN*currFeed; currOut = currIn + GAIN*currFeed;
currFeed = currIn + FBG *currFeed; currFeed = currIn + FBG *currFeed;
wbyteBuff(currOut,y); wbyteBuff(currFeed,&f);
wbyteBuff(currFeed,f);
} }
return 0; return 0;
} }
2 changes: 1 addition & 1 deletion dspic/start.X/src/init.c
@@ -1,5 +1,5 @@
#include "xc.h" #include "xc.h"
#include "proj.h" #include "../include/proj.h"


void clearIO(void) { void clearIO(void) {
//set all i/o to digital //set all i/o to digital
Expand Down
6 changes: 3 additions & 3 deletions dspic/start.X/src/modbuf.s
@@ -1,18 +1,18 @@
.global _W2XS, _RFXS, _CLYS .global _W2XS, _RFXS, _CLYS
_W2XS: //right to x space _W2XS: #right to x space
mov.w [w1], w10 mov.w [w1], w10
mov.w w0, [w10++] mov.w w0, [w10++]
mov.w w10, [w1] mov.w w10, [w1]
return return


_RFXS: //read from x space _RFXS: #read from x space
mov.w w0, w1 mov.w w0, w1
mov.w [w1], w10 mov.w [w1], w10
mov.w [w10++], w0 mov.w [w10++], w0
mov.w w10, [w1] mov.w w10, [w1]
return return


_CLYS: //clear y space _CLYS: #clear y space
mov.w [w0], w11 mov.w [w0], w11
clr [w11++] clr [w11++]
mov.w w11, [w0] mov.w w11, [w0]
Expand Down
48 changes: 24 additions & 24 deletions dspic/start.X/src/modulo.c
@@ -1,15 +1,17 @@
#include "xc.h" #include "xc.h"
#include "proj.h" #include "../include/proj.h"

int __attribute__((address(0x090C))) modflag = 0;
void initModBuff(volatile int * xi, volatile int * yi, int RegX, int RegY) { void initModBuff(volatile int * xi, volatile int * yi, int RegX, int RegY) {
int mask = 0xC000 int mask = 0xC000;
mask |= RegX; mask |= RegX;
mask |= RegY<<4; mask |= RegY<<4;


XMODSRT = (int) xi; XMODSRT = (int) xi;
XMODEND = ((int) xi)+(NoO*2)-1; XMODEND = ((int) xi)+(NoO*2)-1;
YMODSRT = (int) yi; YMODSRT = (int) yi;
YMODEND = ((int) yi)+(NoO*2)-1; YMODEND = ((int) yi)+(NoO*2)-1;
MODCON = MASK; MODCON = mask;
asm ("nop"); asm ("nop");


for(int i=0; i<NoO; i++) { for(int i=0; i<NoO; i++) {
Expand All @@ -18,28 +20,26 @@ void initModBuff(volatile int * xi, volatile int * yi, int RegX, int RegY) {
} }
} }
void setXMOD(int buff) { void setXMOD(int buff) {
XMODSRT = buff; XMODSRT = (buff&0xF00);
XMODEND = buff + (NoO*2)-1; XMODEND = (buff&0xF00) + (NoO*2)-1;
asm ("nop"); asm ("nop");
} }
void clearBuff(volatile int * buff) { void clearBuff(volatile int ** buff) {
setXMOD((int) buff); setXMOD((int) *buff);
for(int i=0; i<NoO;i++) for(int i=0; i<NoO;i++)
W2XS(0,&buff); W2XS(0,buff);
} }
void wbyteBuff(int val, volatile int * buff) { void wbyteBuff(int val, volatile int ** buff) {
volatile int lastModB; modflag = 1;
lastModB = XMODSRT; setXMOD((int) *buff);
setXMOD((int) buff); W2XS(val,buff);
W2XS(val,&buff); modflag = 0;
setXMOD(lastModB);
} }
int rbyteBuff(volatile int * buff) { int rbyteBuff(volatile int ** buff) {
volatile int lastModB; int temp;
int temp; modflag = 1;
lastModB = XMODSRT; setXMOD((int) *buff);
setXMOD((int) buff); temp = RFXS(buff);
temp = RFXS(&buff); modflag = 0;
setXMOD(lastModB); return temp;
return temp;
} }

0 comments on commit 542163f

Please sign in to comment.