dbuezas / lgt8fx

Board Package for Logic Green LGT8F328P LGT8F328D and LGT8F88D
369 stars 88 forks source link

Lgt8fx - ADC analogRead() is wrong - it only returns back 10bit - need to load manually ADCH + ADCL to get 12bit value #265

Closed jlsilicon closed 1 year ago

jlsilicon commented 1 year ago

I used analogRead() for Lgt8fx , but it only gave me values from 0 to 1023 (10bits). -- which is wrong for Lgt8f chips. I needed to manually read ADCH + ADCL to get the values from 0 to 4095 (12bits)

See below :

// - wait for ADC Ready 
// - tests wrong - only 10 bits , input of potentiometer varies between 0 .. 1023
A_R = analogRead( A0 );  

// - get true 12bit value - tests correctly - returns 12 bits , input of potentiometer varies between 0 .. 4095
A_R = ( (ADCH << 8) | (ADCL << 0) );  
jayzakk commented 1 year ago

10 bits is the Arduino default for compatibility reasons. If you need better (and know your board supports it) you can change with analogReadResolution().

This works as intended, so closing.

Regards, Oliver

jlsilicon commented 1 year ago

oh well