#define write8inline(d) { \
PORTD = (GPIOD_PDOR & B00000000) | ((d) & B11111111); \
}
#define read8inline() ( (GPIOD_PDIR & B11111111))
#define setWriteDirInline() { \
pinMode(2, OUTPUT); \
pinMode(14, OUTPUT); \
pinMode(7, OUTPUT); \
pinMode(8, OUTPUT); \
pinMode(6, OUTPUT); \
pinMode(20, OUTPUT); \
pinMode(21, OUTPUT); \
pinMode(5, OUTPUT); }
#define setReadDirInline() { \
pinMode(2, INPUT); \
pinMode(14, INPUT); \
pinMode(7, INPUT); \
pinMode(8, INPUT); \
pinMode(6, INPUT); \
pinMode(20, INPUT); \
pinMode(21, INPUT); \
pinMode(5, INPUT); }
#define write8 write8inline
// to access any byte int or long
#define LOBYTE(x) (*(unsigned char*)&x) // low byte
#define HIBYTE(x) (*(((unsigned char*)&x)+1)) // 2
#define BYTE3(x) (*(((unsigned char*)&x)+2)) // 3
#define BYTE4(x) (*(((unsigned char*)&x)+3)) // 4
const PROGMEM byte tab_sin[256] =
{
0x7E, 0x7B, 0x78, 0x75, 0x72, 0x6F, 0x6C, 0x69, 0x66, 0x63, 0x60, 0x5D, 0x5A, 0x57, 0x54, 0x51,
0x4E, 0x4B, 0x48, 0x45, 0x43, 0x40, 0x3D, 0x3B, 0x38, 0x35, 0x33, 0x30, 0x2E, 0x2C, 0x29, 0x27,
0x25, 0x23, 0x20, 0x1E, 0x1C, 0x1A, 0x18, 0x17, 0x15, 0x13, 0x12, 0x10, 0x0E, 0x0D, 0x0C, 0x0A,
0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x03, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x10, 0x12, 0x13, 0x15, 0x17, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x23,
0x25, 0x27, 0x29, 0x2C, 0x2E, 0x30, 0x33, 0x35, 0x38, 0x3B, 0x3D, 0x40, 0x43, 0x45, 0x48, 0x4B,
0x4E, 0x51, 0x54, 0x57, 0x5A, 0x5D, 0x60, 0x63, 0x66, 0x69, 0x6C, 0x6F, 0x72, 0x75, 0x78, 0x7B,
0x7E, 0x82, 0x85, 0x88, 0x8B, 0x8E, 0x91, 0x94, 0x97, 0x9A, 0x9D, 0xA0, 0xA3, 0xA6, 0xA9, 0xAC,
0xAF, 0xB2, 0xB5, 0xB8, 0xBA, 0xBD, 0xC0, 0xC2, 0xC5, 0xC8, 0xCA, 0xCD, 0xCF, 0xD1, 0xD4, 0xD6,
0xD8, 0xDA, 0xDD, 0xDF, 0xE1, 0xE3, 0xE5, 0xE6, 0xE8, 0xEA, 0xEB, 0xED, 0xEF, 0xF0, 0xF1, 0xF3,
0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFA, 0xFB, 0xFC, 0xFC, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD,
0xFE, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFC, 0xFC, 0xFB, 0xFA, 0xFA, 0xF9, 0xF8, 0xF7, 0xF6, 0xF5,
0xF4, 0xF3, 0xF1, 0xF0, 0xEF, 0xED, 0xEB, 0xEA, 0xE8, 0xE6, 0xE5, 0xE3, 0xE1, 0xDF, 0xDD, 0xDA,
0xD8, 0xD6, 0xD4, 0xD1, 0xCF, 0xCD, 0xCA, 0xC8, 0xC5, 0xC2, 0xC0, 0xBD, 0xBA, 0xB8, 0xB5, 0xB2,
0xAF, 0xAC, 0xA9, 0xA6, 0xA3, 0xA0, 0x9D, 0x9A, 0x97, 0x94, 0x91, 0x8E, 0x8B, 0x88, 0x85, 0x82
};
#define clocks 15 //15 pin Teensy3.2 - PORTC0 - signal clock for byte readiness
#define frame 16 //16 pin Teensy3.2 - PORTB0 - start of frame
#define stop_rec 17 //17 pin Teensy3.2 - PORTB1 - finish the recording and close the file
#define led 13
uint32_t max_byte=0;//The device should not work more than 5 minutes. During this time 76800000 bytes will be stored
uint8_t pointer0sin;//does nothing, for the same synchronization length
uint8_t pointer1sin=0;//0 degres;
uint8_t pointer2sin=32;//45 degres;
uint8_t pointer3sin=64;//90
uint8_t pointer4sin=128;//180
uint8_t my9_byte=0;// 9 byte - 8 bit saw
uint8_t my10_byte=0;// 10 byte - status bits
#define myDelay 3
void setup()
{
pinMode(led, OUTPUT);
pinMode(clocks, OUTPUT);
pinMode(frame, OUTPUT);
pinMode(stop_rec, OUTPUT);
pinMode(2, OUTPUT);//D0
pinMode(14, OUTPUT); //D1
pinMode(7, OUTPUT);//D2
pinMode(8, OUTPUT);//D3
pinMode(6, OUTPUT);//D4
pinMode(20, OUTPUT);//D5
pinMode(21, OUTPUT);//D6
pinMode(5, OUTPUT); //D7
}
void loop()
{
while(1)
{
//Sine wave 1
//high byte write
GPIOD_PDOR=tab_sin[pointer1sin];// high byte of value
digitalWriteFast(frame, HIGH);// beginning of frame
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
pointer0sin++;//does nothing, for the same synchronization length
//low byte write
GPIOD_PDOR=tab_sin[pointer1sin];// high byte of value
digitalWriteFast(frame, LOW);// within a frame
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
pointer1sin++;
//Sine wave 2
//high byte write
GPIOD_PDOR=tab_sin[pointer2sin];//GPIOD_PDOR=0;// high byte of value
digitalWriteFast(frame, LOW);// if not start frame this bit =0
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
pointer0sin++;//does nothing, for the same synchronization length
//low byte write
GPIOD_PDOR=tab_sin[pointer2sin];// low byte of value
digitalWriteFast(frame, LOW);// within a frame
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
pointer2sin++;
//Sine wave 3
//high byte write
GPIOD_PDOR=tab_sin[pointer3sin];//GPIOD_PDOR=0;// high byte of value
digitalWriteFast(frame, LOW);// if not start frame this bit =0
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
pointer0sin++;//does nothing, for the same synchronization length
//low byte write
GPIOD_PDOR=tab_sin[pointer3sin];// high byte of value
digitalWriteFast(frame, LOW);// within a frame
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
pointer3sin++;
//Sine wave 4
//high byte write
GPIOD_PDOR=tab_sin[pointer4sin];// GPIOD_PDOR=0;// high byte of value
digitalWriteFast(frame, LOW);// if not start frame this bit =0
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
pointer0sin++;//does nothing, for the same synchronization length
//low byte write
GPIOD_PDOR=tab_sin[pointer4sin];// high byte of value
digitalWriteFast(frame, LOW);// within a frame
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
pointer4sin++;
//9 and 10 byte
//9 byte write
GPIOD_PDOR=my9_byte;// 9 byte
my9_byte++;
digitalWriteFast(frame, LOW);// if not start frame this bit =0
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
//10 byte write
my10_byte =0;
if(max_byte >= 7680000)//76800000 byts / 10byte per frame=7680000 frame
{
digitalWriteFast(led, HIGH);//
digitalWriteFast(stop_rec, HIGH);//
my10_byte =1<<4;
}
else
{
digitalWriteFast(led, LOW);//
digitalWriteFast(stop_rec, LOW);//
}
max_byte++;
GPIOD_PDOR=my10_byte;// high byte of value
digitalWriteFast(frame, LOW);// within a frame
digitalWriteFast(clocks, HIGH);// synchronization
delayMicroseconds(myDelay);
digitalWriteFast(clocks, LOW);// synchronization
}
}