Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

No PWM output on OC1B

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
gertc

Bascom Member



Joined: 06 May 2006
Posts: 88

canada.gif
PostPosted: Wed Feb 07, 2018 11:52 pm    Post subject: No PWM output on OC1B Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1544

blank.gif
PostPosted: Thu Feb 08, 2018 5:08 am    Post subject: Re: No PWM output on OC1B Reply with quote

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
View user's profile
gertc

Bascom Member



Joined: 06 May 2006
Posts: 88

canada.gif
PostPosted: Thu Feb 08, 2018 11:05 pm    Post subject: Reply with quote

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
View user's profile
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 230
Location: Berlin

germany.gif
PostPosted: Thu Feb 08, 2018 11:54 pm    Post subject: Reply with quote

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
View user's profile
gertc

Bascom Member



Joined: 06 May 2006
Posts: 88

canada.gif
PostPosted: Fri Feb 09, 2018 12:15 am    Post subject: Reply with quote

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
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 138
Location: D.F.

mexico.gif
PostPosted: Fri Feb 09, 2018 12:46 am    Post subject: Reply with quote

Good I did a test for atmega16 are you correct or not? Shocked

Code:
$regfile = "m16adef.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32




'OC1A Pin 19
Config Portd.5 = Output
'OC1B pin 18
Config Portd.4 = Output



Config Timer1 = Pwm , Prescale = 1 , Pwm = 10 , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_up
'08 bit
Tccr1a.5 = 1 : Tccr1a.5 = 0 : Tccr1b.4 = 0 : Tccr1b.4 = 0



Do
   Waitms 1000
   Pwm1a = 700
   Pwm1b = 400
   Toggle Portd.4
Loop
End
 
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4590
Location: Holland

blank.gif
PostPosted: Mon Feb 12, 2018 12:48 pm    Post subject: Reply with quote

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.

_________________
Best regards,

Mark Alberts
MCS Electronics

http://www.mcselec.com
Back to top
View user's profile Visit poster's website
gertc

Bascom Member



Joined: 06 May 2006
Posts: 88

canada.gif
PostPosted: Tue Feb 13, 2018 11:13 pm    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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