Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem with Timer/Counter2
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
sarwar

Bascom Member



Joined: 08 Jan 2010
Posts: 50

uk.gif
PostPosted: Tue Feb 16, 2010 3:01 pm    Post subject: Problem with Timer/Counter2 Reply with quote

Hi,

I am using an Atmega644PV target... and an external 32.768 KHz crystal clock to count for seconds.... as shown:

Moreover I am using the following code:
Code:

$regfile = "m644pdef.dat"                                   ' Atmega644p


$crystal = 8000000

$hwstack = 32
$swstack = 16
$framesize = 40


Dim Seconds_count As Long
Seconds_count = 0

'************************************************************************************************
' GENERAL STATE LED
'************************************************************************************************


Staled Alias Porta.7                                        ' State LED
Config Staled = Output
Set Staled


' Timer2 configs using the exteranl 32.768 KHz crystal

   Assr = &H20
   Tccr2a = &H00
   Tccr2b = &H05



On OVF2 OVF2_isr
Enable OVF2

' Reset the Timer2 count
TCNT2= &H00

Enable Interrupts



'------------------------------------------------------------------
'---------- main loop -------------------
'----------------------------------------------------------------------

Do

   If Seconds_count = 5 Then

      Seconds_count = 0

      Reset Staled
      Waitms 50                                             ' light indicator every 5 seconds
      Set Staled

   End If


Loop

                                                             ' end of program
End


'--------------------------------------------------------------------------



OVF2_isr:

  Incr Seconds_count

Return
 



And I am not using any JTAG interface... The fuse setting are given in the screen shot...


Every thing works fine.... and I get LED flash every 5 seconds as required....
But when i apply a pulse waveform signal even of low frequency (20 Hz) on the pin-24 (PCINT 21), the timer slows down... and i get flash very late... about 10 seconds instead of 5.... This problem is there only with pin-24.... I mean if i apply the same signal to other pins like pins 21-23... the clock is not affected......


Do any body have some idea that whats going wrong.....????

I am very thankful for the cooperations.....

Many Thanks


Best Regards,
Sarwar
Back to top
View user's profile
sarwar

Bascom Member



Joined: 08 Jan 2010
Posts: 50

uk.gif
PostPosted: Wed Feb 17, 2010 11:04 am    Post subject: Reply with quote

Hi,

Can i use Timer2 internally instead of using exteranl crytal????

or may be i can use timer1 or timer3 as the seconds count as well....????

I think, may be its the capacitor coupling (cross capacitance) causing the disturbance of timer2 clock........

Any idea from some one.............


Many Thanks

Best Regards,
Sarwar
Back to top
View user's profile
snipacarina

Bascom Member



Joined: 28 Jun 2007
Posts: 62
Location: Åland

blank.gif
PostPosted: Thu Feb 18, 2010 1:31 am    Post subject: Reply with quote

sarwar wrote:
Any idea from some one.............
Sarwar

Hi. I do not know the answer, but let me guess...
ATMEL recomends to tie unused ports to either high or low, by diffrent means, in order not to disturb the used circuit. Furthermore groundingplane around a XTAL is mentioned as an essential part of design.

That could explain why you got those ghosts effects when using a pin that is close to one of the XTAL pins. But who knows? Smile Best luck!
Back to top
View user's profile
sarwar

Bascom Member



Joined: 08 Jan 2010
Posts: 50

uk.gif
PostPosted: Thu Feb 18, 2010 2:03 pm    Post subject: Reply with quote

Hi

I did tried the same code and things on a completely different platform, that has a very sound crystal and groundings....

The problem is still there.... The application of signal on pin-24 (PC5)is still causing the clock delay etc.....

I think, may be a problem with the Atmega644PV...... may be..... or the capacitor selection.... But i have tried it using different crystals, different boards, and also taking the capacitors OFF....

I dont think capacitors are havinf some effect.... May be....
But problem is still there..............

Any idea is welcome....


Many Thanks,
Sarwar
Back to top
View user's profile
Estelles

Bascom Member



Joined: 14 Dec 2005
Posts: 208
Location: Scotland

uk.gif
PostPosted: Thu Feb 18, 2010 2:03 pm    Post subject: Reply with quote

Hi,

I got a similar design and I did try what you say (I do have power planes aroudn the xtal) and worryingly, it does what Sarwar mention, it does affect the timer2 performance.

Does anyone knows how to contact Atmel and see if this could be a bug? The curios thing is that running a simulation on Proteus VSM works fine. As far as I know their code is based on the pdf specs. That smells a bug from Atmel, isn´t it?
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2263

blank.gif
PostPosted: Thu Feb 18, 2010 3:01 pm    Post subject: Reply with quote

Sound to me like there's too much stray capacitance on your board, and therefore the signal applied on pin 24 is able to stop temporary the oscillation via stray in from this pin.
Is the PCB clean ?

Try to remove the capacitors from the 32768Hz crystal or/and try another crystal of different make.

Also be aware, that watch crystal specs differ, did you read "Low Frequency Crystal Oscillator" in the datasheet ? What's the load capacitance of the used watch crystal ?
Back to top
View user's profile
Estelles

Bascom Member



Joined: 14 Dec 2005
Posts: 208
Location: Scotland

uk.gif
PostPosted: Thu Feb 18, 2010 3:50 pm    Post subject: Reply with quote

