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
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: 62209
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