Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
doctek
PostPosted: Mar 18, 2009 - 11:39 PM
Wannabe


Joined: Jun 10, 2007
Posts: 53


Using AVR Timer/Counters: Pulse Width Modulation Modes


OK Freaks, thanks for your responses and suggestions after my plea (below). I've reposted the whole enchilada as a pdf with the code and makefile in a zip.

Please note: You have to log in if you want to be able to download the files and read the tutorial!

Does this work for everyone??


I'll wait a few days for comments and either repost (with a complete tutorial, or delete this and go to Instructables.


Last edited by doctek on Mar 27, 2009 - 05:06 PM; edited 4 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
zphere
PostPosted: Mar 20, 2009 - 04:02 AM
Newbie


Joined: May 31, 2008
Posts: 18


Hi,
Thanks for the write up.

To answer your question, I would like to see a well commented, reasonably monolithic code example showing the usage of the pwm hardware.

Such an example could include the initialization of the pwm hardware, selecting prescalers (and the like) based on appropriate criteria (F_CPU being the most obvious), mode selection, output pin, duty cycle, frequency, hooking interrupts at various times in the cycle.. and so on and so forth.

ex; One large code block with many of the commonly used features represented, comments describing what each one does, and where features are mutually exclusive, only one is uncommented. The comments could also include datasheet page numbers to review for additional details.

I've always found it easier to start with something that is working, modify it, pick it apart, and learn from it while referencing a tutorial or the datasheet. The datasheet is horribly lacking a code segment pulling together and example of the usage of the hardware it is describing in the section - unless I'm just missing it. 350 pages, and very little example code.


Oh, and whatever you do, don't waste your time at Instructables. They've really gone down hill lately. So many things are turning into "Membership Benefit!"s. First we lost viewing all steps on one page, now you cannot view the other images posted for a step w/o logging in. Before long, all a person will be able to do (w/o logging in,) will be viewing the abstract of the instructable.

I'd rather not read a paragraph or two, then click on the Next button and wait for another page load just to read the next two paragraphs. Put the whole thing on one page, and remove the clutter from the rest of the page.

-Thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
doctek
PostPosted: Mar 20, 2009 - 09:31 PM
Wannabe


Joined: Jun 10, 2007
Posts: 53


Thanks for the excellent response, zphere. Hopefully, I'll get a few more opinions on this as well.

The sort of tutorial you're asking for is exactly what I have prepared and am trying to post. The first few parts that make up the posting so far are admittedly wordy, but provide the necessary background to understand the PWM modes. Not only do I have more detailed info on the PWM modes, but I have an example program that shows the modes in action and can be easily plagiarized for your own purposes. ("Show me a good programmer and I'll show you a good plagiarizer!")

I think you're a little harsh with Instructables. Your points are well taken, but here're a few counterpoints.

What's wrong with logging in? After all, we have to login in to Freaks to post, to see the Projects, and even to see the Figures that I included with my first post.

Yes, you have to click to see the next section, but you can always download the pdf version.

Finally, for the poster, Instructables handles uploaded code, figures, and files much better than whatever Forum Software it is that Freaks uses.

So here's what I'm thinking: I will actually post the Tutorial as several separate posts - one section (and no more than 3 figures or files each). I think this will work.

An alternative is to put the code, figures and diagrams in the Projects section. So a reader could download them, then read the Tutorial itself.

Any opinions or suggestions??

Thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Mar 21, 2009 - 12:37 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

An alternative is to put the code, figures and diagrams in the Projects section. So a reader could download them, then read the Tutorial itself.

Too complex - the best bet is to put the whole thing into a .PDF and attach it to a post here. (use CutePDF is you need a free PDF "printer")

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
doctek
PostPosted: Mar 21, 2009 - 06:00 PM
Wannabe


Joined: Jun 10, 2007
Posts: 53


Sounds like a good idea, I'll try it. It'll take a few hours to get the file all put together, then I'll post it.