This is a testing boards I have for quick things so it is not the best design ever, however never had to use the PCINT2 as a counter and never had problems until I tried Sarwar symptoms.

How do you fix the "stray capacitance" on two pins that are very close together?
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2263

blank.gif
PostPosted: Thu Feb 18, 2010 4:24 pm    Post subject: Reply with quote

Quote:
How do you fix the "stray capacitance" on two pins that are very close together?


If your PCB design is ok, you can't. If it's clean and no flux residuals are on the board it should be fine. Normal stray capacity doesn't hurt the oscillator, if the oscillation is strong enough.

But it sounded to me somehow, if the oscillation stops with the help of pin 24, maybe because of too high stray capacity on the TOSC pins, unsuitable crystal, resistance or capacitance between the neighbored pins, and that includes also bad PCB design.

It may work alright without a signal on pin 24, but a signal there is the final straw then.

So my guess, remove the capacitors and try again. Next, use a different make of the crystal and recheck the PCB.

I don't think Atmel will be happy to have a bug alarm raised, whilst you did not even check the datasheet.
Page 35 in 8011L–AVR–02/09, 6.5 Low Frequency Crystal Oscillator.

Edit:
This may be useful: http://www.atmel.com/dyn/resources/prod_documents/doc2521.pdf
Note especially:
Quote:
Devices who support 1.8-5.5V operating voltages do not have internal capacitors (except Atmega162).
That's the case for the M644PV, and tells me whether you need capacitors and if yes, which value, is completely depending on the the specs of the 32768Hz crystal.

Last edited by MWS on Thu Feb 18, 2010 6:04 pm; edited 1 time in total
Back to top
View user's profile
Estelles

Bascom Member



Joined: 14 Dec 2005
Posts: 208
Location: Scotland

uk.gif
PostPosted: Thu Feb 18, 2010 5:57 pm    Post subject: Reply with quote

Yes, it does need capacitors.
I was trying with 10pF but having a second look at the specs it looks like I should be using 20pF. I will post results shortly!
Back to top
View user's profile Visit poster's website
sarwar

Bascom Member



Joined: 08 Jan 2010
Posts: 50

uk.gif
PostPosted: Thu Feb 18, 2010 7:13 pm    Post subject: Reply with quote

Hi

I gave it a try without capacitors (No capacitors)..... Problem still there...
Then I put 22pF capacitors.... Problem still there.....
similarly with 10pF capacitors.... problem is still there....

I used different crystal as well... But nothing positive.....

One thing is for sure, its a hardware problem.... Any other idea is most welcome.....


Many Thanks.


Best Regards,
Sarwar
Back to top
View user's profile
Estelles

Bascom Member



Joined: 14 Dec 2005
Posts: 208
Location: Scotland

uk.gif
PostPosted: Thu Feb 18, 2010 7:14 pm    Post subject: Reply with quote

Ok, I have tested 20pF. Nothing, exactly the same behaviour.

Has anyone got pcint21 working well as a counter at the same time than the RTC from crystal?
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2263

blank.gif
PostPosted: Thu Feb 18, 2010 8:37 pm    Post subject: Reply with quote

How is the µC flashed ? ISP or bootloader ?

If you'll post the created files, .obj, .hex, .bin, .dbg, I'll have a look into the created code.
Back to top
View user's profile
Estelles

Bascom Member



Joined: 14 Dec 2005
Posts: 208
Location: Scotland

uk.gif
PostPosted: Thu Feb 18, 2010 8:37 pm    Post subject: Reply with quote

Right, another test:

I have disconnected pcint21 from the board (pin on the air) and applied a square signal (32Hz) on the track that was connected to pin24.

I DOES work fine. I assume that if it was a stray capacitance it would be there weather the pin is connected or disconnected woudn´t it?
The input of this track is externally pulled high so the interferences should be there anyway but they aren´t with pcint21 fully disconnected.

Unless I´m missing something... this sounds a bug on the IC, doesn´t it?
Back to top
View user's profile Visit poster's website
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 537

PostPosted: Thu Feb 18, 2010 9:57 pm    Post subject: Reply with quote

Clever test.

It would be conclusive if another 644p micro showed exactly the same results.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2263

blank.gif
PostPosted: Thu Feb 18, 2010 10:12 pm    Post subject: Reply with quote

Hmm,
as I see the fuses settings from sarwar use a bootloader.

Till I haven't seen all the code, and that means the bootloader code and the interrupt vector table, I would not put it on the hardware.

Try this and check what happens:
Code:
$regfile = "m644pdef.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 32

Dim Cntr_bit7 As Byte
Dim Sec_ctr As Byte
Dim Trigd As Bit

Ddrc.pc5 = 0

Led Alias Porta.7
Config Led = Output
Set Assr.as2
  Tccr2a = 0
  Tccr2b = Bits(cs22 , Cs20)

  Reset Led
  Tcnt2 = 0
  Sec_ctr = 0
  Trigd = 0
Do
  Cntr_bit7 = Tcnt2 And &B1000_0000
    If Cntr_bit7 = &B1000_0000 And Trigd = 0 Then
        Trigd = 1
          Incr Sec_ctr
    End If
    If Cntr_bit7 = &B0000_0000 And Trigd = 1 Then
        Trigd = 0
    End If
      If Sec_ctr = 5 Then
        Toggle Led
          Sec_ctr = 0
      End If
Loop

End

Think you see my intention.
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
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