Nano Every Board - Timer B registers not compiling

I am using TCB0 timer for 8 BIT pwm MODE as per ATMEGA4809 USER Guide documentation.

the arduine IDE environment won't recognize the registers ...

is there any timer header files available that i can use to solve this compilation issue on the nano every board?

or how to solve this issue? Additionally i also have freeRTOS library installed - i assume that the RTOS wud use Timer A and i can use any of the 4 TCB timers for my private application - pls confirm this assumption

It would help if you posted your sketch...

It is easier to provide help if you post your sketch in a reply (using code tags when you do) rather than attaching it

#include <Arduino_FreeRTOS.h>
#include <semphr.h>
#include <megaAVR_TimerInterrupt.h>
#include <megaAVR_TimerInterrupt.hpp>
#include <megaAVR_ISR_Timer.h>
#include <megaAVR_ISR_Timer.hpp>
#include <SoftwareSerial.h>

// inslude the SPI library:
//#include <SPI.h>

#define SCHEDULING_TIMER_BLDC 20
#define SCHEDULING_TIMER 20  // wait for 16.60ms ~60 Hz
#define KEYPRESSCOUNT 5
#define KEYPRESSCOUNTLOW 0
#define KEYPRESSCOUNTHIGH 5

#define FINEDINE 14
#define ADCHAN 4
#define TOPPWMVALUE 225
#define DUTYVALUE 76

// add the FreeRTOS functions for Semaphores (or Flags).

/// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0;  // Analog input pin that the power supply monitor is attached to

const int analogInPinSO1 = A6;  // Analog input pin that the SHx
const int analogInPinSO2 = A5;  // Analog input pin that the SHx
const int analogInPinSO3 = A7;  //Analog input pin that the SHx

// constants won't change. Used here to set a pin number;
const int ledPin = LED_BUILTIN;  // the number of the LED pin

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;

// constants won't change. Used here to set a pin number;
//const int ledPin =  LED_BUILTIN;// the number of the LED pin
int Leddrive = LOW;
int ledState = LOW;
int PrevledState = HIGH;  // DRIVE MOTOR STATUS

int SteerState = LOW;
int PrevSteerState = HIGH;  // STEER MOTOR STATUS
int ButtonState = LOW, bitspistate;
unsigned int simplecnt = 0;
unsigned int humblecount = 0;
unsigned int ADcount = 0;
int sensorValue = 0;  // value read from the pot
int outputValue = 0;  // value output to the PWM (analog out)
int sensorValue1[8][15];
int ADCCHEK;
unsigned int loccount = 0;
unsigned int count = 0, freecount;
unsigned int MotorDelay = 0;

static unsigned int bldcphasecount = 0;

static unsigned int rpmmotor = 400, rpmmotor1 = 400;  // 30 deg electrical Angular equivalent RPM count

// digital pin 2 has a pushbutton attached to it. Give it a name:
uint8_t pushButton = 2;
char Rxport;
unsigned char itimer1, itimer2, adclow, adchigh;
int buttonState[6];

const unsigned int DrvMode[16] = { 0x0000, 0x8800, 0x9000, 0x9800, 0xa000, 0x2b78, 0x3378, 0x3b36, 0xc000, 0xc820, 0x503f, 0xda0a, 0x6058, 0x0000, 0x0000, 0x0000 };

enum BUTTON_T
{
    PRESS,
    POSTPRESS,
    PRESSLOOK,
    POSTPRESSLOOK
};

enum MOTORSPEED_T
{
    GEAR0,
    GEAR1,
    GEAR2,
    GEAR3
};

enum BLDCMOTOR_T
{
    ACCEL0,
    ACCEL1,
    ACCEL2,
    ACCEL3,
    ACCEL4,
    ACCEL5,
    ACCEL6,
    ACCEL7,
    ACCEL8,
    ACCEL9,
    ACCEL10,
    ACCEL11,
    ACCEL12,
    DECEL,
    BEMF1,
    BEMF2,
    STOP,
    ALIGN
};

enum MOTORSPEEDRAMP_T
{
    ASCEND,
    DESCEND,
    SLOW
};

MOTORSPEEDRAMP_T RampCntrl = ASCEND;

MOTORSPEED_T motorspeed_state = GEAR0;

BUTTON_T stateofbutton = PRESSLOOK;

BLDCMOTOR_T bldcstate = STOP;

unsigned int Period, Period0, Period1, Period2;
unsigned int Period3 = 0;
unsigned short int k = 0;
byte Phase[] = { B01100000, B01010000, B01110000, B01000000, B00000010, B11111101 };  //Lookup Table pb1 - least, HL format, only pb1 hi or, low and func, d4/d5 direct portd writes...