In the mean time, I've noticed an error in the Makefile lines to enable the Clock Output. Don't use the code in my first post - I'll correct it in the new one.

Thanks again for the suggestion.
 
 View user's profile Send private message  
Reply with quote Back to top
zbaird
PostPosted: Mar 22, 2009 - 03:42 AM
Raving lunatic


Joined: Aug 13, 2006
Posts: 6711
Location: Bellingham, WA - USA

Quote:
Don't use the code in my first post - I'll correct it in the new one.

Edit any changes into earlier posts, too, since not everyone will read through the entire thread.

_________________
Chuck Baird
"It's better to catch the trapeze than test the safety net" -- RPi book
http://www.cbaird.org
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
doctek
PostPosted: Mar 22, 2009 - 04:21 AM
Wannabe


Joined: Jun 10, 2007
Posts: 53


Done - Corrections are in the original posting.
 
 View user's profile Send private message  
Reply with quote Back to top
doctek
PostPosted: Mar 24, 2009 - 06:16 PM
Wannabe


Joined: Jun 10, 2007
Posts: 53


All comments prior to this one were to the original (partial)post. Comments after this should be to the new pdf version and to the code that goes with it.

Hopefully, the pdf approach will be satisfactory! Thanks for your patience.
 
 View user's profile Send private message  
Reply with quote Back to top
MatrixIPN
PostPosted: Mar 29, 2009 - 07:55 PM
Newbie


Joined: Aug 30, 2008
Posts: 1


Thank's man now eat your whole enchilada and a few taquitos, thanks a lot
 
 View user's profile Send private message  
Reply with quote Back to top
simpsonss
PostPosted: Apr 21, 2009 - 08:37 AM
Rookie


Joined: Aug 11, 2008
Posts: 42


Thousand of thanks to u.great job man.
 
 View user's profile Send private message  
Reply with quote Back to top
ichionid
PostPosted: May 07, 2009 - 11:12 AM
Rookie


Joined: Aug 24, 2007
Posts: 35


Your tutorial along with deans, are the best recipe for PWM!Very HappyVery Happy
 
 View user's profile Send private message  
Reply with quote Back to top
lautman
PostPosted: May 09, 2009 - 07:17 AM
Hangaround


Joined: Apr 01, 2003
Posts: 186


