Configure Timer 1 or Timer 2 in SAM V71.

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
I recently started programming on a Atmel SAMv71 microcontroller.
Easily I managed to get one timer (TC0, Channel 0) working corrently.
 Now I wanted to use more than one Channel/Timer.
The problem now is, that the code that works fine with the already active timer channel won't work with the other channels.
Has anybody more than one working counter?
It would be great if somebody could help.

The code I use is this:

pmc_enable_periph_clk(ID_TC0);
NVIC_EnableIRQ(TC0_IRQn);
tc_init(TC0, 0, TC_CMR_TCCLKS_TIMER_CLOCK5);
tc_write_rc(TC0,0, ul_value);
tc_enable_interrupt(TC0,0,TC_IER_COVFS);
tc_start(TC0, 0);

 

Last Edited: Thu. Mar 3, 2016 - 09:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

How dow you intent to use them?

I have set up 6 Timer Capture channels and had no problem. In PWM units however you have to configure channel 0 lastly, (because the PWMC_ConfigureChannel() overwrite Ch0 settings..)

 

From your code I understand that you are enabling IRQ, without configuring the timer first, and without clearing pending IRQ.. Also  have you set the TCx_Handlers correctly? What does TC_init does??

 

Yannis

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that sam v7 is cortex m7 not arm7.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi I undergo the same problem does anyone try the TC in waveform mode? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

I have checked with a "barebone" layout (the layout in which i myself soldern and flash, without RAM) and it work like it should be. I would suggest that the RAM onboard would be the reason for this problem.

 

For TIOB I found the solutions here:

http://www.at91.com/discussions/...

and here

http://atmel.force.com/support/a...

as said in section 46.6.11 Waveform Operating Mode : TIOB is defined as an output if it is not used as an external event (EEVT parameter in TC_CMR). so you muss set clearly that TC_CMR_EEVT_XC0 in order to make TIOB as output.

 

 

Best regards,

Last Edited: Fri. Mar 11, 2016 - 10:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 3

Hi there,

Not sure if you have found the solution to your problem, but I had the same issue and after some interaction with Atmel support I found the solution. Although this is an old-ish thread, I thought I'd share the answer anyway.

 

The problem I was having was that I did not realise that each channel of each TC must be enabled separately in the PMC, as shown in the code below. I thought that the first line in the snippet below would enable the clock to all channels in TC0, but each TC channel seems to be a different TC as far as the PMC is concerned. This is shown in Table 14-1 of the datasheet where each TC is treated separately. However it is a little confusing because the 16-bit Timer Counter Channel 3, 4 and 5 have instance names of TC3, TC4 and TC5 in Table 14-1 of the datasheet, but are all referred to as instance TC1 in Table 50-4.

 

Hope this helps you out. 

 

PMC->PMC_PCER0 |= (1 << ID_TC0);    // Enable clock to TC0, Ch0
PMC->PMC_PCER0 |= (1 << ID_TC1);    // Enable clock to TC0, Ch1
// etc...

 

Last Edited: Wed. Jun 1, 2016 - 10:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hi,

Am also new here.

am struggling to get my timer working.

if you don't mind, could you share your basic timer code?

It would have been really helpful.

Am using SAM E 70 & hopefully your code might give an insight regarding how to program the board that I am having.

Please help.

crying

Silly beans are always silly
:)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hi all,

 

the E70 documentation and also the examples given by ATMEL are misleading concerning the enabling of the clock of the timers in the PMC. You have to enable the clock of each channel in the PMC seperately. The id's are given as follows:

#define ID_TC0                   TC0_INSTANCE_ID_CHANNEL0
#define ID_TC1                   TC0_INSTANCE_ID_CHANNEL1
#define ID_TC2                   TC0_INSTANCE_ID_CHANNEL2
#define ID_TC3                   TC1_INSTANCE_ID_CHANNEL0
#define ID_TC4                   TC1_INSTANCE_ID_CHANNEL1
#define ID_TC5                   TC1_INSTANCE_ID_CHANNEL2
#define ID_TC6                   TC2_INSTANCE_ID_CHANNEL0
#define ID_TC7                   TC2_INSTANCE_ID_CHANNEL1
#define ID_TC8                   TC2_INSTANCE_ID_CHANNEL2
#define ID_TC9                   TC3_INSTANCE_ID_CHANNEL0
#define ID_TC10                  TC3_INSTANCE_ID_CHANNEL1
#define ID_TC11                  TC3_INSTANCE_ID_CHANNEL2

 

 

So if for example if you want to use channel 0 and channel 1 of TC1 you have to include the following code:

pmc_enable_periph_clk( TC1_INSTANCE_ID_CHANNEL0);

pmc_enable_periph_clk( TC1_INSTANCE_ID_CHANNEL1);

 

The defines for TC1_INSTANCE_ID_CHANNEL0 etc. are given in the tc1.h file that should be included in any project that is build on ASF. If this is not the case you can simply copy it from any other example project.

 

Best Regards

Markus