//long unsigned int change1, change2, change0 ;

// Declare a mutex Semaphore Handle which we will use to manage the Serial Port.
// It will be used to ensure only only one Task is accessing this resource at any time.
SemaphoreHandle_t xSerialSemaphore;

// define two Tasks for DigitalRead & AnalogRead
void TaskDigitalRead(void *pvParameters);
void TaskHumbleRead(void *pvParameters);
void setup(void);

/**
  void Func_accel0( void );
  void Func_accel2( void );
  void Func_accel4( void );
  void Func_accel6( void );
  void Func_accel8( void );
  void Func_accel10( void );
  void Func_accel12( void );
  void Func_accel_comm( void );

typedef void (*fptr)(void);

const fptr AccelFuncptr[13] = {Func_accel0,Func_accel_comm,Func_accel2,Func_accel_comm,Func_accel4,Func_accel_comm,Func_accel6,Func_accel_comm,Func_accel8,Func_accel_comm,Func_accel10,Func_accel_comm,Func_accel12} ;
 
 **/

// the setup function runs once when you press reset or power the board
void setup()
{
    PORTA.DIR = 0x83;  // PA7 config for CLKOUT chks of CLK_PER value - remove later after DEBUG
    PORTA.OUT = 0x0;

    PORTB.DIR = 0x03;
    PORTB.OUT = 0x0;

    PORTC.DIR = 0x50;
    PORTC.OUT = 0x0;

    PORTD.DIR = 0x07;
    PORTD.OUT = 0x0;

    // port E all are i/ps so no initial value needed
    PORTE.DIR = 0x05;
    PORTE.OUT = 0x0;

    PORTF.DIR = 0x10;
    PORTF.OUT = 0x0;

    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
    // deafult drive code
    //analogReference(DEFAULT);

    while (!Serial)
    {
        ;  // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
    }

    // Semaphores are useful to stop a Task proceeding, where it should be paused to wait,
    // because it is sharing a resource, such as the Serial port.
    // Semaphores should only be used whilst the scheduler is running, but we can set it up here.
    if (xSerialSemaphore == NULL)  // Check to confirm that the Serial Semaphore has not already been created.
    {
        xSerialSemaphore = xSemaphoreCreateMutex();  // Create a mutex semaphore we will use to manage the Serial Port
        if ((xSerialSemaphore) != NULL)
        {
            xSemaphoreGive((xSerialSemaphore));
            // Make the Serial Port available for use, by "Giving" the Semaphore.
        }
    }

    /* Disable interrupts */
    cli();  //stop interrupts

    // Timer Init for TB0/1/2 For FRQPW modes

    // Timers B & A

    //TCA0.SINGLE.CTRLB = 0x01 ; //default is single PWM mode by arduino IDE

    //TCA0.SINGLE.CTRLA = 0x09 ; //default arduino IDE provides divide by 64

    //TCA0.SINGLE.CMP0 = 0x0064 ;

    //TCB0.CTRLB = 0x05 ;
    //TCB0.EVCTRL = 0x01 ;

    // Timers 1

    TCB1.CTRLB = 0x05;
    TCB1.EVCTRL = 0x01;

    //TCB1.INTCTRL = 0x01 ;
    TCB1.CTRLA = 0x05;

    // Timers 2

    TCB2.CTRLB = 0x05;
    TCB2.EVCTRL = 0x01;

    //TCB2.INTCTRL = 0x01 ;
    TCB2.CTRLA = 0x05;

    // EVSYS Drivers

    //EVSYS.CHANNEL0 = 0x42 ;
    EVSYS.CHANNEL4 = 0x4D;
    EVSYS.CHANNEL5 = 0x43;

    // EVSYS.CHANNEL1 = 0x84 ;  // TCA0 CMP0 events connected to channel 1

    //EVSYS.USERTCB0 = 0x01 ; // TCB0 to CH0

    EVSYS.USERTCB1 = 0x05;  // TCB1 to CH4
    EVSYS.USERTCB2 = 0x06;  // TCB2 to CH5

    // set the digital pin as output:
    // PWMA,PWMB,PWMC hold on zero
    // Engate cmd ZERO

    //delay(10);

    for (unsigned int i = 0; i <= 14; i++)
    {
        sensorValue1[7][i] = 620;
    }

    Serial.println("\n\t ADC FILL DONE");

    // enable PWM

    // 1-PWM drive
    //TIMER TCB0 SET UP
    //timer TCB0 -- interrupt @32uS

    TCBROUTEA = 0x01;   // TCB0 o/p routed to PF4/D6 - Arduino port
    TCB0.CTRLA = 0x04;  // TCA0 CLK Chosen, but TCB disabled still
    TCB0.CTRLB = 0x07;  // 8 bit PWM mode chosen for TCB0 timer
    TCB0.CCMPL = DUTYVALUE;
    TCB0.CCMPH = TOPPWMVALUE;

    TCB0.INTCTRL = 0x01;  // interrupt enabled in 8bit PWM mode
                          //TCB0.CTRLA = 0x05 ; // TCB0 enabled

    //the following port pins are configured for rising edge interrupt if configured as I/Ps

    PORTF.PIN3CTRL = 0x02;  // A5/SCL ARDUINO PORT
    PORTE.PIN3CTRL = 0x02;  // D8 ARDUINO PORT
    PORTA.PIN1CTRL = 0x02;  // D7 ARDUINO PORT

    sei();  //allow interrupts

    // Now set up two Tasks to run independently.
    xTaskCreate(
      TaskDigitalRead, (const portCHAR *)"DigitalRead"  // A name just for humans
      ,
      128  // This stack size can be checked & adjusted by reading the Stack Highwater
      ,
      NULL, 3  // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
      ,
      NULL);

    xTaskCreate(
      TaskHumbleRead, (const portCHAR *)"HumbleRead"  // A name just for humans
      ,
      128  // This stack size can be checked & adjusted by reading the Stack Highwater
      ,
      NULL, 1  // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
      ,
      NULL);

    // Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started.
}

