Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problems with ATMEGA164PA
Goto page Previous  1, 2
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1525

blank.gif
PostPosted: Mon May 14, 2018 6:24 am    Post subject: Re: ATMEGA164PA Timer2 Issue Reply with quote

madhav1080 wrote:
I am still not very clear about the PCINT2 triggered for the PORTB activity, maybe I should just write the code for testing this and then add the rest, on couple of occasions this helped solve such problem.

Without having checked the circuit and in case no external pull-downs are used, I would activate the internal pull-ups for all PCINT inputs to make sure nothing floats and is prone for crosstalk..
A test program is pretty simple then, blink an led within PCINT-ISR and check via writing to PortB.
Back to top
View user's profile
madhav1080

Bascom Member



Joined: 06 Jan 2008
Posts: 32
Location: Hyderabad

india.gif
PostPosted: Mon May 14, 2018 12:25 pm    Post subject: ATMEGA164PA PCINT2 Gets triggered with PORTB Activity Reply with quote

Hello,

I have fixed this problem doing the following...

upon Serial interrupt, first LIMIT PCINT2 by setting PCMSK2= &H00, process the action and set the PORTB accordingly, ENABLE PCINT2 by setting back PCMSK2=&H7C

This was the only way to work around this problem, might help some one with a similar issue...

Code:


'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'                          System Main Routine
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Enable Interrupts
Enable Urxc
Eicra = &H01
Enable Int0


PCMSK2 = &H7C
Enable PCINT2

Enable Timer0
Enable Timer2

On Urxc Srlisr
On Timer0 Tmr0isr
On Timer2 Tmr2isr
On Int0 Zerocrss
On PCINT2 switches

Load Timer0, 200
Load Timer2, 200


Reset DDir
SEt Rstt
waitms 100
Call Get_addr
Call Recall_settings
Print "Addr:"; addr; ":::::"; "UID:";uid


Do
   Call Run_system
   If Zrcss = 1 then
      Select case Opseq
         Case is = 0:
         Case is = 1:

            Call Store_curStat
            OPSEQ = 0
         Case is = 2:
            PortB = Cdata
            Call Store_curStat
            OPSEQ = 0
            PCMSK2 = &H7C
         Case is = 3:
            PORTB = CData
            Call Store_curStat
            OPSEQ = 0
         Case is = 4:
            Call Store_curStat
            OPSEQ = 0
      End select
      Zrcss = 0
      Eicra = &H01
      Enable Int0
   End if

Loop
End

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'                                Serial Comm
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Serial_Com()
   Local Checktag as string * 4
   If Srlint = 1 then
      PCMSK2 = &H00
      P1 = Mid(command , 2 , 3)
      P2 = Mid(Command , 5 , 3)
      P3 = Mid(command , 8 , 2)
      P4 = Mid(command , 10 , 1)
      P5 = Mid(command , 11 , 2)
      P6 = Mid(command , 13 , 2)
      Call Get_addr
      If P1 = UID then
         If P2 = Addr Then
            Select case P3
               Case is = "LI":
                  Call Comm_Li
               Case is = "SP":
                  Call Comm_Sp
               Case is = "OT":
                  Checktag = P5 + P6
                  If P4 = "O" then
                     If Checktag = "ROOM" then
                        opseq = 4
                        Cdata = 0
                        Fn_spd = 0

                     End if
                  End If
               Case is = "AL":
                  Checktag = P5 + P6
                  If P4 = "L" then
                     If Checktag = "OOFF" then
                        opseq = 4
                        Cdata = 0
                        Fn_spd = 0

                     End if
                  End If
            End select
         Elseif P2 = "AAA" then
            Checktag = P5 + P6
            Select case P3
               Case is = "OT":
                  If P4 = "O" then
                     If Checktag = "HOME" then
                        opseq = 4
                        Cdata = 0
                        Fn_spd = 0

                     End if
                  End If
               Case is = "IN":
                  If P4 = "S" then
                     If Checktag = "HOME" then

                     End if
                  End If
            End select
         End if
      Else
         If P3 = "SP" then
            If P4 = "*" then
               If P5 = "20" then
                  Call Write_uid
               End if
            End if
         End If
      End if
      Srlint = 0
      Comcnt = 0
      Command = ""
      Enable Urxc
   End if

