Forum: ARM programming with GCC/GNU tools PWM on SAMD21

von Víctor (Guest)

Rate this post
0 useful
not useful
So I was trying this code I got right off a book but changing the pin 
where I should have the PWM signal output... but it is not working... 
any guesses why?... PD: I can't do debugging because I have a strange 
error on executing the ELF file.

Wrote this code on and did the programming on atmel studio 7 with the 
atmel - ice.
#include "sam.h"

unsigned char* ARRAY_PORT_PINCFG0 = (unsigned char*)&REG_PORT_PINCFG0;
unsigned char* ARRAY_PORT_PMUX0 = (unsigned char*)&REG_PORT_PMUX0;

int main(void)
  REG_GCLK_CLKCTRL = 0x401A; //TCC0 para PWM en GCLK0
    REG_PM_APBCMASK |= 0x00000100; //Enable TCC0, es la funcion F para el pin PA17
  REG_TCC0_CTRLA = 1; //Reset al registro

  while(REG_TCC0_CTRLA & 1){} //Esperar hasta sincronizar
  REG_TCC0_WAVE = 2; // Modo PWM normal
  REG_TCC0_PER = 16666-1;
  REG_TCC0_CC0 = 5555-1;
  REG_TCC0_CTRLA |= 2;
  ARRAY_PORT_PINCFG0[17] |= 1; //Activa el multiplexor a perifericos
  ARRAY_PORT_PMUX0[8] = (0x5<<4);
  while (1) 


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.