ISR(ADC_vect)
{
    adclow = ADCL;
    adchigh = (ADCH & 0x03);
    sensorValue1[(ADMUX & 0x07)][count] = (unsigned int)((((unsigned int)adchigh) << 8) | ((unsigned int)adclow));

    //freecount = freecount + 1 ;
    count = count + 1;
}

ISR(TIMER1_OVF_vect)
{
    Period3 += 1;
}

/*******ISRs**

ISR(PCINT0_vect)
{
 
  TCCR1B = 0x18 ; //0HZTCCR1B &= ~(1<< CS10);//Stoping timer
  PIND|=B00010000;//PIN B to One
  
  Period=ICR1;
  OCR1A=(Period>>1);
  k=0;
  TCNT1=0;
  TCCR1B = 0x19 ; //16MhzTCCR1B &= (1<< CS10);//Starting timer
  
 
 }
ISR(PCINT1_vect)
{
  
  TCCR1B = 0x18 ; //0HZ Stoping timer
  PIND&=B11110111;//PIN A to Zero
  
  Period=ICR1;
  OCR1A=(Period>>1);
  k=1;
  TCNT1=0;
  TCCR1B = 0x19 ; //16Mhz//Starting timer
  
  
}

ISR(PCINT2_vect)
{
  
  
  TCCR1B = 0x18 ; //0HZ//Stoping timer
  PIND&=B11011111;//Pin C to Zero
  
  Period=ICR1;
  OCR1A=(Period>>1);
  k=2;
  TCNT1=0;
  TCCR1B = 0x19 ; //16Mhz//Starting timer
  


}


ISR(TIMER1_COMPB_vect)
{
PIND|=Phase[k];//Commute
}

****/

/**
ISR(PCINT0_vect)
{
  if((PINB & 0x01))
  {
    TCCR1B = 0;//Stoping timer

 

  Period0=TCNT1;

  //OCR1A=(Period>>1);

  //k=0;

  TCNT1=0;

  TCCR1B = 4;//Starting timer
  //change0 += 1 ;
  }
 //pb0 port
}

ISR(PCINT1_vect)
{
  
 if((PINC & 0x20))
  {
    TCCR1B = 0;//Stoping timer

 

  Period1=TCNT1;

  //OCR1A=(Period>>1);

  //k=0;

  TCNT1=0;

  TCCR1B = 4;//Starting timer
  //change1 += 1 ;
  }
 
 //pc5 
}

ISR(PCINT2_vect)
{
  
 if((PIND & 0x80))
  {
    TCCR1B = 0;//Stoping timer

 

  Period2=TCNT1;

  //OCR1A=(Period>>1);

  //k=0;

  TCNT1=0;

  TCCR1B = 4 ;//Starting timer
  //change2 += 1 ;
  }

//pd7
}

**/

