Grazie mille per la risposta.
Ho letto tutto.
Riguardo a questa:
PWM library (GitHub) – a powerful library that allows you to change the PWM frequency on ATmega48 / 88 / 168 / 328 / 640 / 1280 / 1281 / 2560 / 2561 microcontrollers, of which 328 is on UNO/Nano/Mini and 2560 is an Arduino Mega.
Credi che ATmega48 stia anche per 4809 dell'Arduino Nano Every ?
NON c'entra nulla, è una famiglia di MCU orientata all'automotive, basta cercare il datasheet ...
Il ATmega4809 è una nuova famiglia (megaAVR 0), diversa dai vecchi AVR, per cui o le librerie vengono scritte anche per supportare questa specifica MCU oppure non vanno bene.
Gran bell'articolo! Ovviamente il tutto è decisamente troppo per me... ma leggendolo ho avuto modo di affinare un pò le ricerche e sono riuscito a trovare la libreria megaAVR_PWM
Questa libreria modifica la frequenza del Arduino Nano Every ma... non riesco proprio a capire come fare a modificare il Duty cycle che per impostazione di libreria avviene in percentuale 0-100% e farlo tornare a 8 bit 0-255. Noto che il motore ad ogni salto numerico "saltella"... Grazie a tutti come sempre in anticipo.
Ecco il codice che sto utilizzando attualmente, ad A7 è collegato un sensore ad effetto Hall.
#define _PWM_LOGLEVEL_ 0 // 4 for complete log
#include "megaAVR_PWM.h"
#define USING_TIMERB true
#define pwm 6 // Use Timer B of Pin 6 for High Frequency
megaAVR_PWM* PWM_Instance;
float frequency;
int sensorValue;
float dutyCycle;
void setup() {
Serial.begin(9600);
while (!Serial) { ; }
Serial.begin (9600);
frequency = 40000; // Set Frequency to 40000 Hz
PWM_Instance = new megaAVR_PWM(pwm, frequency, 0);
}
void loop() {
sensorValue = analogRead(A7); // Read Hall Sensor
dutyCycle = map(sensorValue, 184, 840, 0, 100); //Map Hall Sensor to Duty cycle
PWM_Instance->setPWM(pwm, frequency, dutyCycle); //Set Duty cycle
Serial.print(", PWM: ");
Serial.println (dutyCycle); // Send Pwm Value to Serial Monitor
Serial.print(", Hall: ");
Serial.print(sensorValue); // Send Hall Value to Serial Monitor
}
//End