How do you generate a reference voltage in a circuit?
You want to know how to measure the battery voltage that's powering the analogue to digital converter.   well unless you can use a different voltage as the anaglogue reference voltage you can't 

You want to know why you get 1023 (the highest ADC reading possible on your device) - that's because the battery voltage is equal to (or higher than) the reference voltage.

So what can you do?

One option is to get a reference voltage source to provide a fixed "V_AREF" supply to the ADC. this is often using a shunt reference (more on that later) this will produce a lower voltage than the battery gives, so you also need to reduce the battery voltage (eg. using a resistive divider to reduce the battery voltage by some ratio) so that it falls inside the new measurement range of the ADC

another option is to get use the battery voltage as reference and mesure a known lower voltage "VREF" that is less than the battery voltage  and measure that with the ADC

Eg. The VREF is 1.25V  you measure it and to comes out at 315 on the ADC. you then do some arithmetic: if 1.25V is 315  what voltage would be 1023 ?
    1023 / 315 * 1.25 =

This is a good method because you can power the voltage reference source from one of the GPIO pins, so when you don't need it you can turn it off so that it doesn't consume energy.

The voltage reference could be something cheap like a LED, or a precision reference like TL431CLPG depending on how much precision you need.