ISR(TIMER2_OVF_vect)
{
    //timer1 interrupt
    switch (bldcstate)
    {
        case STOP:

            //digitalWrite(3, LOW);// ports must be zero D3 XCHG TO B1
            //digitalWrite(4, LOW);
            //digitalWrite(5, LOW);
            //PORTB = (B11111101 & PORTB);
            PORTD = B01000000;  //digitalWrite(6, HIGH); // ENGATE

            bldcphasecount = 0;
            bldcstate = ALIGN;
            break;

        case ALIGN:

            if (bldcphasecount == 0)
            {
                PORTB = (B00000010 | PORTB);  //digitalWrite(3, HIGH); B1 XCHG
                PORTD = B01110000;

                //digitalWrite(4, HIGH);
                //digitalWrite(5, HIGH);

                bldcphasecount = bldcphasecount + 1;
            }
            else if (bldcphasecount < 32000)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                // 1-PWM drive 99% DUTY for entering accel
                bldcphasecount = 0;
                bldcstate = ACCEL0;
            }

            break;

        case ACCEL0:

            if (bldcphasecount == 0)
            {
                //*AccelFuncptr[bldcphasecount] ;

                PORTB = (B11111101 & PORTB);  //digitalWrite(3, LOW);
                //PORTD = B01110000 ;

                bldcphasecount = bldcphasecount + 1;
            }
            else if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                bldcstate = ACCEL1;
                bldcphasecount = 0;
            }

            break;

        case ACCEL1:

            // odd states commute cmds
            if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                //freecount = 0 ;
                bldcstate = ACCEL2;
                bldcphasecount = 0;
            }

            break;

        case ACCEL2:

            if (bldcphasecount == 0)
            {
                //*AccelFuncptr[bldcphasecount] ;

                PORTD = B01010000;  //digitalWrite(5, LOW);

                bldcphasecount = bldcphasecount + 1;
            }
            else if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                bldcstate = ACCEL3;
                bldcphasecount = 0;
            }

            break;

        case ACCEL3:

            // odd states commute cmds
            if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                //freecount = 0 ;
                bldcstate = ACCEL4;
                bldcphasecount = 0;
            }

            break;

        case ACCEL4:

            if (bldcphasecount == 0)
            {
                //*AccelFuncptr[bldcphasecount] ;

                PORTB = (B00000010 | PORTB);  //PORTD = B01011000 ;//digitalWrite(3, HIGH);

                bldcphasecount = bldcphasecount + 1;
            }
            else if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                bldcstate = ACCEL5;
                bldcphasecount = 0;
            }

            break;

        case ACCEL5:

            // odd states commute cmds
            if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                //freecount = 0 ;
                bldcstate = ACCEL6;
                bldcphasecount = 0;
            }

            break;

        case ACCEL6:

            if (bldcphasecount == 0)
            {
                //*AccelFuncptr[bldcphasecount] ;

                PORTD = B01000000;  //digitalWrite(4, LOW);

                bldcphasecount = bldcphasecount + 1;
            }
            else if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                bldcstate = ACCEL7;
                bldcphasecount = 0;
            }

            break;

        case ACCEL7:

            // odd states commute cmds
            if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                //freecount = 0 ;
                bldcstate = ACCEL8;
                bldcphasecount = 0;
            }

            break;

        case ACCEL8:
            if (bldcphasecount == 0)
            {
                //*AccelFuncptr[bldcphasecount] ;

                PORTD = B01100000;  //digitalWrite(5, HIGH);

                bldcphasecount = bldcphasecount + 1;
            }
            else if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                bldcstate = ACCEL9;
                bldcphasecount = 0;
            }

            break;

        case ACCEL9:

            // odd states commute cmds
            if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                //freecount = 0 ;
                bldcstate = ACCEL10;
                bldcphasecount = 0;
            }

            break;

        case ACCEL10:

            if (bldcphasecount == 0)
            {
                //*AccelFuncptr[bldcphasecount] ;

                PORTB = (B11111101 & PORTB);  //PORTD = B01100000; //digitalWrite(3, LOW);

                bldcphasecount = bldcphasecount + 1;
            }
            else if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                bldcstate = ACCEL11;
                bldcphasecount = 0;
            }

            break;

        case ACCEL11:

            // odd states commute cmds
            if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                //freecount = 0 ;
                bldcstate = ACCEL12;
                bldcphasecount = 0;
            }

            break;

        case ACCEL12:

            if (bldcphasecount == 0)
            {
                //*AccelFuncptr[bldcphasecount] ;

                PORTD = B01110000;  //digitalWrite(4, HIGH);

                bldcphasecount = bldcphasecount + 1;

                //or BEMF1 if RPM exceeds BEMFTHR
            }
            else if (bldcphasecount < rpmmotor)
            {
                bldcphasecount = bldcphasecount + 1;
            }
            else
            {
                bldcstate = ACCEL1;
                rpmmotor = rpmmotor1;
                bldcphasecount = 0;
            }

            break;

        case DECEL:
            break;

        case BEMF1:

            break;

        default:
            bldcstate = STOP;
            bldcphasecount = 0;
            break;
    }
}

