For (D2D) HD measurement using PTA6 ADC1_S18, you should also include the voltage divider factor into previously mentioned equation.
Such voltage divider factor is configured with CFG[HDHSDIV] register (see reference manual):
_Leo__0-1762896791370.png
The voltage divider factor values are stated datasheet:
_Leo__1-1762896801798.png
So equation 2 should be updated to:
ADCresult = ((2^N) (Vin / divider_factor)) / VREF
I hope this information is helpful.