View previous topic :: View next topic |
Author |
Message |
gertc
Joined: 06 May 2006 Posts: 88
|
Posted: Wed Feb 07, 2018 11:52 pm Post subject: No PWM output on OC1B |
|
|
Hello,
I am making an Digital to Analog conversion using PWM. Using OC1B I have no problem, but if I use OC1A I am not getting any PWM output.
Now back to the basic, using the code from the help file. Still the same problem
Am I missing something, or are there a bug in the compiler when using the ATtiny1634?
Here is 4 small test programs I tryed out:
Bascom Ver. 2.0.8.0
Code: |
$regfile = "attiny1634.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40
Config Portb.3 = Output 'OC1A pin 18 (ATtiny1634 SOIC)
Config Porta.6 = Output 'OC1B pin 3 (ATtiny1634 SOIC)
'---------------------------------------------------------------------------
' -- TEST 1 --
Config Timer1 = Pwm , Pwm = 10 , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_down , Prescale = 1
Enable Timer1
Start Timer1
Do
Waitms 1000
Pwm1a = 800 '4Khz on PORTB.3 (OC1A)
Pwm1b = 800 'Output High on PORTA.6 (OC1B)
Loop
'---------------------------------------------------------------------------
' -- TEST 2 --
Config Timer1 = Pwm , Pwm = 10 , Compare_b_pwm = Clear_up , Prescale = 1
Enable Timer1
Start Timer1
Do
Waitms 1000
Pwm1b = 800 'Output Low on PORTA.6 (OC1B)
Loop
'---------------------------------------------------------------------------
' -- TEST 3 --
Config Timer1 = Pwm , Pwm = 10 , Compare_b_pwm = Clear_down , Prescale = 1
Enable Timer1
Start Timer1
Do
Waitms 1000
Pwm1b = 800 'Output High on PORTA.6 (OC1B)
Loop
'---------------------------------------------------------------------------
' -- TEST 4 --
Config Timer1 = Pwm , Pwm = 10 , Compare_a_pwm = Clear_up , Prescale = 1
Enable Timer1
Start Timer1
Do
Waitms 1000
Pwm1a = 800 '4Khz on PORTB.3 (OC1A)
Toggle Porta.6 'PORTA.6 Toggling HI/LOW << PORT IS WORKING AS NORMALLY OUTPUT
Loop
|
(BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.8.1 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Feb 08, 2018 5:08 am Post subject: Re: No PWM output on OC1B |
|
|
gertc wrote: | Using OC1B I have no problem, but if I use OC1A I am not getting any PWM output. | Comments in your code tell the contrary, there OC1A is described to put out 4kHz. What is correct?
If you want to check whether registers are set correctly, simply print TCCR1A and TCCR1B to console and compare with the data sheet.
Alternatively run the simulator, write down these register values from the register overview, or do a print to the console and compare.
Why do you enable the timer interrupt without ISR btw.? Makes no sense. At least you don't enable interrupts generally, so it has no effect. |
|
Back to top |
|
|
gertc
Joined: 06 May 2006 Posts: 88
|
Posted: Thu Feb 08, 2018 11:05 pm Post subject: |
|
|
Hello MWS,
Thank you for your reply.
The text should have said: "Using OC1A I have no problem, but if I use OC1B I am not getting any PWM output."
When I run the program in the simmulator I get: TCCR1A = B3, and TCCR1B = 01
IF I change Compare_b_pwm to Clear_up then TCCR1A = A3, and TCCR1B = 01
Why does TCCR1A change, and not TCCR1B?
I looked at the data sheet, and to be honest, I am not quite shure what is going on
The code now looks as this:
Code: |
$sim
$regfile = "attiny1634.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40
Config Portb.3 = Output 'OC1A pin 18 (ATtiny1634 SOIC)
Config Porta.6 = Output 'OC1B pin 3 (ATtiny1634 SOIC)
Config Timer1 = Pwm , Pwm = 10 , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_down , Prescale = 1
Do
Waitms 1000
Pwm1a = 700 '4Khz on PORTB.3 (OC1A)
Pwm1b = 400 'Output High on PORTA.6 (OC1B)
Loop
|
|
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Thu Feb 08, 2018 11:54 pm Post subject: |
|
|
Hi,
as far I can see there is a bug in attiny1634.dat file (Version 2.0.8.0): the [WIO] - definition of OCR1B is not correct (should be $6a, not $2e), in [IOEXT] OCR1BL and OCR1BH is missing.
Please contact support and ask for a fix.
Quote: | Why does TCCR1A change, and not TCCR1B? |
Don't get control register and compare register wrong. the behavior of pwm pins is defined in TCCR1A only. |
|
Back to top |
|
|
gertc
Joined: 06 May 2006 Posts: 88
|
Posted: Fri Feb 09, 2018 12:15 am Post subject: |
|
|
Thanks,
Maybe not only the ATtiny1634. I tryed the same with an ATtiny4313, where also only OC1A works
Anyway, I will contact support as suggested.
Regards,
gerrysc |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Feb 12, 2018 12:48 pm Post subject: |
|
|
the 1634def. dat is derived from the atmel tn1634 file :
.equ OCR1BL = 0x2e
.equ OCR1BH = 0x2e
but.. the datasheet shows indeed a different address.
I think Tomi corrected this for 2081. And i checked the 2081 files and that is indeed the case.
I think we better derive from the atdf files in the future.
Notice that 1634 and 4313 are entirely different chips. _________________ Mark |
|
Back to top |
|
|
gertc
Joined: 06 May 2006 Posts: 88
|
Posted: Tue Feb 13, 2018 11:13 pm Post subject: |
|
|
Hello,
I installed ver. 2081, and everything works fine.
Sorry I didn't do that earlier.
Thanks for all the help.
gerrysc |
|
Back to top |
|
|
|
|
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
|
|