void loop()
{
    // Empty. Things are done in Tasks.
}

//*--------------------------------------------------*/
// /*---------------------- Tasks ---------------------*/
// /*--------------------------------------------------*/

void TaskDigitalRead(void *pvParameters __attribute__((unused)))  // This is a Task.
{
    //digitalWrite(ledPin, LOW);
    //freecount = 0 ;
    //start motor PWM cmd only
    TCCR2B = 0x01;  //starts clk io to timer2 //16Mhz
                    //change1 = 0;
                    //change2 = 0;
                    //change0 = 0;

    for (;;)  // A Task shall never return or exit.
    {
        // read the input pin:

        //digitalWrite(ledPin, Leddrive);

        // Leddrive = !Leddrive ;

        // Motor control portion

        // them monitor logic - exit - BATTERY VALUE 670 decimal is good for stop motor control or 660.

        // based on RC o/p for motor logic/direction change for sterr+drive, set direction for motor.example only below .all info from Serial port Rx Task
        // first to stop PWM:

        /******************************************

  if (PrevledState != ledState)
  {

  if (ledState == LOW) 
  {
      // print the results to the Serial Monitor:
      digitalWrite(7, HIGH); 
      if (MotorDelay < 8)
        {
          MotorDelay = MotorDelay + 1 ;
          
        }
        else
        {
  
        MotorDelay = 0 ;
        //delay(100);
        digitalWrite(8, LOW);//6 shud opeartw
        PrevledState = ledState ;
        if (ledState == LOW) {
      
      //analogWrite(6, outputValue);
  
  
    } else {
      
      //analogWrite(5, outputValue);
  
    }
        
        // See if we can obtain or "Take" the Serial Semaphore. 
      // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
      if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { 
        // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
        // We want to have the Serial Port for us alone, as it takes some time to print, 
        // so we don't want it getting stolen during the middle of a conversion. 
        // print out the state of the button:

          if (ledState == LOW) 
         {
      
            Serial.println("\n\t MotorControl = Forward");
  
  
         } 
         else
         {
      
            Serial.println("\n\t MotorControl = Reverse"); 
  
         } 
        
         
 
        xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
              }
        
        }
  
  
    } 
    else
    {
      // print the results to the Serial Monitor:
  digitalWrite(8, HIGH);
       if (MotorDelay < 8)
        {
          MotorDelay = MotorDelay + 1 ;
          
        }
        else
        {
  
        MotorDelay = 0 ;
        //delay(100);
        digitalWrite(7, LOW);// 5 shud operaTE
        PrevledState = ledState ;
        if (ledState == LOW) {
      
      //analogWrite(6, outputValue);
  
  
    } else {
      
      //analogWrite(5, outputValue);
  
    }
        
        // See if we can obtain or "Take" the Serial Semaphore. 
      // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
      if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { 
        // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
        // We want to have the Serial Port for us alone, as it takes some time to print, 
        // so we don't want it getting stolen during the middle of a conversion. 
        // print out the state of the button:

          if (ledState == LOW) 
         {
      
            Serial.println("\n\t MotorControl = Forward");
  
  
         } 
         else
         {
      
            Serial.println("\n\t MotorControl = Reverse"); 
  
         } 
        
         
 
        xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
              }
        
        }
      
  
    }

  
         
    } 

***************************/

        //Battery Monitor portion
        if (count < 8)
        {
            ADMUX |= 0x07;  //0x47 ; // repeat in isr cpde for A7
            ADCSRA = 0xDF;  //SOC BIT 6

            //sensorValue1[count] = analogRead(analogInPin);
        }
        else
        {
            count = 0;
            sensorValue = 0;
            while (count < 8)
            {
                sensorValue += sensorValue1[7][count];
                count = count + 1;
            }

            sensorValue = (sensorValue >> 3);

            count = 0;

            if (sensorValue >= 500)
            {
                // map it to the range of the analog out, ready for supply voltage based Pwm Control, extend 4 or 5 sample averaging here.
                outputValue = map(sensorValue, 600, 750, 255, 0);
                // 490 coreesponds to 4.5 volts, aref=3.3volts, 22k/12k
                //outputValue = (255 - outputValue) ;

                //outputValue = (outputValue >> 1) ;

                // inkl logic for battery cut off...or warning or stop control of motor

                if (outputValue > 255)
                {
                    outputValue = 255;
                }
                else if (outputValue < 0)
                {
                    outputValue = 0;
                }

                if (outputValue != 0)
                {
                    outputValue = (outputValue >> motorspeed_state);
                }

                if (simplecnt <= 57)
                {
                    simplecnt = simplecnt + 1;
                }
                else
                {
                    simplecnt = 0;
                    // See if we can obtain or "Take" the Serial Semaphore.
                    // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
                    if (xSemaphoreTake(xSerialSemaphore, (TickType_t)1) == pdTRUE)
                    {
                        // We were able to obtain or "Take" the semaphore and can now access the shared resource.
                        // We want to have the Serial Port for us alone, as it takes some time to print,
                        // so we don't want it getting stolen during the middle of a conversion.
                        // print out the value you read:
                        //Serial.println("\n\t  Sensor Value");
                        Serial.println(sensorValue);

                        // Serial.println("\n\t PWM Value");
                        //Serial.println(outputValue);

                        xSemaphoreGive(xSerialSemaphore);  // Now free or "Give" the Serial Port for others.
                    }
                }
            }
            else
            {
                outputValue = 0;
                if (sensorValue < 580)
                {
                    if (simplecnt <= 9)
                    {
                        simplecnt = simplecnt + 1;
                    }
                    else
                    {
                        simplecnt = 0;
                        // See if we can obtain or "Take" the Serial Semaphore.
                        // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
                        if (xSemaphoreTake(xSerialSemaphore, (TickType_t)1) == pdTRUE)
                        {
                            // We were able to obtain or "Take" the semaphore and can now access the shared resource.
                            // We want to have the Serial Port for us alone, as it takes some time to print,
                            // so we don't want it getting stolen during the middle of a conversion.
                            // print out the value you read:
                            Serial.print("\n\t battlow");

                            // Serial.print("     sensor = ");
                            Serial.print(sensorValue);

                            // Serial.println("\n\t\t    ");
                            //Serial.println(outputValue);

                            xSemaphoreGive(xSerialSemaphore);  // Now free or "Give" the Serial Port for others.
                        }
                    }
                }
            }
        }

        //serial port checks...

        // See if we can obtain or "Take" the Serial Semaphore.
        // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.

        // We were able to obtain or "Take" the semaphore and can now access the shared resource.
        // We want to have the Serial Port for us alone, as it takes some time to print,
        // so we don't want it getting stolen during the middle of a conversion.
        // print out the state of the button:
        if (Serial.available())
        {
            Rxport = Serial.read();

            if (Rxport == '0')
            {
                motorspeed_state = GEAR0;
                rpmmotor1 = 350;
            }
            else if (Rxport == '1')
            {
                motorspeed_state = GEAR1;
                rpmmotor1 = 300;
            }
            else if (Rxport == '2')
            {
                motorspeed_state = GEAR2;
                rpmmotor1 = 250;
            }
            else if (Rxport == '3')
            {
                motorspeed_state = GEAR3;
                rpmmotor1 = 200;
            }
            else if (Rxport == '+')
            {
                //OCR1A += 5 ;
                OCR2B += 5;  // duty cycle
            }
            else if (Rxport == '-')
            {
                //OCR1A -= 5 ;
                OCR2B -= 5;  // duty cycle
            }

            if (xSemaphoreTake(xSerialSemaphore, (TickType_t)1) == pdTRUE)
            {
                Serial.println("\n\t RXPORT");
                Serial.println(Rxport);
                //Serial.println(OCR1A);
                Serial.println(OCR2B);
                //Rxport1 = Rxport;
                xSemaphoreGive(xSerialSemaphore);  // Now free or "Give" the Serial Port for others.
            }
        }

        // xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
        //}

        /**if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
                  // We want to have the Serial Port for us alone, as it takes some time to print, 
                  // so we don't want it getting stolen during the middle of a conversion. 
                  // print out the state of the button: 
                  //Serial.println("\n\t PushButton = LOW");
                  //ledState = !ledState ;
                    Serial.println("\n\t Pressed");//Serial.println(buttonState); 
                    //stateofbutton = POSTPRESSLOOK ;
 
                  xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
                  
              }*
              */

        vTaskDelay(SCHEDULING_TIMER / portTICK_PERIOD_MS);  //pdMS_TO_TICKS()
                                                            //vTaskDelay( pdMS_TO_TICKS(16.6) );
    }
}