Excellent tutorial (though I'm still mulling it over; my own app requires timer 0, so no frequency correct mode, making the examples a little less applicable for me). I did notice a mistake in Fig. 4 (p. 8): OC1A goes low when COUNT equals OCR1A and high when COUNT equals ICR1 (TOP). Text on p. 7 says, "When the COUNT is equal to the value in OCR1A, the output on OC1A will go high. As soon as the count reaches TOP, OC1A will be cleared." Sounds like just the opposite of what's shown. I know the output may easily be inverted, but the text should match the diagram.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
doctek
PostPosted: May 14, 2009 - 05:30 PM
Wannabe


Joined: Jun 10, 2007
Posts: 53


If you're using just timer 0, then you have just Phase Correct Mode available. Since this mode offers the main advantages of Phase & Frequency Correct Mode, you'll be just fine and the examples I give should be fully applicable. In fact, I couldn't really come up with a good demo of P&F Mode vs. Phase Correct Mode only. P&F only helps if the behavior during a frequency transition is of great importance - usually it isn't. If you use Phase Correct Mode only in the examples I provide, you'll find the behavior is identical.

As far as Fig. 4 vs. the text, you are correct on both points. The text *should indeed* match the figure (sorry about that); and the behavior can be easily inverted. (Maybe that's what I was trying to illustrate and just didn't realize it? Smile}

HTH.
 
 View user's profile Send private message  
Reply with quote Back to top
munish4u911ex
PostPosted: May 27, 2009 - 12:37 PM
Newbie


Joined: Mar 10, 2009
Posts: 14


Hi all,
seems everybody's using OC1A here... I have also tried to set pwm on OC1B of mega8 but it didn't work.
The (working) code I made for OC1A was:
Code:
void pwm_set_1A(unsigned char pulse_width)
{
DDRB |= (1<<1);         //Port B.1 as o/p (OC1A)
OCR1AL = pulse_width;   //Load Pulse width
OCR1AH = 0;
TCCR1A=((1<<COM1A1)&~(1<<COM1A0)|(1<<WGM10)&(~(1<<WGM11))); //8-bit, Non-Inverted PWM
//just a harder way to write TCCR1A = 0x81 :D
TCCR1B = 1<<CS10;             //Start PWM
}

Now, it works. Problem is with getting OC1B to work:
Code:

void pwm_set_1B(unsigned char pulse_width)
{
DDRB |= (1<<2);         //Port B.2 as o/p (OC1B)
OCR1BL = pulse_width;   //Load Pulse width
OCR1BH = 0;
TCCR1A = ((1<<COM1B1)&~(1<<COM1B0));//|(~(1<<WGM13)&(1<<WGM12))); //8-bit, Non-Inverted PWM
TCCR1B = ((1<<WGM12)&~(1<<WGM13));

TCCR1B = 1<<CS10;             //Start PWM
}
I am using these in:
Code:

while(1)
{      
   for(unsigned char i=0; i<0xff; i++)
   {pwm_set_1B(i); //pwm_set_1A(i) works here
   _delay_ms(5);
   }
   for(unsigned char i=0xff; i>0; i--)
   {pwm_set_1B(i);   
   _delay_ms(5);
   }
}
when I run it in Proteus, nothing comes on OC1B. Am I setting TCCR1A & TCCR1B the correct way??
Kind suggestions please...
-Regards,
Munish Rolling Eyes
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: May 27, 2009 - 12:38 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

Kind suggestions please...

How do you know Proteus simulates correctly?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
munish4u911ex
PostPosted: May 27, 2009 - 12:41 PM
Newbie


Joined: Mar 10, 2009
Posts: 14


Coz it is simulating OC1A correctly! and in hardware also I have connected 2 LEDs to both the OCs. OC1A lights (dims) its respective LED, while OC1B doesnt.

_________________
-
Regards,
Munish
 
 View user's profile Send private message  
Reply with quote Back to top
doctek
PostPosted: May 29, 2009 - 04:16 AM
Wannabe


Joined: Jun 10, 2007
Posts: 53


Looks to me like you aren't really doing the same things to make OC1B like OC1A.
- You're making TCCR1A equal to just 1<<COM1B1. The setting of (1<<WGM10)&(~(1<<WGM11) is lost.
- Setting TCCR1B to (1<<WGM12)&(~(1<<WGM13) would select CTC mode. (See the Waveform Generation Mode Bit Description Table.)
- But that doesn't even happen since you then make TCCR1B equal to 1<<CS10 and wipe out the value of the other bits in TCCR1B.

Try this:
Code:

void pwm_set_1B(unsigned char pulse_width)
{
DDRB |= (1<<2);         //Port B.2 as o/p (OC1B)
OCR1BL = pulse_width;   //Load Pulse width
OCR1BH = 0;
TCCR1A = (1<<COM1B1) |(1<<WGM10)); //8-bit, Non-Inverted PWM

TCCR1B = 1<<CS10;             //Start PWM
}


If you OR in the command to enable OC1B, you can keep OC1A running as well.
 
 View user's profile Send private message  
Reply with quote Back to top
limseckhoung
PostPosted: Sep 27, 2009 - 11:22 AM
Newbie


Joined: Sep 09, 2009
Posts: 10
Location: Penang, Malaysia

Thank you for the great+detail+ easy to understand tutorial!! Really helped me!! =)
 
 View user's profile Send private message  
Reply with quote Back to top
aghabro
PostPosted: Sep 27, 2009 - 01:08 PM
Newbie


Joined: Sep 27, 2009
Posts: 1


