I have a global array.
it needs to be stuffed from pin input.
rather than incrementing that array in the main code I think calling a function would be better.
so since it is a global array I can input constants to define the array element and it changes the array values without returning anything.
include "pins.h" //the pin definitions pin number= name
include "var.h" //global vareable definition
void setup()
{
//initilise the serial usb hardware check to see if a program has the port latter
Serial.begin(9600); // USB is always 12 Mbit/sec
init_pins_direction();
//if serial port has to be started the wait for dtr command might
//have to be commented out and run once.
while (!Serial.dtr()) ; // wait for user to start the serial monitor
Serial.println("This is the teensy++ TI ADS1278 ADC test program.");
int number = 1234;
Serial.println(number); // number (base 10 if 16 or 32 bit)
Serial.println(number, DEC); // number, base 10 (default)
Serial.println(number, HEX); // number, base 16/hexidecimal
Serial.println(number, BIN); // number, base 2/binary
Serial.println(number, BYTE); // number, as a single byte
Serial.send_now(); //transmit buffer imediately
}
void loop()
{
// read the state of the pushbutton value:
DRDY_State = digitalRead(DRDY);
if(DRDY_State==LOW){
clkoutallbytes();
print24arraybytes();
}//end of if DRDY is LOW ... this I hope is fast enough...
//PortB 7 is unconnected!
//two's compliment is the sign number
}//end of main
inline void print24arraybytes(void)
{
//now that the array is filled send the bytes up the usb if working with 64 byte buffer 3 samples 3bytes per channel*8channels=
//24byts per sample 2 = 48 bytes...
**Serial.print(data_Out[0],BYTE);
**Serial.print(data_Out[1],BYTE);
**Serial.print(data_Out[2],BYTE);
**Serial.print(data_Out[3],BYTE);
**Serial.print(data_Out[4],BYTE);
**Serial.print(data_Out[5],BYTE);
**Serial.print(data_Out[6],BYTE);
**Serial.print(data_Out[7],BYTE);
**Serial.print(data_Out[8],BYTE);
**Serial.print(data_Out[9],BYTE);
**Serial.print(data_Out[10],BYTE);
**Serial.print(data_Out[11],BYTE);
**Serial.print(data_Out[12],BYTE);
**Serial.print(data_Out[13],BYTE);
**Serial.print(data_Out[14],BYTE);
**Serial.print(data_Out[15],BYTE);
**Serial.print(data_Out[16],BYTE);
**Serial.print(data_Out[17],BYTE);
**Serial.print(data_Out[18],BYTE);
**Serial.print(data_Out[19],BYTE);
**Serial.print(data_Out[20],BYTE);
**Serial.print(data_Out[21],BYTE);
**Serial.print(data_Out[22],BYTE);
**Serial*.print(data_Out[23],BYTE);
Serial.send_now(); //transmit buffer imediately
}
inline void init_pins_direction(void){
//initilise pins to a defalt state high or low
digitalWrite(ledPin, HIGH); // set the LED OFF it is active low
digitalWrite(SYNC, HIGH); //SYNC is active low init as HIGH
digitalWrite(SCLK, LOW); //SCLK rests low shifts out on falling edge
//initilise the direction of pins or ports
pinMode(ledPin, OUTPUT); // initialize the pin as an output:
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
pinMode(SCLK, OUTPUT); //SCLK comes out the micro into the ADC to clock out data
pinMode(DRDY, INPUT); //DRDY goes into the micro out of the ADC to say when a conversion is done
pinMode(SYNC, OUTPUT); //this is used to syncronise many ADCs
DDRB = 0; //set port b to input //test this using other led outputs...
}
inline void getMSB(void){
asm("nop\n\t"); //delay 1 cycle inline assembly. This is the delay tds "falling edge of #DRDY to rising edge of SCLK to retreve data"
digitalWrite(SCLK, HIGH); // set the SCLK HIGH tMSBPDDRDY FALLING EDGE TO MSB valid weight is taken.
//IF NOT BYTE OP. DO THIS 8 TIMES ... DRDY_State = digitalRead(DRDY);
data_Out[0]=PINB;//DO1 = LSB - DO8 = MSB... check wiring...
}
inline void getbyte(int bytenum){
digitalWrite(SCLK, LOW); // set the SCLK LOW GET NEXT BYTE
asm("nop\n\t"); //delay 1 cycle inline assembly. SCLK falling edge wait for valid data..
data_Out[bytenum]=PINB;
digitalWrite(SCLK, HIGH); // set the SCLK HIGH
asm("nop\n\t"); //delay to ensure valid pulse width
}
inline void clkoutallbytes(void){
//62.5ns per sclk check timing diagrams for ads1278
//1/12MHZ per clk 83ns
//get byte 1
getMSB();
//get byte 2
getbyte(1);
//get byte 3
getbyte(2);
//get byte 4
getbyte(3);
//get byte 5
getbyte(4);
//get byte 6
getbyte(5);
//get byte 7
getbyte(6);
//get byte 8
getbyte(7);
//get byte 9