void TaskHumbleRead(void *pvParameters __attribute__((unused)))  // This is a Task.
{
    for (;;)  // A Task shall never return or exit.
    {
        //push button read portion

        switch (stateofbutton)
        {
            case PRESSLOOK:
                if (loccount <= KEYPRESSCOUNT)
                {
                    buttonState[loccount] = digitalRead(pushButton);
                    loccount = loccount + 1;
                }
                else
                {
                    stateofbutton = PRESS;
                }

                break;

            case PRESS:
                ButtonState = LOW;
                loccount = KEYPRESSCOUNTLOW;
                while (loccount <= KEYPRESSCOUNTHIGH)
                {
                    if (!buttonState[loccount])
                    {
                        loccount = loccount + 1;
                    }
                    else
                    {
                        // See if we can obtain or "Take" the Serial Semaphore.
                        // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.

                        // We were able to obtain or "Take" the semaphore and can now access the shared resource.
                        // We want to have the Serial Port for us alone, as it takes some time to print,
                        // so we don't want it getting stolen during the middle of a conversion.
                        // print out the state of the button:
                        //Serial.println("\n\t PushButton = HIGH");

                        //Serial.println(buttonState);

                        //xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
                        loccount = 0;
                        ButtonState = HIGH;
                        break;
                    }
                }

                if (ButtonState)
                {
                    ButtonState = LOW;
                    stateofbutton = PRESSLOOK;
                }
                else
                {
                    ledState = !ledState;
                    stateofbutton = POSTPRESSLOOK;
                    if (xSemaphoreTake(xSerialSemaphore, (TickType_t)1) == pdTRUE)
                    {                                                 // We were able to obtain or "Take" the semaphore and can now access the shared resource.
                                                                      // We want to have the Serial Port for us alone, as it takes some time to print,
                                                                      // so we don't want it getting stolen during the middle of a conversion.
                                                                      // print out the state of the button:
                                                                      //Serial.println("\n\t PushButton = LOW");
                                                                      //ledState = !ledState ;
                        Serial.println("\n\t PushButton = Pressed");  //Serial.println(buttonState);
                                                                      //stateofbutton = POSTPRESSLOOK ;

                        xSemaphoreGive(xSerialSemaphore);  // Now free or "Give" the Serial Port for others.
                    }

                    loccount = 0;
                }

                break;

            case POSTPRESSLOOK:

                if (loccount <= KEYPRESSCOUNT)
                {
                    buttonState[loccount] = digitalRead(pushButton);
                    loccount = loccount + 1;
                }
                else
                {
                    stateofbutton = POSTPRESS;
                }

                break;

            case POSTPRESS:
                ButtonState = LOW;
                loccount = KEYPRESSCOUNTLOW;
                while (loccount <= KEYPRESSCOUNTHIGH)
                {
                    if (buttonState[loccount])
                    {
                        loccount = loccount + 1;
                    }
                    else
                    {
                        // See if we can obtain or "Take" the Serial Semaphore.
                        // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.

                        // We were able to obtain or "Take" the semaphore and can now access the shared resource.
                        // We want to have the Serial Port for us alone, as it takes some time to print,
                        // so we don't want it getting stolen during the middle of a conversion.
                        // print out the state of the button:
                        //Serial.println("\n\t PushButton = HIGH");

                        //Serial.println(buttonState);

                        //xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
                        loccount = 0;
                        stateofbutton = POSTPRESSLOOK;
                        ButtonState = HIGH;
                        break;
                    }
                }

                if (ButtonState)
                {
                    ButtonState = LOW;
                    // stateofbutton = LOOK ;
                }
                else
                {
                    stateofbutton = PRESSLOOK;
                }

                loccount = 0;

                break;
        }

        if (humblecount <= 6)
        {
            humblecount = humblecount + 1;
        }
        else
        {
            switch (RampCntrl)
            {
                case ASCEND:
                    if (rpmmotor1 >= 25)
                    {
                        rpmmotor1 -= 5;
                    }
                    else
                    {
                        //RampCntrl = DESCEND ;
                        //rpmmotor1 = rpmmotor1 ;//rpmmotor1 += 5 ;
                        RampCntrl = SLOW;
                    }
                    break;

                case DESCEND:
                    if (rpmmotor1 <= 400)
                    {
                        rpmmotor1 += 5;
                    }
                    else
                    {
                        RampCntrl = ASCEND;
                        rpmmotor1 -= 5;
                    }
                    break;

                case SLOW:
                    if (rpmmotor1 > FINEDINE)
                    {
                        rpmmotor1 -= 1;
                        PCICR = 0x07;  // pc interrupts enabled....
                    }
                    else
                    {
                        //RampCntrl = DESCEND ;
                        //rpmmotor1 = rpmmotor1 ;
                        // See if we can obtain or "Take" the Serial Semaphore.
                        // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
                        if (xSemaphoreTake(xSerialSemaphore, (TickType_t)1) == pdTRUE)
                        {
                            // We were able to obtain or "Take" the semaphore and can now access the shared resource.
                            // We want to have the Serial Port for us alone, as it takes some time to print,
                            // so we don't want it getting stolen during the middle of a conversion.
                            // print out the value you read:
                            if (k == 0)
                            {
                                Serial.println("\n\t  PCINT 0    :");
                                Serial.println(Period0);
                                k += 1;
                            }
                            else if (k == 1)
                            {
                                Serial.println("\n\t  PCINT 1    :");
                                Serial.println(Period1);
                                k += 1;
                            }
                            else if (k == 2)
                            {
                                Serial.println("\n\t  PCINT 2    :");
                                Serial.println(Period2);
                                k += 1;
                            }
                            else if (k == 3)
                            {
                                Serial.println("\n\t  TIMER1_OVFF    :");
                                Serial.println(Period2);
                                k = 0;
                            }

                            xSemaphoreGive(xSerialSemaphore);  // Now free or "Give" the Serial Port for others.
                        }

                        if (ADcount > 12)
                        {
                            ADcount = 0;
                        }
                        //rpmmotor1 += 5 ;
                    }
                    break;
            }

            /**if(OCR1A >= 0x000B)
            {
              OCR1A -= 0x000A ; // duty cycle value
            }
            else if (OCR1A >= 0x0180)
            {
              OCR1A += 0x000A ; // duty cycle value
            } **/

            humblecount = 0;
        }

        // void BushButtonRead() ;
        vTaskDelay(SCHEDULING_TIMER_BLDC / portTICK_PERIOD_MS);
        // vTaskDelay( 1000 / portTICK_PERIOD_MS );
        //vTaskDelay( 10 );
    }
}

