View previous topic :: View next topic |
Author |
Message |
balou
Joined: 14 Apr 2007 Posts: 36
|
Posted: Sun Sep 10, 2017 5:47 pm Post subject: Attiny4313 PWM problem |
|
|
Hi,
Sometimes the PWM signal is free running.
Measure port B.3 OC0A.
Bascom 2.0.8.0
What is wrong ?
Balou.
$regfile = "attiny4313.Dat"
$crystal = 8000000
$hwstack = 20
$swstack = 20
$framesize = 20
$baud = 9600
Config Pind.2 = Input '** IR **
Config Timer0 = Timer , Prescale = 256 '** 8000000/256=31250 Hz
Config Int0 = Falling '** Interruption on Falling
Stop Timer0
Enable Timer0
Enable Timer1
Enable Int0
Enable Interrupts
On Timer0 Tikers '** work on timer
On Int0 Infrared '** work on interruption
'******************* PWM Timer1 *****************
Config Timer1 = Pwm , Prescale = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up
'********* OC1A = B.3 / OC1B = B.4 **************
Dim Tik As Word 'counter of teaks of timer
Dim Byt As Byte 'counter accepted bit
Dim Repeat_flag As Bit 'flag of repetition
Dim Start_flag As Bit 'flag of start condition
Dim Address As Byte 'byte of address
Dim Command As Byte 'byte of command
Dim Address_1 As Byte 'direct byte of address
Dim Command_1 As Byte 'direct byte of command
Dim Address_0 As Byte 'indirect byte of address
Dim Command_0 As Byte 'indirect byte of command
'Dim Summa As Word
'**************************** Main program ***********************************************
Pwm1a = 0
Pwm1b = 0
Do 'Main cycle
Select Case Command
Case 90 : Pwm1a = Pwm1a + 10 '** Up B.3 **
Waitms 15
Case 16 : Pwm1a = Pwm1a - 10 '** Low B.3 **
Waitms 15
Case 152 '** Off "0" B.3/B.4 **
Pwm1a = 0
Pwm1b = 0
Waitms 10
End Select
Waitms 40
Loop
End 'End of main cycle
'############################# Timer0 ###########################################
Tikers: '** work on timer
Timer0 = 253 '** 31250/(256-253)=10416,66 Hz (96 een)
Incr Tik
If Tik >= 1200 Then '** if 1200 teaks, have thrown all in source condition
Tik = 0
Repeat_flag = 0
Start_flag = 0
Address_1 = 0
Command_1 = 0
Address_0 = 0
Command_0 = 0
Address = 0
Command = 0
Stop Timer0
End If
Return
'############################## Timer 0 ############################################
Infrared: '** work on interruption
Start Timer0
If Tik >= 139 And Tik < 150 Then '** if has happenned from 139 before 150 teaks - "START"
Address = 1
Repeat_flag = 0
Start_flag = 1
Address_1 = 0
Command_1 = 0
Address_0 = 0
Command_0 = 0
End If
If Tik >= 116 And Tik < 139 Then '** if has happenned from 116 before 138 teaks - "REPETITION"
Address = 2
Repeat_flag = 1
Start_flag = 0
End If
If Tik >= 22 And Tik < 116 And Start_flag = 1 Then '** if has happenned from 22 before 115 teaks - have taken "1"
Incr Byt
If Byt < 9 Then
Shift Address_1 , Left
Address_1 = Address_1 + 1
End If
If Byt >= 9 And Byt < 17 Then
Shift Address_0 , Left
Address_0 = Address_0 + 1
End If
If Byt >= 17 And Byt < 25 Then
Shift Command_1 , Left
Command_1 = Command_1 + 1
End If
If Byt >= 25 Then
Shift Command_0 , Left
Command_0 = Command_0 + 1
End If
End If
If Tik >= 10 And Tik < 22 And Start_flag = 1 Then '** if has happenned from 10 before 21 teaks - have taken "0"
Incr Byt
If Byt < 9 Then
Shift Address_1 , Left
End If
If Byt >= 9 And Byt < 17 Then
Shift Address_0 , Left
End If
If Byt >= 17 And Byt < 25 Then
Shift Command_1 , Left
End If
If Byt >= 25 Then
Shift Command_0 , Left
End If
End If
Tik = 0
If Byt = 32 Then '** if have taken 4 bytes, check correctness a receiving a command
'if address or command 16-bit, check does not pass
'Summa = Address_0 + Address_1
'If Summa = 255 Then
Address = Address_1
'Else
'Address = 0
'End If
'Summa = Command_0 + Command_1
'If Summa = 255 Then
Command = Command_1
'Else
'Command = 0
'End If
Byt = 0
Repeat_flag = 0
Start_flag = 0
Stop Timer0
End If
Return
'################################################################################################################
(BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Sep 10, 2017 8:00 pm Post subject: Re: Attiny4313 PWM problem |
|
|
balou wrote: | Sometimes the PWM signal is free running. |
Define "free running".
Some potential problems: no test for under-/overrun of pwm1a, command is not cleared immediately after execution. |
|
Back to top |
|
|
balou
Joined: 14 Apr 2007 Posts: 36
|
Posted: Sun Sep 10, 2017 8:33 pm Post subject: |
|
|
Free running, pwm1a change from 0 to 255. |
|
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
|
|