AS5048a "incremental" on Mega2560

Hi all,

I’m trying to convert the absolute SPI output from a AS5048a to a incremental value. With the following code I’d expect the incremental count to follow the angle value i.e. 1 degree = 1 increment to the count, but it doesn’t, it doesn’t get anywhere near it but it does seem to generate more counts if the sensor is moved slowly. Can anyone see what I’m doing wrong here?

#include "AS5048A.h"
#include <MCUFRIEND_kbv.h>

MCUFRIEND_kbv tft;       
AS5048A angleSensor(53);
int currentValue, previousValue,ct;


void setup()
{
 
 uint16_t id;
 id = tft.readID();
 tft.begin(id);
 tft.setRotation(1); //landscape
 tft.fillScreen(TFT_WHITE); 
 tft.setTextColor(TFT_BLACK, TFT_WHITE);
 tft.setTextSize(2);

 angleSensor.init();

}

void loop()
{ 

 int val = angleSensor.getRawRotation();
 int angle=val/45.511;
 
 tft.setCursor(50, 120);
 tft.print("Current angle: "); 
 tft.print(angle);
 tft.print(" degrees ");

 tft.setCursor(50, 140);
 tft.print("Current value: "); 
 tft.print(val);

 currentValue=angle;

 if (currentValue != previousValue) {previousValue=currentValue;
                                     ct=++ct;  
                                     tft.setCursor(50, 160);
                                     tft.print("Current count: "); 
                                     tft.print(ct);}
                                     
                                   

}

TIA.

ct=++ct;

Should be:

ct++;

Does encoder only turn one direction, UP and never DOWN?
For math try:

int angle = val * 0.021973 + 0.5; // for rounding

Doh! Yes c++, unfortunately makes no difference. also multiplying instead of division too. The sensor goes both ways but at the moment I only need to know if it has moved.