Dear guyz i m getting a crrupeted zip from the link geven above? wht shld i do now?
 
 View user's profile Send private message  
Reply with quote Back to top
divclonera
PostPosted: Sep 27, 2009 - 11:56 PM
Newbie


Joined: Sep 27, 2009
Posts: 1


is anyone one here writing bascom scripts for atmega48? This looks like all greek to me. I would pay someone to compile me a script.
 
 View user's profile Send private message  
Reply with quote Back to top
doctek
PostPosted: Sep 28, 2009 - 05:21 AM
Wannabe


Joined: Jun 10, 2007
Posts: 53


Quote:
Dear guyz i m getting a crrupeted zip from the link geven above? wht shld i do now?


I just downloaded the zip file myself and it came in just fine. Maybe try again??

Quote:
is anyone one here writing bascom scripts for atmega48?


Sorry, I don't do bascom. Maybe someone else would be interested?

HTH.
 
 View user's profile Send private message  
Reply with quote Back to top
abohmaid
PostPosted: Sep 02, 2010 - 02:28 AM
Newbie


Joined: Aug 26, 2010
Posts: 15
Location: Egypt

thank you doctec.[b]
 
 View user's profile Send private message  
Reply with quote Back to top
seasick
PostPosted: Sep 05, 2010 - 10:23 AM
Rookie


Joined: Mar 04, 2010
Posts: 31


great tutorial. thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
bolterX
PostPosted: Sep 20, 2010 - 07:39 AM
Newbie


Joined: Sep 20, 2010
Posts: 1


i cant download the link either...the download never starts....can you upload it again please?
 
 View user's profile Send private message  
Reply with quote Back to top
dipszee
PostPosted: Oct 02, 2010 - 09:57 AM
Newbie


Joined: Oct 02, 2010
Posts: 1


bolterX wrote:
i cant download the link either...the download never starts....can you upload it again please?
I cant download it either Sad can you please put it again? thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Oct 02, 2010 - 02:29 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

As folks seem to have problems with the two files in the first post I've re-hosted them on my website here:

http://www.wrightflyer.co.uk/CT_Examples.zip
http://www.wrightflyer.co.uk/Using%20AVR%20Counter.pdf

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
doctek
PostPosted: Oct 05, 2010 - 06:19 AM
Wannabe


Joined: Jun 10, 2007
Posts: 53


Thanks for re-hosting the files, but I really can't figure out the problem. I just tried again to download them and they came down with no problem. People do understand they have to log in, right? That's the only thing I can think of that might be wrong.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Oct 05, 2010 - 10:01 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

Yeah it's odd - the very fact that I've rehosted them means I went to the first post and downloaded them - it worked for me. I would agree that the posters to this thread probably weren't logged in when they tried to download them EXCEPT that to post here they have to be logged in?!? (unless they try to download when not logged in then actually log in to post without bothering to try and download again?)

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
lavared
PostPosted: Jul 14, 2011 - 05:01 PM
Newbie


Joined: Oct 14, 2010
Posts: 3


Hi
I'm not able to download the pdf writeup. It abruptly stops after a while downloading. Please send me one if somebody has it.

thanks
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jul 14, 2011 - 05:16 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

It abruptly stops after a while downloading. Please send me one if somebody has it.


Did you try my link above:

http://www.wrightflyer.co.uk/Using%20AVR%20Counter.pdf

I just downloaded the one from the first post and refreshed that to make sure it's up to date - works for me.

Cliff

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
lavared
PostPosted: Jul 14, 2011 - 05:29 PM
Newbie


Joined: Oct 14, 2010
Posts: 3


thanks it did work for me.
 
 View user's profile Send private message  
Reply with quote Back to top
tuskk98
PostPosted: Jul 31, 2011 - 01:48 PM
Newbie


Joined: Jul 18, 2011
Posts: 6
Location: Croatia

I have a question concerning PWM. I've read the tutorials and i have a question. Maybe it's written in the tutorial but i either missed it or failed to understand.

