View previous topic :: View next topic |
Author |
Message |
sarwar
Joined: 08 Jan 2010 Posts: 50
|
Posted: Tue Feb 16, 2010 3:01 pm Post subject: Problem with Timer/Counter2 |
|
|
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 |
|
|
sarwar
Joined: 08 Jan 2010 Posts: 50
|
Posted: Wed Feb 17, 2010 11:04 am Post subject: |
|
|
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 |
|
|
snipacarina
Joined: 28 Jun 2007 Posts: 62 Location: Åland
|
Posted: Thu Feb 18, 2010 1:31 am Post subject: |
|
|
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? Best luck! |
|
Back to top |
|
|
sarwar
Joined: 08 Jan 2010 Posts: 50
|
Posted: Thu Feb 18, 2010 2:03 pm Post subject: |
|
|
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 |
|
|
Estelles
Joined: 14 Dec 2005 Posts: 208 Location: Scotland
|
Posted: Thu Feb 18, 2010 2:03 pm Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Feb 18, 2010 3:01 pm Post subject: |
|
|
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 |
|
|
Estelles
Joined: 14 Dec 2005 Posts: 208 Location: Scotland
|
Posted: Thu Feb 18, 2010 3:50 pm Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Feb 18, 2010 4:24 pm Post subject: |
|
|
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 |
|
|
Estelles
Joined: 14 Dec 2005 Posts: 208 Location: Scotland
|
Posted: Thu Feb 18, 2010 5:57 pm Post subject: |
|
|
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 |
|
|
sarwar
Joined: 08 Jan 2010 Posts: 50
|
Posted: Thu Feb 18, 2010 7:13 pm Post subject: |
|
|
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 |
|
|
Estelles
Joined: 14 Dec 2005 Posts: 208 Location: Scotland
|
Posted: Thu Feb 18, 2010 7:14 pm Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Feb 18, 2010 8:37 pm Post subject: |
|
|
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 |
|
|
Estelles
Joined: 14 Dec 2005 Posts: 208 Location: Scotland
|
Posted: Thu Feb 18, 2010 8:37 pm Post subject: |
|
|
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 |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Thu Feb 18, 2010 9:57 pm Post subject: |
|
|
Clever test.
It would be conclusive if another 644p micro showed exactly the same results. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Feb 18, 2010 10:12 pm Post subject: |
|
|
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 |
|
|
|