Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ATTINY806 PWM with TCB0 timer

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
digilabpg

Bascom Member



Joined: 22 Nov 2011
Posts: 3

PostPosted: Sun Jan 23, 2022 12:28 pm    Post subject: ATTINY806 PWM with TCB0 timer Reply with quote

Good morning,
I have this problem and I wanted to know if someone can help me, on an ATTINY806 I have to activate a PWM output on port A.5 using the TCB0 timer, unfortunately I can't get it to work, the TCA0 timer is already used for another use, I am attaching the code if anyone can help me,
thank you


Code:

'--------------------------------------------------------------------------------
'name                     : TCB0-PWM.bas
'copyright                : (c) 1995-2021, MCS Electronics
'purpose                  : demonstrates TCB0 PWM
'micro                    : xtiny806

'--------------------------------------------------------------------------------
$regfile = "atxtiny806.dat"
$crystal = 10000000
$hwstack = 64
$swstack = 64
$framesize = 64
'set the system clock and prescaler

'Config Submode = New

Config Sysclock = 16_20mhz , Prescale = 2 , Clockout = Disabled

'configure the USART
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1

Waitms 1000

'Print "Test TCA0"
Config Pina.5 = Output                                      'WO0 output
'Config Pinc.0 = Output                                      'WO0 output
Config Pina.4 = Output
Led Alias Porta.4


Tca0_per = 9766
Config Tca0 = , Prescale = 1024 , Ovf_int = Enabled , Run = On
On Tca0_ovf Timer_isr



Config Tcb0 = Pwm , Prescale = 2 , Ccmp_output = Enabled , Run = On
'Tcb0_ccmp = 320000                                          'PWM frequency (period)
Tcb0_ccmph = 64                                             ' no. of high cycles
Tcb0_ccmpl = 196
                                          '25% duty cycle on pin PB0 (WO0)
Dim Count_1 As Byte


Enable Interrupts


Do
   nop

Loop



Timer_isr:
   Tca0_intflags = 1
   Toggle Led
   Print "."
Return

 
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sun Jan 23, 2022 9:40 pm    Post subject: Reply with quote

since tcap and tcb0 share the same pin you need to put one of them on an alternative pin.

Code:
config portc.0=output
Config Port_mux = Overwrite , Tcb0_wo0 = Alt1_pc0
 


this will put WO of tcb0 on portc.0
look at the table 5-1 in the datasheet for alternative pins.

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

Bascom Member



Joined: 22 Nov 2011
Posts: 3

PostPosted: Mon Jan 24, 2022 9:55 pm    Post subject: Reply with quote

thanks for the answer but it seems not to work, is it possible that the TCB0 timer setting as PMW is wrong ?, thanks
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Jan 25, 2022 9:21 am    Post subject: Reply with quote

config seems ok.
you can try first without tcA0 to see if tcb0 has any output.

when it does, you could try to use an alternative output for TCA0.

i see some problems in the errata from microchip but nothing about this.

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

Bascom Member



Joined: 22 Nov 2011
Posts: 3

PostPosted: Mon Jan 31, 2022 11:23 pm    Post subject: Reply with quote

good morning, thanks for the answer, for now I use the TCA both as a TIMER and as a PWM, for now I have solved it, when I have a little more time I will do other tests, thanks.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here 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