I am attempting to program N2HET to output a pulse script. The script will be a sequence of 80 bits of on or off. Note that the odd numbered bits are always zeros and they are not shown in the scripts below. There will be four scripts. The default case is an idle state where no script is required to be sent. The application will need to send NHET its desired action.
Script 1:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1
Script 2:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1
Script 3:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 1 1
Script 2:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1
If I were to write this in C I might write something like:
typedef enum SEND_PULSE_SCRIPT
{
SEND_PULSE_SCRIPT_NONE=0,
SEND_PULSE_SCRIPT_1,
SEND_PULSE_SCRIPT_2,
SEND_PULSE_SCRIPT_3,
SEND_PULSE_SCRIPT_4
} SEND_PULSE_SCRIPT_t;
static SEND_PULSE_SCRIPT_t pulse_script = SEND_PULSE_SCRIPT_NONE;
static int nCounter = 0;
void NHET_Loop(void)
{
if (pulse_script == SEND_PULSE_SCRIPT_NONE)
{
return;
}
// odd numbered counts are always zeros
if (nCounter %2 == 1) gioSetBit(hetPORT1, 18, 0);
// preamble
else if (nCounter <= 48) gioSetBit(hetPORT1, 18, 0);
else if (nCounter == 50) gioSetBit(hetPORT1, 18, 1);
else if (nCounter == 52) gioSetBit(hetPORT1, 18, 1);
else if (nCounter == 54) gioSetBit(hetPORT1, 18, 0);
// address
else if (nCounter == 56 || nCounter == 58 || nCounter == 60)
{
if (pulse_script == SEND_PULSE_SCRIPT_1 || pulse_script == SEND_PULSE_SCRIPT_2 )
{
gioSetBit(hetPORT1, 18, 0);
}
else // pulse_script == SEND_PULSE_SCRIPT_3 || pulse_script == SEND_PULSE_SCRIPT_4
{
gioSetBit(hetPORT1, 18, 1);
}
}
// command
else if (nCounter == 62) gioSetBit(hetPORT1, 18, 0);
else if (nCounter == 64) gioSetBit(hetPORT1, 18, 0);
else if (nCounter == 66)
{
if (pulse_script == SEND_PULSE_SCRIPT_1 || pulse_script == SEND_PULSE_SCRIPT_3 )
{
gioSetBit(hetPORT1, 18, 1);
}
else // pulse_script == SEND_PULSE_SCRIPT_2 || pulse_script == SEND_PULSE_SCRIPT_4
{
gioSetBit(hetPORT1, 18, 0);
}
}
else if (nCounter == 68) gioSetBit(hetPORT1, 18, 1);
// end
else if (nCounter == 70) gioSetBit(hetPORT1, 18, 1);
else if (nCounter == 72) gioSetBit(hetPORT1, 18, 1);
else if (nCounter == 74) gioSetBit(hetPORT1, 18, 1);
else if (nCounter == 76) gioSetBit(hetPORT1, 18, 1);
else if (nCounter == 78) gioSetBit(hetPORT1, 18, 1);
if (nCounter >= 80)
{
// script done, reinitialize for next message
gioSetBit(hetPORT1, 18, 1);
pulse_script = SEND_PULSE_SCRIPT_NONE;
nCounter = 0;
}
else
{
nCounter++;
}
}
void SetPulseScript(SEND_PULSE_SCRIPT_t script)
{
pulse_script = script;
}
SEND_PULSE_SCRIPT_t GetPulseScript(void)
{
return pulse_script;
}
How would I write this in HET instructions?
Thanks for your assistance!
ken