Example #1
0
void PulsePal::setFixedVoltage(uint8_t channel, float voltage) // JS 1/30/2014
{
    uint8_t voltageByte = 0;
    voltageByte = voltageToByte(voltage);
    uint8_t message1[4] = { 213, 79, channel, voltageByte };
    serial.writeBytes(message1, 4);
}
Example #2
0
void PulsePal::sendCustomPulseTrain(uint8_t ID, uint8_t nPulses, float customPulseTimes[], float customVoltages[]){
    int nMessageBytes = (nPulses * 5) + 7;
    // Convert voltages to bytes
    uint8_t voltageBytes[1000] = { 0 };
    float thisVoltage = 0;
    for (int i = 0; i < nPulses; i++) {
        thisVoltage = customVoltages[i];
        voltageBytes[i] = voltageToByte(thisVoltage);
    }
    // Convert times to bytes
    uint8_t pulseTimeBytes[4000] = { 0 };
    int pos = 0;
    unsigned long pulseTimeMicroseconds;
    for (int i = 0; i < nPulses; i++){
		pulseTimeMicroseconds = (unsigned long)(customPulseTimes[i] * CycleFreq);
        pulseTimeBytes[pos] = (uint8_t)(pulseTimeMicroseconds); pos++;
        pulseTimeBytes[pos] = (uint8_t)(pulseTimeMicroseconds >> 8); pos++;
        pulseTimeBytes[pos] = (uint8_t)(pulseTimeMicroseconds >> 16); pos++;
        pulseTimeBytes[pos] = (uint8_t)(pulseTimeMicroseconds >> 24); pos++;
    }
    uint8_t *messageBytes = new uint8_t[nMessageBytes];
	messageBytes[0] = 213;
    if (ID == 2) {
        messageBytes[1] = 76; // Op code to program custom train 2
    }
    else {
        messageBytes[1] = 75; // Op code to program custom train 1
    }
    messageBytes[2] = 0; // USB packet correction byte
    messageBytes[3] = (uint8_t)(nPulses);
    messageBytes[4] = (uint8_t)(nPulses >> 8);
    messageBytes[5] = (uint8_t)(nPulses >> 16);
    messageBytes[6] = (uint8_t)(nPulses >> 24);
    int timeDataEnd = 7 + (nPulses * 4);
    for (int i = 7; i < timeDataEnd; i++){
        messageBytes[i] = pulseTimeBytes[i - 7];
    }
    for (int i = timeDataEnd; i < nMessageBytes; i++){
        messageBytes[i] = voltageBytes[i - timeDataEnd];
    }
    serial.writeBytes(messageBytes, nMessageBytes);
}
Example #3
0
void PulsePal::setPhase2Voltage(uint8_t channel, float voltage)
{
    program(channel, 10, voltageToByte(voltage));
}
Example #4
0
void PulsePal::syncAllParams() {
    uint8_t messageBytes[168] = { 0 };
	messageBytes[0] = 213;
    messageBytes[1] = 73;
    int pos = 2;
    uint32_t thisTime = 0;
    float thisVoltage = 0;
    uint8_t thisVoltageByte = 0;

    // add time params
    for (int i = 1; i < 5; i++){
		thisTime = (uint32_t)(currentOutputParams[i].phase1Duration * CycleFreq);
        messageBytes[pos] = (uint8_t)(thisTime); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 8); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 16); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 24); pos++;
		thisTime = (uint32_t)(currentOutputParams[i].interPhaseInterval * CycleFreq);
        messageBytes[pos] = (uint8_t)(thisTime); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 8); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 16); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 24); pos++;
		thisTime = (uint32_t)(currentOutputParams[i].phase2Duration * CycleFreq);
        messageBytes[pos] = (uint8_t)(thisTime); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 8); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 16); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 24); pos++;
		thisTime = (uint32_t)(currentOutputParams[i].interPulseInterval * CycleFreq);
        messageBytes[pos] = (uint8_t)(thisTime); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 8); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 16); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 24); pos++;
		thisTime = (uint32_t)(currentOutputParams[i].burstDuration * CycleFreq);
        messageBytes[pos] = (uint8_t)(thisTime); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 8); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 16); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 24); pos++;
		thisTime = (uint32_t)(currentOutputParams[i].interBurstInterval * CycleFreq);
        messageBytes[pos] = (uint8_t)(thisTime); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 8); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 16); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 24); pos++;
		thisTime = (uint32_t)(currentOutputParams[i].pulseTrainDuration * CycleFreq);
        messageBytes[pos] = (uint8_t)(thisTime); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 8); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 16); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 24); pos++;
		thisTime = (uint32_t)(currentOutputParams[i].pulseTrainDelay * CycleFreq);
        messageBytes[pos] = (uint8_t)(thisTime); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 8); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 16); pos++;
        messageBytes[pos] = (uint8_t)(thisTime >> 24); pos++;
    }

    // add single-byte params
    for (int i = 1; i < 5; i++){
        messageBytes[pos] = (uint8_t)currentOutputParams[i].isBiphasic; pos++;
        thisVoltage = PulsePal::currentOutputParams[i].phase1Voltage;
        thisVoltageByte = voltageToByte(thisVoltage);
        messageBytes[pos] = thisVoltageByte; pos++;
        thisVoltage = PulsePal::currentOutputParams[i].phase2Voltage;
        thisVoltageByte = voltageToByte(thisVoltage);
        messageBytes[pos] = thisVoltageByte; pos++;
        messageBytes[pos] = (uint8_t)currentOutputParams[i].customTrainID; pos++;
        messageBytes[pos] = (uint8_t)currentOutputParams[i].customTrainTarget; pos++;
        messageBytes[pos] = (uint8_t)currentOutputParams[i].customTrainLoop; pos++;
		thisVoltage = PulsePal::currentOutputParams[i].restingVoltage;
		thisVoltageByte = voltageToByte(thisVoltage);
		messageBytes[pos] = thisVoltageByte; pos++;
    }

    // add trigger channel 1 links
    for (int i = 1; i < 5; i++){
        messageBytes[pos] = (uint8_t)currentOutputParams[i].linkTriggerChannel1; pos++; 
    }
    // add trigger channel 2 links
    for (int i = 1; i < 5; i++){
        messageBytes[pos] = (uint8_t)currentOutputParams[i].linkTriggerChannel2; pos++;
    }

    // add trigger channel modes
        messageBytes[pos] = (uint8_t)currentInputParams[1].triggerMode; pos++;
        messageBytes[pos] = (uint8_t)currentInputParams[2].triggerMode; pos++;

    serial.writeBytes(messageBytes, 168);
}
Example #5
0
void PulsePal::setRestingVoltage(uint8_t channel, float voltage)
{
	program(channel, 17, voltageToByte(voltage));
	PulsePal::currentOutputParams[channel].restingVoltage = voltage;
}
Example #6
0
void PulsePal::setPhase2Voltage(uint8_t channel, float voltage)
{
    program(channel, 3, voltageToByte(voltage));
    PulsePal::currentOutputParams[channel].phase2Voltage = voltage;
}