View previous topic :: View next topic |
Author |
Message |
gertc
Joined: 06 May 2006 Posts: 88
|
Posted: Fri Aug 29, 2014 8:12 pm Post subject: Problem with PWM on attiny84 |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Aug 29, 2014 8:38 pm Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Aug 29, 2014 10:20 pm Post subject: |
|
|
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 |
|
|
gertc
Joined: 06 May 2006 Posts: 88
|
Posted: Tue Sep 02, 2014 12:37 am Post subject: |
|
|
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 |
|
|
|