Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem with PWM on attiny84

 
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
gertc

Bascom Member



Joined: 06 May 2006
Posts: 88

canada.gif
PostPosted: Fri Aug 29, 2014 8:12 pm    Post subject: Problem with PWM on attiny84 Reply with quote

I am going to use a PWM signal for creating a DAC output. but first I have to get the PWM working. I have read most of the
forums related to PWM issues, and can't see anything wrong with the code. Tried several chips (ATTINY84A)

Here is the bare bone code: (Similar to what is shown in the help files and what others has posted)
Code:
$regfile = "attiny84.DAT"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40


Config Portb.2 = Output       'pin5
Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Down
Start Timer0

Do
  Pwm0a = 500
Loop

End


Nothing shows on the scope, and when looking at pin5 with a logic probe, it looks like the output is in tri-state mode

What am I doing wrong?
thanks,
gerryc

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2264

blank.gif
PostPosted: Fri Aug 29, 2014 8:38 pm    Post subject: Reply with quote

Do you really believe a compare match value of 500 is suitable for an 8-bit timer with max count value of 255?
Edit:
And move setting of OCR0A in front of the loop.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5928
Location: Holland

blank.gif
PostPosted: Fri Aug 29, 2014 10:20 pm    Post subject: Reply with quote

the only thing i could find is that the data direction is not set by the compiler for portb.2 and porta.7. i did add that now.
i see in your code you set portb.2 to output manual. you need to do the same for porta.7
and as MWS says, 500 is not what you get. this will be AND-ed with 255 which will be &HF4.

_________________
Mark
Back to top
View user's profile Visit poster's website
gertc

Bascom Member



Joined: 06 May 2006
Posts: 88

canada.gif
PostPosted: Tue Sep 02, 2014 12:37 am    Post subject: Reply with quote

Stupid mistake. I changed the max count, now 200

I got it working now..... I always has the SPI cable from the STK500 connected to my board when debugging without any problem. Now, to get it working, I have to disconnect the SPI cable after programming, and then toggle the power off/on to the cpu. No Idea why.

Are there any reason that I have to set porta.7 as well? It works without doing it. (I need that extra ADC input)

thanks,
gerryc
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