Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Timer0 problem on ATtiny 1634

 
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: Thu Feb 15, 2018 12:46 am    Post subject: Timer0 problem on ATtiny 1634 Reply with quote

Hello again,
I realy have problem with the 1634.
I have being using the ATtiny167 without any problem, but I need two additional ports so I am switching to the ATtiny1634
The program does not jump to "Frequency_ab" on Timer0 Interrupts

Code:

$regfile = "attiny1634.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40

Config Portb.3 = Output                 'PWM Using Timer1
Config Porta.0 = Output                 '150Hz to 500Hz Square Wave

Dim Pu As Word

'COM PORT
'Open "comb.0:9600,8,n,1" For Output As #1

Config Timer0 = Timer , Prescale = 1
On Timer0 Frequency_ab
Enable Timer0
Start Timer0
Enable Interrupts

Config Timer1 = Pwm , Pwm = 10 , Compare_a_pwm = Clear_up , Prescale = 1

Do
   Waitms 1000
   Pwm1a = 512                          '50% ~4Khz PWM on PORTB.3  (OC1A)
Loop
                            '
Frequency_ab:
   Pu = Pu + 1
   'Print #1 , "Pu: " ; Pu
   If Pu => 62 Then                     '62=500Hz  206=150Hz
      Pu = 0
   Elseif Pu >= 31 Then                 '31=500Hz  103=150Hz
      Porta.0 = 1
   Elseif Pu >= 0 Then
      Porta.0 = 0
   End If
Return

End
 



Excatly the same program (Except using different ports) it works fine with ATtiny167

Code:

$regfile = "attiny167.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40

Config Portb.0 = Output                 'PWM Using Timer1
Config Porta.2 = Output                 '150Hz to 500Hz Square Wave

Dim Pu As Word

'COM PORT
'Open "coma.0:9600,8,n,1" For Output As #1

Config Timer0 = Timer , Prescale = 1
On Timer0 Frequency_ab
Enable Timer0
Start Timer0
Enable Interrupts

Config Timer1 = Pwm , Pwm = 10 , Compare_a_pwm = Clear_up , Prescale = 1

Do
   Waitms 1000
   Pwm1a = 512                          '50% ~4Khz PWM on PORTB.0  (OC1AU)
Loop
                             '
Frequency_ab:
   Pu = Pu + 1
   'Print #1 , "Pu: " ; Pu
   If Pu => 206 Then                    '62=500Hz  206=150Hz
      Pu = 0
   Elseif Pu >= 103 Then                '31=500Hz  103=150Hz
      Porta.2 = 1
   Elseif Pu >= 0 Then
      Porta.2 = 0
   End If
Return

End
 


The only different I can see is that all the Timer0 instructions for the ATtiny 1634 are in lover case and black. Timer1 instructions Upper case and red.
Config Timer0 = Timer , Prescale = 1
On Timer0 Frequency_ab

For the Attiny167 both Timer0 and Timer1 instructions are both Upper case and red.
Config TIMER0 = Timer , Prescale = 1
On TIMER0 Frequency_ab

I don't know if that means anything?

Thanks,
gerrysc


(BASCOM-AVR version : 2.0.8.1 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5925
Location: Holland

blank.gif
PostPosted: Thu Feb 15, 2018 10:13 am    Post subject: Reply with quote

this is a bug in the START statement. it does not know the T1634 and enables the wrong register.
Instead write TCCR0B=1 for this chip and it should work.

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

Bascom Member



Joined: 06 May 2006
Posts: 88

canada.gif
PostPosted: Thu Feb 15, 2018 7:01 pm    Post subject: Reply with quote

Thanks,
It works. I wounder why the T167 is giving me a 500Hz square wave and the T1634 only a 314Hz square wave? Both are using 8Mhz internal clock

Here is how I am using the Tccr0b. Not quite sure if it is correct.

Code:

 ' Config Timer0 = Timer , Prescale = 1
On Timer0 Frequency_ab
Enable Timer0
Start Timer0
Tccr0b = 1
Enable Interrupts
 


Best regards,
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