Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

PCINT does not work on every input-pin

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 386
Location: Wuppertal, Germany

germany.gif
PostPosted: Sun Jun 23, 2019 11:07 am    Post subject: PCINT does not work on every input-pin Reply with quote

Hello,
I'm working on pin-change-interrupt to get SW-Uart to work. I'm encountering problems, so I stripped down the thing to the essenrtial.
As you can seen, I achive to trigger PCINT on pulsed outputs, that makes it easier to set up the test.
Every second I pulse out some OUTPUTS with delays, just to see things clearer.
What I expect ist to trigger an PCINT by pulsing an output, which triggers the corresponding PCINT.
It works fine if I pulse PINB.0.

My issue: It does not work if I use PortB.1. Not shown here, but the same issue on PortB.2. No other pin tested.
The pulsed outputs work, leds are connected. Only one of the remarked snippets is to unmark at a time, of course.

It seems not to be that complex, what's wrong here?

regards
Marc


Code:
$regfile = "m328pdef.dat"
$crystal = 8000000
$hwstack = 120
$swstack = 120
$framesize = 120
$baud = 9600

'$prog &HFF , &HE2 , &HD7 , &HFD


Dim Tick_1s As Bit

Led_pwr Alias Portb.0                                                           'Power-Led green
Rel_ss Alias Portb.6
Led_ch4 Alias Portd.7

Config Pinb.0 = Output
Config Pinb.1 = Output
Config Pinb.2 = Output
Config Pinb.6 = Output
Config Pind.6 = Output
Config Pind.7 = Output

'****  Timer1 1s ****
Const Timer1reload = 7812
Config Timer1 = Timer , Prescale = 1024
Load Timer1 , Timer1reload
On Ovf1 Timer1_isr
Enable Timer1
Start Timer1

Declare Sub Uart_in_service

'#### this toggles Rel_ss in Uart_in_service ISR:
'Pcmsk0 = &B0000_0001
'On Pcint0 Uart_in_service
'Enable Pcint0


'#### This does not:
'Pcmsk0 = &B0000_0010
'On Pcint1 Uart_in_service
'Enable Pcint1

Enable Interrupts

'****  Main Loop ****

Do


   If Tick_1s = 1 Then
      Reset Tick_1s
      Pulseout Portd , 7 , 250000
      Waitms 250
      Pulseout Portb , 0 , 250000
            Waitms 250
      Pulseout Portb , 1 , 250000
      Pulseout Portb , 2 , 250000
      Pulseout Portd , 6 , 250000
   End If
Loop

'****  Interrupt Routines ****

Timer1_isr:
   Load Timer1 , Timer1reload
   Set Tick_1s
Return

Uart_in_service:
   Toggle Rel_ss
Return


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

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Jun 23, 2019 11:50 am    Post subject: Re: PCINT does not work on every input-pin Reply with quote

Arera wrote:
It seems not to be that complex, what's wrong here?
Code:
'#### This does not:
'Pcmsk0 = &B0000_0010
'On Pcint1 Uart_in_service
'Enable Pcint1

If you understand how PCINT works, i.e. that any pin of one port, selected by PCMSK, triggers one PCINT-vector, then you understand what's wrong with your code.
Back to top
View user's profile
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 386
Location: Wuppertal, Germany

germany.gif
PostPosted: Sun Jun 23, 2019 12:22 pm    Post subject: Reply with quote

MWS, I got it.
PCMSK0 relates to Pinb.[0...7].

ATMEGA328PU has 23 PINT-pins, masked by PCMSK0, PCMSK1, PCMSK2.

Got that fron the datasheet bevore. What mislead me, is the fact, that bascom alowes to type PCINT23. PCINT24 is rejected.
Thus I thougt bascom would to the right settings, if i use i.e. PCINT18.
So what is

Code:
on PCINT18 isr18


meant for?
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Jun 23, 2019 1:57 pm    Post subject: Reply with quote

Arera wrote:

So what is

Code:
on PCINT18 isr18


meant for?

This symbol abuse means nothing.

Only because you can type frzgblrmfogl , it does not mean anybody understands it.
The symbols PCINT18, PCINT19, a.s.o. exist because they describe the PC-interrupt pins according the data sheet, thus it is valid to write:
Code:
PCMSK2.PCINT18 = 1

for enabling PCINT18-pin (PD2) to trigger vector PCINT2.
Back to top
View user's profile
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 386
Location: Wuppertal, Germany

germany.gif
PostPosted: Sun Jun 23, 2019 2:15 pm    Post subject: Reply with quote

OK. Got it.

In difference to "sjgfjhasgfuzawgu" (will not be compiled), "ON PCINT18 my_ISR" will compile. That lead my to assume that this is a valid Interrupt. That lead me to use PCINT1, expecting to Interrupt on PCINT1 (pinb.1).
"on gfgfjdjdhdhz my_ISR" will not compile too, enforcing my erroneous assumption.

Thank you, MWS!

Marc
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Jun 23, 2019 3:30 pm    Post subject: Reply with quote

You need to read the datasheet, as you are responsible for correctness of your code.

If you address the point of 'it did not complain, thus it was supposed to work': there are tons of occasions in micro-controller programming, in Bascom and other programming languages to write something that looks ok, but won't work.
Even it would be possible to ask why you was not warned about using an improper interrupt vector, you need to ask how many man-hours or -years of work have to go into catching up simple user errors and report them.

This can be a hole without bottom, so catching up errors needs to stop somewhere and that's where user's responsibility starts.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5917
Location: Holland

blank.gif
PostPosted: Mon Jul 01, 2019 10:05 am    Post subject: Reply with quote

Quote:
"ON PCINT18 my_ISR"


yes it will compile since ON is not only used for interrupts but also for data sets.
ON value ...
And since PCINT18 is a numeric constant it will be seen as valid.

_________________
Mark
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
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