Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: pwm setup
PostPosted: Thu Feb 25, 2010 6:20 pm 
Offline

Joined: Wed Jan 07, 2009 6:56 pm
Posts: 5
Hi everyone,

I am using one of the PWM channels on my AT91sam7s64 to create a data packet. I wanted to have the channel sit low until I create the packet e.g. bit 1 = short high, long low x 2; bit= 0 short high, long low, long high, short low. Then afte packet is complete go back low.

I'm pretty sure I have set everything up correctly :wink::wink:
at initialisation I set CPOL = 1, DUTYCYCLE = 0 then enable the channel to make sure the channel sits low.

I enable the interrupt to update the duty cycle in the ISR and wait for the for the ISR to finish (using a flag) before loading my next value in.

Once I'm finished I set the DUTYCYCLE back to 0 and disable the interrupts.

I know i shouldn't be setting the DUTYCYCLE to 0 or to the period length but if I set it to a value in between won't I get a pulse I don't want?? My polarity is toggling which I assume is down to to the DUTYCYCLE = 0 when the interrupt is enabled.

Is there a particular method I should apply to achieve the behaviour I want?

1. initialise PWM (clocks, cpol etc) I enable the channel here....should I enable the channel and/or interrupts here?

2. Packet to be created & sent now. So I enable the interrupt and load values in then disable the interrupt when finished.

I repeat step 2 whenever a packet is to be sent.

am i missing something obvious?

Thanks

swilson


Top
 Profile  
 
 Post subject: Re: pwm setup
PostPosted: Fri Feb 26, 2010 7:21 pm 
Offline

Joined: Thu Feb 25, 2010 5:02 pm
Posts: 88
swilson1978 wrote:
Hi everyone,
I know i shouldn't be setting the DUTYCYCLE to 0 or to the period length but if I set it to a value in between won't I get a pulse I don't want?? My polarity is toggling which I assume is down to to the DUTYCYCLE = 0 when the interrupt is enabled.

Is there a particular method I should apply to achieve the behaviour I want?


You might try disabling the PWM and use the PIO to drive the output pin for duty cycles of zero.
Here is the pseudo code that shows how we utilize the PWM for this kind of setup.

Code:
// If the duty cycle is > 0 then set the duty cycle
if( dutyCycle_ > 0 )
{
    // Make sure the PWM channel is enabled

    // Set the PWM duty cycle

    // Make sure the PWM peripheral is on
}
// Otherwise the duty cycle is zero so disable the channel and peripheral and set
// the output using the PIO based on whether the duty cycle is inverted.
// Note: If the duty cycle is allowed to go to zero the duty cycle changes to
//       an invalid inverted state. This implementation prevents this from occuring and
//       operates as expected.
else
{
    // Disable the PWM channel

    // Enable the PIO and set the pin output

    // Turn off the PWM peripheral

}

_________________
Duane P. Fridley, IEEE CSDP
Viable Bytes, Inc.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: