View previous topic :: View next topic |
Author |
Message |
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Mon Feb 20, 2023 4:57 pm Post subject: Xmega 8/16/32E5 - Solved PWM |
|
|
The datasheet for the E5 series does show that PWM signals can be output directly to pins on PORTs C and D.
However, the current BASCOM compiler does not appear to have this function. Instead, this work-around was proposed in the samples:
Code: | $regfile = "xm32e5def.dat"
$crystal = 32000000 '32MHz
$hwstack = 64
$swstack = 40
$framesize = 40
Config Osc = Enabled , Pllosc = Enabled , Pllmul = 10
Config Sysclock = Pll , Prescalea = 1 , Prescalebc = 1_1
Config Priority = Static , Vector = Application , Lo = Enabled
Config Portd.4 = Output ' leds on the prototyep boards
Config Portd.5 = Output
Config Tcc4 = Pwm , Prescale = 1024 , Capmodeah = Both_enabled
Tcc4_per = 5000 ' set blink frequence
Tcc4_cca = 4990 ' set led on start time
On Tcc4_ovf Tc4_isr ' interrupt when count = period
On Tcc4_cca Myisr ' interrupt when timer = compare (CCA)
Enable Tcc4_ovf , Lo 'Enable overflow interrupt in LOW Priority
Enable Tcc4_cca , Lo 'Enable overflow interrupt in LOW Priority
Enable Interrupts
Do
!nop
Loop
End 'end program
'--------------------[Interrupt Service Routines]-------------------------------
Tc4_isr: ' overflow interrupt
Toggle Portd.4 ' change status led D4
Set Portd.5 ' led D5 is Off (ON by pull-down)
Tcc4_intflags.0 = 1 ' clear interrupt flag
Return
Myisr:
Reset Portd.5 ' led D5 is OFF(off by pull-down)
Return |
It seems the configuration statement CONFIG TCC4 = PWM ... etc., does not have any effect on the relevant registers. Test code is shown here:
Code: | $regfile = "xm32e5def.dat"
$hwstack = 127
$swstack = 127
$framesize = 127
$crystal = 32000000
Config Osc = Disabled , 32mhzosc = Enabled 'internal 2 MHz and 32 MHz enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 'use 32 MHz
'====================================================
'Soft UART
'====================================================
Open "COMD.6:57600,8,N,1" For Output As #2
'====================================================
' PWM Test - original
'====================================================
Config Portc = Output
'Config Tcc4 = Pwm , Prescale = 1024 , Capmodeah = Cap_enabled
Config Tcc4 = Pwm , Prescale = 1024 , Capmodeah = Comp_enabled
'Config Tcc4 = Pwm , Prescale = 1024 , Capmodeah = Both_enabled
'Changes to the CONFIG does not change the values of the Registers shown below.
Start TCC4 'Not needed or no function??
Tcc4_per = &HFFFF
Tcc4_cca = &H8000
Tcc4_ccb = &H8000
Tcc4_ccc = &H8000
Tcc4_ccd = &H8000
Print #2 , "PORTC Registers"
Print #2 , "==============="
Print #2 , "PORTC_REMAP " ; Bin(portc_remap)
Print #2 , "TCC4_CTRLA " ; Bin(tcc4_ctrla)
Print #2 , "TCC4_CCABF " ; Bin(tcc4_ccabuf)
Print #2 , "TCC4_CTRLB " ; Bin(tcc4_ctrlb)
Print #2 , "TCC4_CCBBF " ; Bin(tcc4_ccbbuf)
Print #2 , "TCC4_CTRLC " ; Bin(tcc4_ctrlc)
Print #2 , "TCC4_CCCBF " ; Bin(tcc4_cccbuf)
Print #2 , "TCC4_CTRLD " ; Bin(tcc4_ctrld)
Print #2 , "TCC4_CCDBF " ; Bin(tcc4_ccdbuf)
Print #2 , "TCC4_CTRLE " ; Bin(tcc4_ctrle)
Print #2 , "TCC4_CTRLF " ; Bin(tcc4_ctrlf)
Print #2 , "TCC4_CTRLGS " ; Bin(tcc4_ctrlgset)
End |
No output is created on PORTC0...3.
However, the datasheets suggests that the CTRLE register must be set.
Code: | $regfile = "xm32e5def.dat"
$hwstack = 127
$swstack = 127
$framesize = 127
$crystal = 32000000
Config Osc = Disabled , 32mhzosc = Enabled 'internal 2 MHz and 32 MHz enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 'use 32 MHz
'====================================================
'Soft UART
'====================================================
Open "COMD.6:57600,8,N,1" For Output As #2
'====================================================
' PWM Test - Solution
'====================================================
Config Portc = Output
'Config Tcc4 = Pwm , Prescale = 1024 , Capmodeah = Cap_enabled ', Comparea = Enabled
Config Tcc4 = Pwm , Prescale = 1024 , Capmodeah = Comp_enabled ', Comparea = Enabled
'Config Tcc4 = Pwm , Prescale = 1024 , Capmodeah = Both_enabled ', Comparea = Enabled
Tcc4_per = &HFFFF
Tcc4_cca = &H8000
Tcc4_ccb = &H8000
Tcc4_ccc = &H8000
Tcc4_ccd = &H8000
Tcc4_ctrle = &B01010101
Print #2 , "PORTC Registers"
Print #2 , "==============="
Print #2 , "PORTC_REMAP " ; Bin(portc_remap)
Print #2 , "TCC4_CTRLA " ; Bin(tcc4_ctrla)
Print #2 , "TCC4_CCABF " ; Bin(tcc4_ccabuf)
Print #2 , "TCC4_CTRLB " ; Bin(tcc4_ctrlb)
Print #2 , "TCC4_CCBBF " ; Bin(tcc4_ccbbuf)
Print #2 , "TCC4_CTRLC " ; Bin(tcc4_ctrlc)
Print #2 , "TCC4_CCCBF " ; Bin(tcc4_cccbuf)
Print #2 , "TCC4_CTRLD " ; Bin(tcc4_ctrld)
Print #2 , "TCC4_CCDBF " ; Bin(tcc4_ccdbuf)
Print #2 , "TCC4_CTRLE " ; Bin(tcc4_ctrle)
Print #2 , "TCC4_CTRLF " ; Bin(tcc4_ctrlf)
Print #2 , "TCC4_CTRLGS " ; Bin(tcc4_ctrlgset)
End |
This creates the proper output on PORTC0...3.
Also, the output can be moved to PORTC4...7 by using the REMAP Register:
Code: | Portc_remap = &B000_0_1111 |
Notes:
1) The Start TCC4 command does NOT seem to have any function?
2) Did not test TCC5.
E |
|
Back to top |
|
|
cyklop1977
Joined: 05 Jun 2011 Posts: 11
|
Posted: Tue May 16, 2023 9:37 am Post subject: |
|
|
Tcc4_ctrle = &B01010101
It is same result for:
PWM
CONFIG TCC4 = PWM , PRESCALE = 64 , CAPMODEAL = COMP_ENABLED , CAPMODEBL = COMP_ENABLED , CAPMODECL = COMP_ENABLED , CAPMODEDL = COMP_ENABLED , RESOLUTION = 16
and FREQ
CONFIG TCC4 = FREQ , PRESCALE = 1 , CAPMODEAL = COMP_ENABLED , CAPMODEBL = COMP_ENABLED , CAPMODECL = COMP_ENABLED , CAPMODEDL = COMP_ENABLED , RESOLUTION = 16 |
|
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
|
|