Permalink
Browse files

weird ring mod shit dude kinda rad, but try and sync a2d to t2 timer

  • Loading branch information...
santoshalper committed Oct 12, 2017
1 parent 1e10fd1 commit 542163fc15d2cacf7e00e35b6758cae367a24b11
Showing with 61 additions and 61 deletions.
  1. +7 −5 dspic/start.X/include/proj.h
  2. +26 −28 dspic/start.X/main.c
  3. +1 −1 dspic/start.X/src/init.c
  4. +3 −3 dspic/start.X/src/modbuf.s
  5. +24 −24 dspic/start.X/src/modulo.c
@@ -1,20 +1,22 @@
//LIMIT 16 DONT FUCK UP
#define NUMoBUF(a) ADCON2 |= ((a-1)<<2)
#define NoB 8 //ADC BUFFER
#define NoO 64//IN/OUT DATA BUFFER
#define NoB 1//ADC BUFFER
#define NoO 120//IN/OUT DATA BUFFER
extern void W2XS(int, volatile int **);
extern int RFXS(volatile int **);
extern void CLYS(volatile int **);
extern int modflag;
void inita2d(void);
void initPWMdac(void);
void clearIO(void);
void initModBuff(volatile int *,volatile int *,int,int);
void setXMOD(int);
void clearBuff(volatile int *);
void wbyteBuff(int,volatile int *);
int rbyteBuff(volatile int *);
void clearBuff(volatile int **);
void wbyteBuff(int,volatile int **);
int rbyteBuff(volatile int **);
View
@@ -6,7 +6,7 @@
*/
#include "xc.h"
#include "proj.h"
#include "include/proj.h"
// DSPIC30F3014 Configuration Bit Settings
// 'C' source line config statements
@@ -35,53 +35,51 @@
#define Y_B 0x0C00
#define DEL 32//<NoO
#define GAIN (1/2)
#define FDG (1/2)
#define GAIN (1/4)
#define FBG (1/4)
//
volatile int __attribute__((address(0x0800))) * x = (volatile int *) X_B;
volatile int __attribute__((address(0x0802))) * xo = (volatile int *) X_B;
volatile int __attribute__((address(0x0804))) * f = (volatile int *) FDB;
volatile int __attribute__((address(0x0806))) * fo = (volatile int *) FDB;
volatile int __attribute__((address(0x0808))) * y = (volatile int *) Y_B;
volatile int __attribute__((address(0x080A))) * yo = (volatile int *) Y_B;
volatile int __attribute__((address(0x0900))) * x = (volatile int *) X_B;
volatile int __attribute__((address(0x0902))) * xo = (volatile int *) X_B;
volatile int __attribute__((address(0x0904))) * f = (volatile int *) FDB;
volatile int __attribute__((address(0x0906))) * fo = (volatile int *) FDB;
volatile int __attribute__((address(0x0908))) * y = (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) {
OC2RS = rbyteBuff(yo);
IFS0 &= 0xFFBF;
OC2RS = currOut;
IFS0 &= 0xFFBF;
}
void __attribute__((interrupt,auto_psv))_ADCInterrupt (void) {
int temp=0;
volatile int lastModB;
while(!(ADCON1&&0x0001));
lastModB = XMODSRT;
setXMOD(X_B);
for(int i=0;i<NoB; i++) {
temp = *((&ADCBUF0)+i) >> 4;
W2XS(temp,&x);
}
setXMOD(lastModB);
if(modflag == 0) {
while(!(ADCON1&&0x0001));
setXMOD(X_B);
for(int i=0;i<NoB; i++) {
temp = *((&ADCBUF0)+i) >> 4;
W2XS(temp,&x);
}
}
IFS0 &= 0xF7FF;
}
int main(void) {
int currIn,currFeed,currOut = 0;
int currIn,currFeed = 0;
clearIO();
initModBuff(x,y,10,11);
initModBuff(x,y,10,11);
clearBuff(&f);
f = f + DEL;
clearBuff(f);
inita2d();
initPWMdac();
while (1) {
currIn = rbyteBuff(xo);
currFeed = rbyteBuff(fo);
currIn = rbyteBuff(&xo);
currFeed = rbyteBuff(&fo);
currOut = currIn + GAIN*currFeed;
currFeed = currIn + FBG *currFeed;
wbyteBuff(currOut,y);
wbyteBuff(currFeed,f);
wbyteBuff(currFeed,&f);
}
return 0;
}
View
@@ -1,5 +1,5 @@
#include "xc.h"
#include "proj.h"
#include "../include/proj.h"
void clearIO(void) {
//set all i/o to digital
@@ -1,18 +1,18 @@
.global _W2XS, _RFXS, _CLYS
_W2XS: //right to x space
_W2XS: #right to x space
mov.w [w1], w10
mov.w w0, [w10++]
mov.w w10, [w1]
return
_RFXS: //read from x space
_RFXS: #read from x space
mov.w w0, w1
mov.w [w1], w10
mov.w [w10++], w0
mov.w w10, [w1]
return
_CLYS: //clear y space
_CLYS: #clear y space
mov.w [w0], w11
clr [w11++]
mov.w w11, [w0]
View
@@ -1,15 +1,17 @@
#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) {
int mask = 0xC000
int mask = 0xC000;
mask |= RegX;
mask |= RegY<<4;
XMODSRT = (int) xi;
XMODEND = ((int) xi)+(NoO*2)-1;
YMODSRT = (int) yi;
YMODEND = ((int) yi)+(NoO*2)-1;
MODCON = MASK;
MODCON = mask;
asm ("nop");
for(int i=0; i<NoO; i++) {
@@ -18,28 +20,26 @@ void initModBuff(volatile int * xi, volatile int * yi, int RegX, int RegY) {
}
}
void setXMOD(int buff) {
XMODSRT = buff;
XMODEND = buff + (NoO*2)-1;
asm ("nop");
XMODSRT = (buff&0xF00);
XMODEND = (buff&0xF00) + (NoO*2)-1;
asm ("nop");
}
void clearBuff(volatile int * buff) {
setXMOD((int) buff);
for(int i=0; i<NoO;i++)
W2XS(0,&buff);
void clearBuff(volatile int ** buff) {
setXMOD((int) *buff);
for(int i=0; i<NoO;i++)
W2XS(0,buff);
}
void wbyteBuff(int val, volatile int * buff) {
volatile int lastModB;
lastModB = XMODSRT;
setXMOD((int) buff);
W2XS(val,&buff);
setXMOD(lastModB);
void wbyteBuff(int val, volatile int ** buff) {
modflag = 1;
setXMOD((int) *buff);
W2XS(val,buff);
modflag = 0;
}
int rbyteBuff(volatile int * buff) {
volatile int lastModB;
int temp;
lastModB = XMODSRT;
setXMOD((int) buff);
temp = RFXS(&buff);
setXMOD(lastModB);
return temp;
int rbyteBuff(volatile int ** buff) {
int temp;
modflag = 1;
setXMOD((int) *buff);
temp = RFXS(buff);
modflag = 0;
return temp;
}

0 comments on commit 542163f

Please sign in to comment.