Hi Bob,
i hope u are able to open the sketch project file that is attached. Background : the original project compiled and executed successfully on the Nano board. Now i am porting the project to the Nano Every board with the ATMega 4809 uC.
There are many compilations errors that i have to sort in this porting project, but, to start with the ATMeg4809 Register based driver code shud compile. that wud be the starting point of help for me in this porting project.

Thanks,Benjamin

#include <Arduino_FreeRTOS.h> 
#include <semphr.h> 
#include <megaAVR_TimerInterrupt.h>
#include <megaAVR_TimerInterrupt.hpp>
#include <megaAVR_ISR_Timer.h>
#include <megaAVR_ISR_Timer.hpp>
#include <SoftwareSerial.h>
// header declarations above at start of sketch

// driver code snippet below from the sketch
TCBROUTEA = 0x01 ; // TCB0 o/p routed to PF4/D6 - Arduino port
  TCB0.CTRLA = 0x04 ; // TCA0 CLK Chosen, but TCB disabled still
TCB0.CTRLB = 0x07 ; // 8 bit PWM mode chosen for TCB0 timer
TCB0.CCMPL = DUTYVALUE ;
TCB0.CCMPH = TOPPWMVALUE ;

TCB0.INTCTRL = 0x01 ; // interrupt enabled in 8bit PWM mode
//TCB0.CTRLA = 0x05 ; // TCB0 enabled

Can anybody help pls...The timer B registers driver code dont compile on the Nano Every Board project setting

Please provide a link. Which core are you using? Arduino core or 3rd party (which one)?

I have no experience with the Nano Every nor with RTOS. I've tried to compile your sketch and got far too many errors (not only related to the timer). If you have that same problem I would suggest that you break your code into pieces and rework each functionalitiy before integrating.

PS
It seems to be PORTMUX.TCAROUTEA and PORTMUX.TCBROUTEA according to 'variant.c' in the Arduino board package. So you can try to prepend PORTMUX.

Well, I'm pretty sure that should look more like:

PORTMUX.TCBROUTA = 0x01;

We might be more help if you'd at least tell us what the error messages were.
Even better would be an otherwise compilable sketch without "many" weird library dependencies.

Brother Westfw, thanks so much, u r syntax was right, this solved my present problem

yes brother sterretje, i prepended the portmux and it worked, thnaks

ur right i am integrating more code and i might have more errors to solve... thanks for the hint

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.