End sub

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'                             Check Wall Switches
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Chk_Wallsws()
   if Kyb = 1 then
      DEl = 5
      Call Delayy

      If pinC.2 = 0 then
         Opseq = 3
         Del = 30
         Call Delayy
         CData.0 = 1
      Elseif PINC.2 = 1 then
         Opseq = 3
         Del = 30
         Call Delayy
         CData.0 = 0
      End if

      If PinC.3 = 0 Then
         Opseq = 3
         Del = 30
         Call Delayy
         CData.1 = 1
      Else
         Opseq = 3
         Del = 30
         Call Delayy
         CData.1 = 0
      End if

      If PinC.4 = 0 then
         Opseq = 3
         Del = 30
         Call Delayy
         CData.2 = 1
      Else
         Opseq = 3
         Del = 30
         Call Delayy
         CData.2 = 0
      End if

      If PinC.5 = 0 then
         Opseq = 3
         Del = 30
         Call Delayy
         CData.3 = 1
      Else
         Opseq = 3
         Del = 30
         Call Delayy
         CData.3 = 0
      End if

      If PinC.6 = 0 then
         Opseq = 3
         Del = 30
         Call Delayy
         Fn_on = 1
      Else
         Opseq = 3
         Del = 30
         Call Delayy
         Fn_on = 0
      End if

      If PinC.7 = 0 then

      End if
      Kyb = 0
      PCMSK2 = &H7C
      Enable PCINT2
   End if
End Sub

 


Once Again I THANK each one of you for your Kind and timely inputs, have a wonderful day

Kind Regards

Madhav Tenneti
Back to top
View user's profile Visit poster's website
madhav1080

Bascom Member



Joined: 06 Jan 2008
Posts: 32
Location: Hyderabad

india.gif
PostPosted: Mon May 14, 2018 1:06 pm    Post subject: Re: ATMEGA164PA Timer2 Issue Reply with quote

MWS wrote:
madhav1080 wrote:
I am still not very clear about the PCINT2 triggered for the PORTB activity, maybe I should just write the code for testing this and then add the rest, on couple of occasions this helped solve such problem.

Without having checked the circuit and in case no external pull-downs are used, I would activate the internal pull-ups for all PCINT inputs to make sure nothing floats and is prone for crosstalk..
A test program is pretty simple then, blink an led within PCINT-ISR and check via writing to PortB.


Please refer to the CPU card Schematic, PORTB is Pulled down using 10K SIP-8, this is to ensure that while powering up the Default Logic level will be all zero so that the Relays don't get triggered. Like wise on the PORTC, i.e from PC.2 to PC.7 are pulled up through a 10K SIP-8.

Was actually testing the ULN2803 Inputs and outputs (Using a LOGIC PROBE), a simple program which checks PCINT2 while cyclying PORTB= &HFF Delay, PORTB = &H00 Delay, this too was triggering the PCINT2, I am suspecting the AC-DC 5V Powersupply, I have noted that there is a constant noise on the VCC & GND pins, on VCC the Logic probe normally should be predominently High, I have observed some fast low Pulses, Like wise on the GND pin, predominently should be LOW, but was observing fast flashes of High.


Since my client wanted a low cost powersupply and he provided the same which was designed to be PIN equivalent to RECOM (RAC06-05SC), we used this new power supply insted of our regular RECOM PART. Possibly this is contributing to noise which is effecting the Pin change interrupts.


I have a complete Home automation solution using XBEE (S2C & 865MHz) and serveral cards like...
and now on (ESP8266-12E)

1) Relay Controls

2) DAC based 0-10V analog Control

3) 8 Ch Triac Control

4) Shear & Main Drape Control

4) Tibbo EM1206 Home Automation Gateway

5) SK6812-RGBWW Mood lighting control

6) Learning IR Blaster

Have been doing customised HOME AUTOMATION Solutions for over 12 years based on XBEE & Ethernet, this is the first time ran into some serious trouble. appreciate your help, advice & time. Oh yes most of my products use ATMEL AVR Chips & of course the BASCOM AVR COMPILER.


Always thankful to MARK for his wonderful BASCOM COMPILER and this pro active fourm.


Kind Regards

Madhav Tenneti
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 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