View previous topic :: View next topic |
Author |
Message |
digilabpg
Joined: 22 Nov 2011 Posts: 3
|
Posted: Sun Jan 23, 2022 12:28 pm Post subject: ATTINY806 PWM with TCB0 timer |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sun Jan 23, 2022 9:40 pm Post subject: |
|
|
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 |
|
|
digilabpg
Joined: 22 Nov 2011 Posts: 3
|
Posted: Mon Jan 24, 2022 9:55 pm Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 25, 2022 9:21 am Post subject: |
|
|
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 |
|
|
digilabpg
Joined: 22 Nov 2011 Posts: 3
|
Posted: Mon Jan 31, 2022 11:23 pm Post subject: |
|
|
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 |
|
|
|