Hello again!I have doubts about how to modify the working frequency of the SAMD21 microcontroller, I made this poor program attempt:
#include <stdint.h>#include <stdbool.h>#include "samd21.h" // Device header#include "GPIO.h"//Definiciones#define LED_BUILTIN 8#define TEMP1MSEG 8000//FUNCIONES GLOBALES void SystemBegin(void);void Delay_ms(int x);void DelaySystick(void);int main(void){ //Inicializa el sistema SAMD21 SystemBegin(); //Configuramos el Pin PB08 como salida GPIOPinMode(GPIO_B,LED_BUILTIN,OUTPUT_TOGGLE); /* PROGRAMA PRINCIPAL */ while(true) { GPIOPinToggle(GPIO_B,LED_BUILTIN); Delay_ms(500); }}//FUNCIONES QUE MODFICAN EL SISTEMA Y EL LOS RETARDOS void SystemBegin(void){ //Inicia el sistema SystemInit(); SYSCTRL->OSC8M.bit.PRESC=0x00; //no hay preescalador (es 8 en el reajuste) SYSCTRL->OSC8M.reg=SYSCTRL_OSC8M_ENABLE; //Habilita la fuente GCLK->GENDIV.bit.ID=0x00; //Seleccionamos el Generador 0 GCLK->GENDIV.bit.DIV=0; //Sin preescaldor GCLK->GENCTRL.bit.ID=0x00; //Seleccionamos el Generador 0 GCLK->GENCTRL.reg=GCLK_GENCTRL_SRC_OSC8M;//Seleccionamos como fuente de oscilador interno la de 8MHz GCLK->GENCTRL.bit.GENEN=1; //Habilitamos el generador} void Delay_ms(int x){ int i; for(i=0;i<x;i++) { DelaySystick(); }}void DelaySystick(void){ SysTick->CTRL=0x00; SysTick->LOAD=TEMP1MSEG; SysTick->CTRL=0x05; while( (SysTick->CTRL & (1<<16)) == 0); SysTick->CTRL=0x00;}
But I think what caused the microcontroller to lock up or something, was that it changed in the Xtal(MHz) option to 1MHz
My question is whether modifying the frequency within the program does not affect what I put into the Xtal(MHz) function?
antouriel123 said:how to modify the working frequency of the SAMD21 microcontroller
That's a question for Microchip - nothing to do with Keil or ARM:
https://community.arm.com/developer/tools-software/tools/f/keil-forum/43684/lpc2148-timer0-not-working-as-expected/158950#158950
See the resources from Microchip:
https://www.microchip.com/wwwproducts/en/ATSAMD21G18
https://start.atmel.com/
antouriel123 said:My question is whether modifying the frequency within the program does not affect what I put into the Xtal(MHz) function
That's an entirely different question - ie, how Keil uses the value you put into that box.
AFAIK, Keil just uses that when it converts clock cycles to time values for display in the debugger or simulator - it has no effect on the operation of the code