if i set a counter to Phase correct PWM and counting to top(0xff in 8 bit counter) and set OCR1A(e.g.) to 0 what kind of wave will be generated on OC1A if i specified that it is reset on count up and set on count down.

_________________
"If what you have done yesterday still looks big to you, you haven't done much today. - Mikhail Gorbachev"
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Jul 31, 2011 - 05:20 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13852
Location: Vancouver, BC

In the data sheet under the timer mode you are interested in there will be a statement something like this:
Quote:
The extreme values for the OCR0A Register represent special cases when generating a PWM waveform output in the phase correct PWM mode. If the OCR0A is set equal to BOTTOM, the output will be continuously low and if set equal to MAX the output will be continuously high for non-inverted PWM mode. For inverted PWM the output will have the opposite logic values.
Be sure to check the data sheet of the AVR that you are using since this might not be the same for all models, and it certainly is not the same for all modes.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
tuskk98
PostPosted: Jul 31, 2011 - 09:47 PM
Newbie


Joined: Jul 18, 2011
Posts: 6
Location: Croatia

Thank you. It says exactly the same. i menaged not to see it somehow :S

_________________
"If what you have done yesterday still looks big to you, you haven't done much today. - Mikhail Gorbachev"
 
 View user's profile Send private message  
Reply with quote Back to top
jzb81
PostPosted: Jan 27, 2012 - 04:12 AM
Newbie


Joined: Jan 27, 2012
Posts: 1
Location: Mexico

Thank you,goodtutorial
 
 View user's profile Send private message  
Reply with quote Back to top
franziski
PostPosted: May 01, 2012 - 08:03 AM
Hangaround


Joined: Feb 04, 2007
Posts: 125
Location: Naples province, Southern Italy

Figure 8 (Correction Phase/Frequency PWM) seems to fix.
I know: greater OCRxA/B, greater duty cicle (not inverted mode).

_________________
My (HW && SW) Setup: (MyAVR USB Programmer | bread-board | Butterfly | Arduino 10k | ATtiny2313 | ATmega8) && (WinAVR | AVR asm | AVRstudio)
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: May 01, 2012 - 03:31 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13852
Location: Vancouver, BC

Your post is very unclear, but if you mean that you think the diagram does not match the code, you are wrong. The code has the output being set on up-count and clear on down count, which means that the duty cycle decreases when OCRxA/OCRxB increases.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
franziski
PostPosted: May 02, 2012 - 08:48 AM
Hangaround


Joined: Feb 04, 2007
Posts: 125
Location: Naples province, Southern Italy

Koshchi wrote:
The code has the output being set on up-count and clear on down count, which means that the duty cycle decreases when OCRxA/OCRxB increases.


Yes, in the last example (P&F corrected PWM) it uses "inverted mode" in source code (instead of "not inverted mode" used previously) but without inform the reader.

_________________
My (HW && SW) Setup: (MyAVR USB Programmer | bread-board | Butterfly | Arduino 10k | ATtiny2313 | ATmega8) && (WinAVR | AVR asm | AVRstudio)
 
 View user's profile Send private message  
Reply with quote Back to top
electronic.designer
PostPosted: May 07, 2012 - 10:54 AM
Hangaround


Joined: May 27, 2010
Posts: 396
Location: The land of Cyrus the Great

It may be useful to know that there is a general problem on word BOTTOM in AVR datasheets when describing the time of OCRx update and setting timer overflow flag.
In fast pwm mode, updating OCRx at BOTTOM means "updating OCRx when entering the BOTTOM (at the same timer clock cycle as the TCNTx is cleared)".
But in phase-frequency correct pwm mode, updating OCRx at BOTTOM means " updating OCRx when leaving the BOTTOM (at the same timer clock cycle as the TCNTx is going from BOTTOM to BOTTOM +1)".
Also timer overflow flag is set when moving from MAX or TOP to BOTTOM (entering zero) in normal, CTC and fast pwm modes.
But this is not the case for phase correct and phase-frequency correct pwm modes and the overflow flag is set when moving from BOTTOM to BOTTOM+1 (leaving zero and entering 1).
Therefore by assuming TCNTx=0, only one clock will set the overflow flag in phase-frequency correct pwm mode, because of moving TCNTx from BOTTOM to BOTTOM+1.
Atmel simply writes "BOTTOM" for all timer modes. I have informed atmel support about this problem but:
Quote:
Dear Customer,

