Control TOUT1 Directly

Discussion to talk about hardware related topics only.
Post Reply
DBrunermer
Posts: 67
Joined: Thu Apr 21, 2011 7:06 am
Location: Pittsburgh, PA

Control TOUT1 Directly

Post 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.
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Control TOUT1 Directly

Post 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
DBrunermer
Posts: 67
Joined: Thu Apr 21, 2011 7:06 am
Location: Pittsburgh, PA

Re: Control TOUT1 Directly

Post 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.
User avatar
lgitlitz
Posts: 331
Joined: Wed Apr 23, 2008 11:43 am
Location: San Diego, CA
Contact:

Re: Control TOUT1 Directly

Post 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.
DBrunermer
Posts: 67
Joined: Thu Apr 21, 2011 7:06 am
Location: Pittsburgh, PA

Re: Control TOUT1 Directly

Post by DBrunermer »

That's an interesting idea. I'll play around with that.
Thanks,
Dan B.
DBrunermer
Posts: 67
Joined: Thu Apr 21, 2011 7:06 am
Location: Pittsburgh, PA

Re: Control TOUT1 Directly

Post 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.
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Control TOUT1 Directly

Post 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.
Post Reply