How to drive a PWM pin high?

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

 

I am using an XMEGA C3 Xplained board, and ASF, having setup port E pin 0 as a PWM output pin, and run a PWM sequence using pwm_init, pwm_start and pwm_stop; it works fine.
However, after the pwm_stop, the output is random high or low, and I need it to always be high when it stops. I have tried various ways to drive the pin high, but nothing seems to make any difference. It's just random.

What registers do I need to set, or what function call to make, to drive the pin high, after having used it as a PWM-output? 

I am a n00b with Atmel. ;)

Thanks, Thomas

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

Standard AVRs have some "Force" bits in the Compare Unit registers. Maybe XMega has similar?. Other solution might be to set the output register for that bit high, then turn off the PWM output which probably over-rides the pin setting. Take a look at Alternate Functions for General Purpose IO pins to see what options you have. Setting the output high, first, would avoid some glitches when the pin function is changed.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Hi

 

Thanx!

I found this in the manual, it sounds exactly like what I am looking for

CTRLC - Control Register C

Bit 3:0 – CMPx: Compare Output Value x
These bits allow direct access to the waveform generator's output compare value when the timer/counter is set in the
OFF state. This is used to set or clear the WG output value when the timer/counter is not running.

I'll give that a try and see what it gives

 

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

It worked!

 

But it was a mess accessing the CTRLC register through the ASF code. Well well, it works :)

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

thomasx wrote:
it was a mess accessing the CTRLC register through the ASF code.

ASF? Just say no!

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

clawson wrote:
ASF? Just say no!
yes +1

David (aka frog_jr)

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

What do you recommend instead?

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

Program the timer registers directly. A library like ASF has it's place for technologies that are too complex so that it's unlikely you'll work out what bits need to be set where to operate it (USB springs to mind) but for something simple like a timer just do it the same way we've all been programming timers and UARt and SPI and ADC and the like in mega/tiny for years and that is read the datasheet, understand how to operate the device in the mode you want then set the bits.