Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

pwm code problems with ATtiny13 and 15

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
jasreb

Bascom Member



Joined: 03 Dec 2004
Posts: 41

uk.gif
PostPosted: Fri Dec 03, 2004 11:34 pm    Post subject: pwm code problems with ATtiny13 and 15 Reply with quote

Has anyone had any luck using Bascom pwm with ATtiny15 or 13 devices? My code which works fine with 2313 will not compile on either Tiny13 or 15...

With Tiny15 (2 timers, 1 pwm) and following code:

Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 8

Pwm1a = 0 ' init pwm

I get error message:

Error : 46 Line : 47 Assignment error [PWM1A: 0 0: 112]

and using Tiny13 (1 timer, 2 pwms) and same code I get same error message, but Tiny13 only has 1 timer/counter, so I tried using

Config Timer0 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 8

Pwm1a = 0 ' init pwm

and I get error message:

Error : 86 Line : 48 Invalid parameter for TIMER configuration [PWM = 8]
Error : 46 Line : 50 Assignment error [PWM1A: 0 0: 112]

Is the problem something I'm doing wrong, or is pwm for ATiny13/15 devices not implemented correctly (yet) in Bascom AVR?

thanks in advance for any advice

Jason
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sat Dec 04, 2004 2:34 pm    Post subject: Reply with quote

hi,
on the T13 and T15 you don't have timer1 (16 bit)
you have it, on the Tiny2313
JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
jasreb

Bascom Member



Joined: 03 Dec 2004
Posts: 41

uk.gif
PostPosted: Sat Dec 04, 2004 5:01 pm    Post subject: Reply with quote

Hi

I know there's only 8-bit timer, I assume this is called "timer0"?

Whatever, question is still how can you use Bascom pwm command with Tiny13/15? The device hardware supports pwm, 1 on Tiny15 and 2 on Tiny13, just Bascom does not want to compile it..?

(I prefer to use smd 8pin package, which is why I want to use Tiny13 or 15, and I need ADC so 2343 or Tiny22 are not suitable, nor do they have hardware pwm).

Jason
Back to top
View user's profile
jasreb

Bascom Member



Joined: 03 Dec 2004
Posts: 41

uk.gif
PostPosted: Tue Dec 07, 2004 12:01 pm    Post subject: Reply with quote

Hi again

So does anyone know correct syntax to use Bascom pwm with ATtiny13? It won't compile for me. It would save me having to code my pwm by hand, seems a bit silly if the device has one sitting there and I could just be using "pwm1a=xxx" etc ...

I think there might be a prob with the ATtiny13.dat file?

Jason
Back to top
View user's profile
jasreb

Bascom Member



Joined: 03 Dec 2004
Posts: 41

uk.gif
PostPosted: Tue Dec 07, 2004 12:22 pm    Post subject: Reply with quote

Shouldn't there be something in the ATtiny13.dat file like

OCR0A_PORT=PORTB.0 ; Output compare TIMER0A
OCR0B_PORT=PORTB.1 ; Output compare TIMER0B

or something, like there is the the dat files for other devices eg 2313 or Tiny2313? Right now there's nothing in there for OCR pins...

Jason
Back to top
View user's profile
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 948
Location: the Netherlands

netherlands.gif
PostPosted: Tue Dec 14, 2004 11:08 pm    Post subject: Reply with quote

Hi,

If i do you understand correctly you have found out that Bascom is not supporting the PWM in the Tiny13 at the moment.
This wil not say that you can't use the PWM's in Bascom.
Take a look at the datasheet at http://www.atmel.com/dyn/resources/prod_documents/doc2535.pdf and find the registers that do the job.
Just set the correct register and your PWM will work.
It is not the easyest way but surely very informative.

Frank.


Last edited by Frankeman on Thu Dec 16, 2004 5:15 pm; edited 1 time in total
Back to top
View user's profile
jasreb

Bascom Member



Joined: 03 Dec 2004
Posts: 41

uk.gif
PostPosted: Wed Dec 15, 2004 10:35 pm    Post subject: Reply with quote

Hello Frank, thanks for the reply. Do you know where I can find a sample of code to do this (for any device) - I'm not familiar with this syntax, ie do I need to config the timer first, then set the registers, or something else? (How do I set the prescaler for instance)

Thanks in advance for your advice!

Jason
Back to top
View user's profile
jasreb

Bascom Member



Joined: 03 Dec 2004
Posts: 41

uk.gif
PostPosted: Wed Jan 05, 2005 10:18 am    Post subject: Reply with quote

Still wondering - does anybody have any idea why Bascom 'pwm' does not work with ATtiny13? Is it just not implemented (yet) or am I missing something obvious?

Failing that, does anyone have some sample code to program it manually as Frankeman suggests?

thanks in advance...
Back to top
View user's profile
at90s2343

Bascom Member



Joined: 17 Nov 2004
Posts: 3

PostPosted: Fri Jan 14, 2005 12:43 pm    Post subject: Reply with quote

It's likely U have to do some bitbanging.

2 months ago I had the same problem with *fast copy* untill some friendly guy explained me a few things:

QUOTE
the TCCR0 Register doesnt longer exist int the Tiny13
Its divided in TCCR0A and TCCR0B.
The meaning of the Bits in TCCR0A is depend on the BitSettings of BIT3 in
TCCR0B.
The Lower Bits 0 to 2 in TCCR0B sets the prescaler.If these are Zero, the
Timer is stopped.
for the desired Function : PWM,8,Normal, Prescale1 you have to set:
TCCR0A=&b11000011 =&hC3 =195

To set the Prescaler and special PWM modes for timer0 (or stop it) you must
manipulate TCCR0B
and set in our example to:
TCCR0B=&b0000001 =1 for full speed(prescale=1)
TCCR0B=0 to stop the timer0

It should be noted, that Timer0 has two PWM-Channels. Channel B are not
affected in this Calculation.
the Bits 5 and 4 in the TCCR0A will handle this Channel. If you want to use
the Hardwarepin
(Channel A will be set here on Comparematch) You have to select the DDR Register as Output.
UNQUOTE

Try this in a demo version of *fast copy*, compile and have a look at the PINS of the attiny and the timer/counter in AVRSTUDIO. You'll see it works. Then try to re-arrange a few items and try it with BASAVR.

-----------------------------
TCCR0A=&b10000001 'Set oc0a on comparematch when DOWNcounting
TCCR0B=&b00000001 ' =1 for full speed(prescale=1)
Set DDRB.0
Ocr0a= 76
-------------------------------
The output pin goes 1 when timer is 76 and and goes 0 when 255. After reaching 255 it counts down again and makes output pin 1 when reaching 76...etc.

Good luck
at90s2343
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum