Page 15 of 17

Re: Hacking cartridge HP 84/85

Posted: Thu Oct 03, 2019 6:14 pm
by dragonator
40 nanoseconds for a pin write is pretty fast. I can imagine it being too slow for you, but it is a good reference for me.

For the port you will need to puzzle a little in the core.h: https://github.com/PaulStoffregen/cores ... ore_pins.h

Teensy 4.0 is __IMXRT1062__. This is handy to know since some block only apply to this

Moving from the top

CORE_PIN0_BIT :is which bit of a port is which pin. In this case it is said to be 3 (the 3rd bit).

CORE_PIN0_BITMASK (1<<(CORE_PIN0_BIT)) :creates the actual number which is used to write the port.

CORE_PIN0_PORTSET :determines to which port this is written. GPIO6_DR_SET in this case, port 6

Then there is a whole lot of information that is not relevant. It all applies to the __IMXRT1052__. Move until "#endif // __IMXRT1052__"

A lot further down below there is what digitalWrite(0, 1); is translated to:
CORE_PIN0_PORTSET = CORE_PIN0_BITMASK;, which becomes GPIO6_DR_SET = 1<<3
digitalWrite(0, 0); is translated to:
CORE_PIN0_PORTCLEAR = CORE_PIN0_BITMASK;, which becomes GPIO6_DR_CLEAR = 1<<3

Now these functions can only set pins that are 1 in the mask to high (GPIO_DR_SET) or low (GPIO_DR_CLEAR).

A direct write to the port should be GPIO6_DR, followed by the bits that need to be high and low. GPIO6 = 8; should set GPIO6 pin 3 (which was 0) to high, and GPIO6 = 0; should make all pins 0. However this also writes ALL pins on the port to 0, which is bad. The code to just write pin 0 should be:

Code: Select all

byte pinTable[] = {0,3,4,5,6,7,8,9};
void setup() {
for(int i=0; i<8; i++) {
  pinMode(pinTable[i],OUTPUT); 
  }
}

void loop() {
 GPIO6_DR = GPIO6_DR | 8;
 GPIO6_DR = GPIO6_DR & ~8; //the ~ inverts the 1's and 0's.
}
note that only pin 0 should become 1 and 0 really fast. Every other pin does nothing at the moment. That is because actually figuring out which pin does what would take over an hour with excel, mapping out each pin.

Looking at the values though I am afraid that there are no full ports broken out on the Teensy 4.0

Re: Hacking cartridge HP 84/85

Posted: Sat Oct 05, 2019 6:52 pm
by MAsic12345
dragonator wrote:
Thu Oct 03, 2019 6:14 pm

CORE_PIN0_BIT :is which bit of a port is which pin. In this case it is said to be 3 (the 3rd bit).

CORE_PIN0_BITMASK (1<<(CORE_PIN0_BIT)) :creates the actual number which is used to write the port.

CORE_PIN0_PORTSET :determines to which port this is written. GPIO6_DR_SET in this case, port 6

I’ve got it sorted out and that's what happened,
if I understand correctly?

Re: Hacking cartridge HP 84/85

Posted: Sat Oct 05, 2019 7:43 pm
by MAsic12345
dragonator wrote:
Thu Oct 03, 2019 6:14 pm

Code: Select all

byte pinTable[] = {0,3,4,5,6,7,8,9};
void setup() {
for(int i=0; i<8; i++) {
  pinMode(pinTable[i],OUTPUT); 
  }
}

void loop() {
 GPIO6_DR = GPIO6_DR | 8;
 GPIO6_DR = GPIO6_DR & ~8; //the ~ inverts the 1's and 0's.
}
i used your code here is the result
Безымянный.png
Безымянный.png (80.62 KiB) Viewed 2320 times


but I still can’t understand how to change the pin
can’t understand why the eight at the end of the team

Code: Select all

GPIO6_DR = GPIO6_DR | 8;

Re: Hacking cartridge HP 84/85

Posted: Sun Oct 06, 2019 10:34 am
by dragonator
Now that you have confirmed that the code works, you are 80% of the way there. The 25MHz is going to be the absolute maximum.

Two things to explain what is happening here:

1, the very basics, but important. Binary numbers. Microcontrollers work with binary numbers. Each binary digit is called a bit. 8 bits make a byte, and an 8 bit number can be anything between 00000000 (0) and 11111111 (255). Most Teensy's do most of their operations in 32 bit numbers.

2. A microcontroller has it's I/O pins in ports. This is so that a pin state (high or low) can be represented with a number for a whole port of pins at the same time. Teensy has a 32 bit wide port for I/O pins. This is the table you made. On the teensy the ports are numbered.The example you used is port 6, or GPIO6_DR. Pin 0 is bit 3 in that port, and pin 1 is bit 2.

This means that if I have a number I write to that port, the second bit determines the state of pin 0. 00000000000000000000000000001000 is bit 3 being high, and all other bits being low. The numbers go from right to left and start at 0. If you decode this to a human readable number, it becomes 8.

Two links to help:
https://www.arduino.cc/reference/en/lan ... itwiseand/
https://www.arduino.cc/reference/en/lan ... bitwiseor/

What you wrote to the port is "GPIO6_DR = GPIO6_DR | 8;". You do not simply want to go "GPIO6_DR = 8;" because it will write a 0 to all other pins. You only want to affect pin 0. The or command is explained in the second link. It will combine the current state of port 6 with the bits that 1 in the number 8 (only the third bit). The next command does the same thing, only making it low. ~10101010 equals 01010101. It flips all the bits. And will only keep something 1 if the bit in both numbers is 1. This means that the single 0 on bit 3 is the only pin that will change. All other pins will stay the same.

