PWM on SAMD21

Guest #5489108
Rate this post
• ▲ 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.
1
#include "sam.h"
2

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

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

13
  while(REG_TCC0_CTRLA & 1){} //Esperar hasta sincronizar
14
  
15
  REG_TCC0_WAVE = 2; // Modo PWM normal
16
  REG_TCC0_PER = 16666-1;
17
  REG_TCC0_CC0 = 5555-1;
18
  REG_TCC0_CTRLA |= 2;
19
  
20
  ARRAY_PORT_PINCFG0[17] |= 1; //Activa el multiplexor a perifericos
21
  ARRAY_PORT_PMUX0[8] = (0x5<<4);
22
  
23
  while (1) 
24
    {
25
  }
26
}

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.