Reply by Onestone April 22, 20112011-04-22
yOU OBVIOUSLY DIDN'T READ THE ENTIRE THING. each TIME THE 1KhZ Interrupt
occurs you must add 32 (or whatever number of clock ticks is equal to
1kHz) to the CCRx register. then you must account for the fact that the
timer is being limited in its range to 32768 (when you use the 'count
to' mode, this is what the mask is for. then you must clear the
interrupt flag, except for CCRx0 which auto clears the flag. There are
so many simple ways to do this. My code should be very clear, there is
nothing complicated about it.

Al

Beginning Microcontrollers with the MSP430

Reply by kelsonbatista April 22, 20112011-04-22
In Timer A, I just use CCR0, so I have not faced this problem before. To make things clear I want to generate both frequencies (1Hz and 1KHz) from Timer B only.

Clearing CCIFG as you said, did not work. I did some other test but I have not concluded anything. Can you give me a light? ** i changed the values to make better to understand

For CCR02000 and CCR1 = 4000

FIRST CYCLE:
- CCR0 working (goes to 32000)
- CCR1 working (goes to 36000)

SECOND CYCLE AND SO ON:
- CCRO = working (continue going to 32000)
- CCR1 = NOT working (stopped)
CODE:

Reply by Onestone April 21, 20112011-04-21
Timer A has multiple channels, are you using them all? Are you using the
Timer A overflow ISR as well? There are 4 different very flexible timing
functions you can grab from Timer A. Anyway the principal is the same.
Your 1kHz doesn't work because you are NOT refreshing the compare
register. Also, since you choose to use the 'Count to' mode to generate
your 1Hz time base you have also forgotten that after 32768 is reached
in the 1kHz compare register it will never see the next value becasue
the count overflows and resets to 0. that is only one of the reasons I
hate using the count to mode in most instances. I would simply set the
timer to continous mode, set a constant OneHz and another kHz. Make
OneHz equal to 32768 and khz equal to 32, in each relevant ISR simply do:_



using constants lets you fiddle around with other values and change the
frequency painlessly.

If you insist on using the count to mode then change khz_ISR to:_



Al
Reply by kelsonbatista April 21, 20112011-04-21
> Not related to your specific question, but on some other processors you need
> to count to 32768-1, because 0 counts. That is, the timer counts from 0 to
> 32767 to get 32768 distinct pulses, not 1 to 32768. I don't have the data
> sheet in front of me to decode your mode, but something to verify.

Hi Devin

In fact I heard something about this but I did some tests running only the 1Hz (32768) frequency and looks ok, so I do not think this is the problem. I just need to run different frequencies from the same timer.
Reply by kelsonbatista April 21, 20112011-04-21
> which chip are you employing?

Hi

I am using the MSP430FG4618.
The whole question is ok, only what I need to know is how to run different frequencies from the same timer.
Reply by kelsonbatista April 21, 20112011-04-21
> For a start you have not chosen your timer allocation wisely from the
> information given. If you have a timer B then you have a timer A. In
> this case I would set timer A to source from ACLK and timer b to source
> from MCLK. then set timer A up pretty much as you have for your 1 second
> timebase. next set Timer B up for continuous running, using the count to
> mode inhibits timer flexibility quite a bit. Then set CCRB0 to 8000 and
> set the interrupt. If you need to set pins you can use the built in pin
> control, else simply handle this in the ISR. the reason your code isn't
> working is because you need to keep resetting the CCRA1 register at
> every interrupt, ie CCRA1 += 32, otherwise you only get what you're
> seeing, a single interrupt after the timer has rolled over and clocked
> back around to 32.

Hi Al

I cannot use Timer A because it's already running for another application, so only Timer B is available to generate both frequencies.

Regarding the reset, I think is really something related to it. I did some tests like you said, but it generates 1KHz (TIMERB1) just at the begining and then TIMERB1 stops when 1Hz (TIMERB0) goes to second cycle. Is there any other idea to keep running in a infinite loop?

Reply by kelsonbatista April 21, 20112011-04-21
> Are you sure your ISR are correct ? CCR0 and CCR1 use a different vector

Yes, the ISR's are corret.

Reply by Devin Auclair April 20, 20112011-04-20
Not related to your specific question, but on some other processors you need
to count to 32768-1, because 0 counts. That is, the timer counts from 0 to
32767 to get 32768 distinct pulses, not 1 to 32768. I don't have the data
sheet in front of me to decode your mode, but something to verify.

Devin
Reply by Ken Bueltmann April 20, 20112011-04-20
which chip are you employing?
Reply by Onestone April 20, 20112011-04-20
For a start you have not chosen your timer allocation wisely from the
information given. If you have a timer B then you have a timer A. In
this case I would set timer A to source from ACLK and timer b to source
from MCLK. then set timer A up pretty much as you have for your 1 second
timebase. next set Timer B up for continuous running, using the count to
mode inhibits timer flexibility quite a bit. Then set CCRB0 to 8000 and
set the interrupt. If you need to set pins you can use the built in pin
control, else simply handle this in the ISR. the reason your code isn't
working is because you need to keep resetting the CCRA1 register at
every interrupt, ie CCRA1 += 32, otherwise you only get what you're
seeing, a single interrupt after the timer has rolled over and clocked
back around to 32.

Cheers

Al