A way to easily make the number with the right bits is to use bitshift.

https://www.arduino.cc/reference/en/lan ... shiftleft/
https://www.arduino.cc/reference/en/lan ... hiftright/

This is a lot of new information, but I hope it will help you understand more what it is you are doing.

Re: Hacking cartridge HP 84/85

Posted: Sun Oct 06, 2019 5:26 pm
by MAsic12345
finally I could figure it out
it was incredibly hard
14124.png
14124.png (24.3 KiB) Viewed 2306 times

Code: Select all

byte pinTable[] = {0,1,2,3,4,5,6,7,8,9};
void setup() 
{
for(int i=0; i<10; i++) 
  {
  pinMode(pinTable[i],OUTPUT); 
  }

}
char a[] = {1,0,1,0,1,0,1,0,1,0,1,0,1,0};
char b[] = {1,0,1,0,1,0,1,0,1,0,1,0,1,0};
char c[] = {1,0,1,0,1,0,1,0,1,0,1,0,1,0};
char d[] = {1,0,1,0,1,0,1,0,1,0,1,0,1,0};
char e[] = {1,0,1,0,1,0,1,0,1,0,1,0,1,0};

void loop() 
{
  for(int i=0;i<14;i++)
  {

  if(a[i]==1)
    {
    GPIO6_DR = GPIO6_DR | 8;    //PIN 0
    }
    else
    {
    GPIO6_DR = GPIO6_DR & ~8;
    }
//////////////////////////////////////
  if(b[i]==1)
    {
    GPIO6_DR = GPIO6_DR | 4;    //PIN 1
    }
    else
    {
    GPIO6_DR = GPIO6_DR & ~4;
    }
//////////////////////////////////////
  if(c[i]==1)
    {
    GPIO9_DR = GPIO9_DR | 16;    //PIN 2
    }
    else
    {
    GPIO9_DR = GPIO9_DR & ~16;
    }
//////////////////////////////////////
  if(d[i]==1)
    {
    GPIO9_DR = GPIO9_DR | 32;   //PIN 3
    }
    else
    {
    GPIO9_DR = GPIO9_DR & ~32; 
    }
//////////////////////////////////////
  if(e[i]==1)
    {
    GPIO9_DR = GPIO9_DR | 64;    //PIN 4
    }
    else
    {
    GPIO9_DR = GPIO9_DR & ~64;
    }

  }
}
of course you can do simultaneous switching using 1010101
but that’s enough for me I used 1000000 in turn

Thank dragonator

Re: Hacking cartridge HP 84/85

Posted: Mon Oct 07, 2019 5:15 pm
by dragonator
One more thing to try that will actually do it all together. I hope I wrote it right, it is difficult for me to test here. I works on port 7 bits 0 to 3, so pin 10-13. Let me know if it actually works or where it gives errors.

Code: Select all

byte pinTable[] = {10,12,11,13}; //port 7 bit 0,1,2 and 3

char a[] = {1,0,0,0,1,0,1,0,0,0,1,1,1,0};
char b[] = {0,1,0,0,1,0,1,0,0,0,1,1,0,0};
char c[] = {0,0,1,0,1,0,1,0,0,1,1,1,0,0};
char d[] = {0,0,0,1,1,0,1,0,1,1,1,1,1,0};

long pulse[14];
long decode_pulse;

void setup() 
{
for(int i=0; i<4; i++) 
  {
    pinMode(pinTable[i],OUTPUT); 
  }
  
  for(int i=0;i<14; i++) //encode the values to a single value that can be written to a port
  {
    pulse[i] = 0; //reset pulse
    bitWrite(pulse[i], 0, a[i]); //write 10 (a)
    bitWrite(pulse[i], 1, b[i]); //write 12 (b)
    bitWrite(pulse[i], 2, c[i]); //write 11 (c)
    bitWrite(pulse[i], 3, d[i]); //write 13 (d)
  }
}

void loop()
{   
  for(int i=0;i<14; i++)
  {
    decode_pulse = GPIO7_DR & ~15; //reset the first 4 bits of the port
    GPIO7_DR = decode_pulse| pulse[i]; //set the first 4 bits of the port
  }
}

Re: Hacking cartridge HP 84/85

Posted: Mon Oct 07, 2019 5:34 pm
by MAsic12345
dragonator wrote:
Mon Oct 07, 2019 5:15 pm
One more thing to try that will actually do it all together. I hope I wrote it right, it is difficult for me to test here. I works on port 7 bits 0 to 3, so pin 10-13. Let me know if it actually works or where it gives errors.

no mistakes

Re: Hacking cartridge HP 84/85

Posted: Thu Oct 17, 2019 7:52 pm
by MAsic12345

Re: Hacking cartridge HP 84/85

Posted: Thu Oct 17, 2019 8:04 pm
by MAsic12345
finally the result of this long work.
it was hardcore for a person who did not do this before
it is a great joy and victory for me
Thanks to the people who helped me in this. Thank you very much.

Re: Hacking cartridge HP 84/85

Posted: Wed Dec 04, 2019 10:35 pm
by bigbomber
congratulations!!!!
it is a very good to hear that HP 85 is hacked!!!
can you give us a conclusion about pinout, timings and nozzles physical specifications?
I'm very interested in your project