The word "BOTTOM" in timer context refers to the lowest possible count in the timer which is 0x00. In all the timer modes, the overflow flag will be set after the timer reaches the TOP value. Can you please specify the datasheet and the section where you found the discrepancy?

Apparently, they need to read their datasheets at first.

_________________
Ozhan K.
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: May 08, 2012 - 07:01 AM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13852
Location: Vancouver, BC

The overflow flag is always set on the clock after the specified value (TOP or BOTTOM) is reached. This is the same in all cases, so I don't believe that there is an inconsistency here. However, the update of OCRxx for Fast PWM should be TOP to be consistent, especially since the overflow and the update happen on the same clock.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
electronic.designer
PostPosted: May 22, 2012 - 03:19 PM
Hangaround


Joined: May 27, 2010
Posts: 396
Location: The land of Cyrus the Great

Final atmel response (after a long time):

Quote:
We are able to confirm that the OCR register is updated when TCNT=BOTTOM+1 in the phase and frequency correct PWM mode. We’ll post a bug in the datasheet regarding the same and we assure you that this will be corrected in the subsequent versions. Thank you taking time to report the same.

_________________
Ozhan K.
 
 View user's profile Send private message  
Reply with quote Back to top
badbaud
PostPosted: Jun 11, 2012 - 04:07 AM
Wannabe


Joined: Feb 23, 2011
Posts: 84


I'm trying to translate all of this (your tutorial) into assembly for the ATTiny85 and can't wrap my aged brain around the 'C' code examples you give. In fact I can't find anyone who has coded PWM functions in assembly.
If you know of anyone that has coded PWM for motor speed control in assembly and has posted some examples please let me know.

FYI the 2313 now has table 46 on page 106 (not 110) in their latest datasheet.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jun 11, 2012 - 09:20 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

can't wrap my aged brain around the 'C' code examples you give

When setting up timers the only C involved is pretty much
Code:
SFR = val;

which directly translates to something like
Code:
LDI R16, val
OUT SFR, R15

so translating his C should be simple. I guess the only complication is his use of the _BV() macro and the fact he uses |= (OR with existing) and &= (AND with exitin, so when he uses code such as:
Code:
#define PORT_CT   PORTB
#define DDR_CT   DDRB
#define   CT1A   PB3      // OC1A
#define   CT1B   PB4      // OC1B

   DDR_CT |= _BV(CT1A) | _BV(CT1B) ;   /* Enable CT1 output pins */
   PORT_CT &= ~(_BV(CT1A) | _BV(CT1B));     /* Set them to lo - LEDs off */

I guess the direct equivalent is:
Code:
#define PORT_CT   PORTB
#define DDR_CT   DDRB
#define   CT1A   PB3      // OC1A
#define   CT1B   PB4      // OC1B
#define _BV(n) (1 << n)

IN R16, DDR_CT
ORI R16, _BV(CT1A) | _BV(CT1B)
OUT DDR_CT, R16

IN R16, PORT_CT
LDI R17, _BV(CT1A) | _BV(CT1B)
COM R17
AND R16, R17
OUT PORT_CT, R16

(there may be a way to invert R17 at assemle time instead of my COM R17 but I'm afraid I don't know the Atmel assembler that well).

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
badbaud
PostPosted: Jun 11, 2012 - 10:33 AM
Wannabe


Joined: Feb 23, 2011
Posts: 84


I didn't see the BV relationship either, thanks for pointing it out.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits