Page 1 of 1
Control TOUT1 Directly
Posted: Thu May 12, 2011 11:30 am
by DBrunermer
Hi,
I want to make a pin that goes on for a certain length of time, and I would like to do it using Timer 1 (TMR1). I want it to be in the mode where the pin toggles on terminal count. But, I want to set the pin high, arm the timer, and then have it turn off. And I don't want it to go high on its own, only when I tell it. I can't seem to figure out how to control the TOUT1 I/O pin directly.
Any help? Thank you,
Dan B.
Re: Control TOUT1 Directly
Posted: Thu May 12, 2011 2:16 pm
by tod
Dan,
Are we talking about the 5272? TOUT1 is multiplexed with PWM_OUT1. Di you use the Port D Control Register to set it up for TOUT1. See section 17.2.4 of the Freescale 5272 Manual (MCF5272UM.pdf) in your docs folder.
If this is all new to you and you don't understand how to do it, I recently posted a
blog entry on configuring the 5272 for RTS/CTS, while the port location is different the process is pretty similar. If that doesn't help let me know and I can give you more detailed instructions, teach a programmer to fish and all that...
Tod
Re: Control TOUT1 Directly
Posted: Fri May 13, 2011 4:50 am
by DBrunermer
Hi Tod,
Thanks for the reply. The part I was missing was the Port D. That said, I'm thinking that I must not be able to do it. In 17.2.4 the manual states that "Port D has no data register nor data direction register." I'm guessing that means there's no way to talk to the pin.
Thanks again,
Dan B.
Re: Control TOUT1 Directly
Posted: Fri May 13, 2011 10:50 am
by lgitlitz
It looks like that pin is also connected to the PWM2. It looks like you can set the PWM peripheral to be forced high when enabled and output low when disabled. This should allow you to manually control the pin by enabling and disabling the PWM. This would disable any automated control by the timer peripheral. Still you can use the pin as general purpose output if you want to toggle it in an interrupt generated by the timer.
Re: Control TOUT1 Directly
Posted: Fri May 13, 2011 12:33 pm
by DBrunermer
That's an interesting idea. I'll play around with that.
Thanks,
Dan B.
Re: Control TOUT1 Directly
Posted: Mon May 16, 2011 7:17 am
by DBrunermer
Hey! This is starting to work! At first it didn't, though, as I was confusing myself. The PWMs in the book are numbered 0, 1, and 2, while the sim. definition structure is 1, 2, and 3. So watch out for that if anyone else is trying this. I have a counting loop inside the interrupt, and it's providing me with enough accuracy for now.
Thanks for the help everyone! Dan B.
<UPDATE>
You also don't have to enable and disable it. If you just change the value of bit 5 in the control word (the 'state when disabled' bit), you can set the state while never enabling the PWM itself.
Re: Control TOUT1 Directly
Posted: Mon May 16, 2011 10:45 am
by tod
You edited out your question so you probably discovered the volatile keyword. Although at one point the -O2 optimization flag would mistakenly optimize away even volatile, I assume that has been fixed although I haven't tested it in a while.