sfiga69
Active Member
Offline
Posts: 188
Thank You
-Given: 198
-Receive: 159
In the order is preserved, in the mess is created.
|
|
« on: June 30, 2016, 08:09:44 20:09 » |
|
excuse me, but I have little experience with the AVR 8bit. I have to control the PCINT0.3 interrupt of a attiny85. The simulation in Proteus with the connection 1, it works correctly, but in practice no. The pin PCINT0.3 always remains at a low level (0.4 - 0.6V). if I configure the pin as an input, the levels are correct (0 - 4.4V) but the interrupt does not trigger. What is the correct method to interrupt drive? (1 or 2)
thanks
|
|
|
Logged
|
|
|
|
pickit2
Moderator
Hero Member
Offline
Posts: 4662
Thank You
-Given: 833
-Receive: 4313
There is no evidence that I muted SoNsIvRi
|
|
« Reply #1 on: June 30, 2016, 11:49:31 23:49 » |
|
show us your code... you have to be careful using Proteus, they expect you to have set the fuses correctly. Example enter code for a pic16f84 change device and the code still runs.
I suspect your fuse setting are wrong. if set correct it should be high. you enable pull up resistor, or have a resistor in your circuit.
|
|
|
Logged
|
Note: I stoped Muteing bad members OK I now put thier account in sleep mode
|
|
|
kreutz
Active Member
Offline
Posts: 183
Thank You
-Given: 994
-Receive: 125
|
|
« Reply #2 on: June 30, 2016, 11:58:46 23:58 » |
|
You should not only configure it as input but also enable interrupts and have the proper interrupt routine written in order for it to work. Check the code.
|
|
|
Logged
|
|
|
|
TucoRamirez
Senior Member
Offline
Posts: 307
Thank You
-Given: 257
-Receive: 115
Tuco ... dead or Alive
|
|
« Reply #3 on: July 01, 2016, 08:25:56 08:25 » |
|
yup, gotta disable all the other alternative functions on that pin (Analog in, comparators, i.e.) and as i can see, check the fuses to activate the internal osc and detach from the XTAL pin circuitry
|
|
|
Logged
|
Whoever double crosses me and leaves me alive... he understands nothing about Tuco.
|
|
|
mars01
V.I.P
Hero Member
Offline
Posts: 537
Thank You
-Given: 696
-Receive: 1774
|
|
« Reply #4 on: July 01, 2016, 02:17:11 14:17 » |
|
The schematic in figure 1 is OK. On how to configure things, have a look on what this guy done here: http://www.avrfreaks.net/forum/pin-change-interrupts-attiny-beginnersFor PCINT3 test I would do a code like this (make sure that you have debounce on the LED of the opto if the signal is bouncing): // ADD a LED (with resistor) on pin5 of the uC and use the pin change interrupt function on pin 2 of the uC
volatile unsigned char flag = 0;
ISR(PCINT3_vect) // interrupt service routine { // called when PCINT3 changes state flag++; return; }
void SystemInit(void) { PCMSK |= (1<<PCINT3); // pin change mask: listen to PORTB bit 3 GIMSK |= (1<<PCIE); // enable PCINT interrupt sei(); // enable all interrupts }
void main(void) { ADCSRA = 0; // ADC is disabled (because bit7 is 0) ACSR = 0; // comparator OFF (because bit7 is 0) DDRB = 0b00000001; // PORTB bit 0 is OUTPUT the rest are INPUT's PORTB &= ~(1 << 3); // PORTB bit 3 internal pull-up resistor disabled SystemInit();
while(1) { // the LED on PORTB bit 0 will change state only when the pin change from HIGH to LOW and then HIGH again - schematic in FIG 1 was used if (flag >= 2) { cli(); flag = 0; PORTB = (PORTB ^ 0x01); // toggle red led on PORTB bit 0 sei(); } } }
|
|
« Last Edit: July 01, 2016, 04:12:08 16:12 by mars01 »
|
Logged
|
|
|
|
sfiga69
Active Member
Offline
Posts: 188
Thank You
-Given: 198
-Receive: 159
In the order is preserved, in the mess is created.
|
|
« Reply #5 on: July 01, 2016, 09:42:18 21:42 » |
|
I have attached a test Proteus project with the source bascomAvr to check the interrupt operation. I'm trying on a digispark with D + and D- USB's cut, so as not to have influences on PB3 (usb only for power). Proteus you can see that in the two cases all operating normally. practically the P2 and P1 button have no effect. I think I properly set the bits required to operate according to the ATtiny85 datasheet: GIMSK, Bit 5 - PCIE: Pin Change Interrupt Enable PCMSK, BIT 3 - PCINT3 Pin Change Mask Register
from datasheet: 9.2 External Interrupts ...... Observe that, if enabled, the interrupts will trigger even if the INT0 or PCInt [5: 0] pins are configured as outputs. This feature Provides a way of generating a software interrupt. Pin change interrupts PCI will trigger if any enabled PCInt [5: 0] pin toggles. ..... If I put: Portb.1 config = Output Proteus acts as the digispark: P1 = no effect P2 = triggered the interrupt
Thanks for your help
|
|
|
Logged
|
|
|
|
kreutz
Active Member
Offline
Posts: 183
Thank You
-Given: 994
-Receive: 125
|
|
« Reply #6 on: July 02, 2016, 12:06:33 00:06 » |
|
Can't help, I don't use Proteus. If you post the code I might be able to take a look at it.
|
|
|
Logged
|
|
|
|
sfiga69
Active Member
Offline
Posts: 188
Thank You
-Given: 198
-Receive: 159
In the order is preserved, in the mess is created.
|
|
« Reply #7 on: July 02, 2016, 09:04:47 09:04 » |
|
schematics and code ' LB FBL FBH FBE $prog &HFF , &HF1 , &HDF , &HFF
$regfile = "attiny85.dat" $crystal = 16000000 $hwstack = 40 $swstack = 40 $framesize = 40
On Pcint0 Isr_int0 ' interrupt service routine Set Gimsk.5 ' enable PCIE = PCINT0 enable interrupt Set Pcmsk.3 ' enable PCINT3
Config Portb.1 = Output 'config portb.3 = output
Start1:
Enable Interrupts Do
Loop End
Return
'*************************************************************************** '* interrupt routine INT0 '***************************************************************************
Isr_int0:
Toggle Portb.1
Return
|
|
|
Logged
|
|
|
|
mars01
V.I.P
Hero Member
Offline
Posts: 537
Thank You
-Given: 696
-Receive: 1774
|
|
« Reply #8 on: July 02, 2016, 03:31:18 15:31 » |
|
Hi, I've made a fast program in mikroC for AVR. The code works as it is supposed to and it is like this: volatile unsigned char flag = 0;
void PCINT3_ISR() iv IVT_ADDR_PCINT0 ics ICS_AUTO { flag++; }
void init_sys(){ ADEN_bit = 0; // disable ADC ACD_bit = 0; // disable Analog Comparator DDRB = 0b00000010; // set PORTB bit 1 as OUTPUT, the rest are INPUT's PORTB3_bit = 0; // disable internal pull-up on bit 3 of the PORTB PCINT3_bit = 1; // enable interrupt on PCINT3 PCIE_bit = 1; // enable pin change interrupts SREG_I_bit = 1; // enable interrupts }
void main() { init_sys(); for(;;) { // the LED on PORTB bit 0 will change state only when the pin change from HIGH to LOW and then HIGH again - schematic in FIG 1 was used if (flag >= 2) { SREG_I_bit = 0; // disable interrupts flag = 0; PORTB = (PORTB ^ 0x02); // toggle led on PORTB bit 1 SREG_I_bit = 1; // enable interrupts } } }
I've attached an archive that contain the mikroC for AVR project and Proteus 8.4 simulation. I hope that this will solve your problem. Unfortunately I don't code in Bascom but if you look at the program structure you might easily port it.
|
|
« Last Edit: July 15, 2016, 08:06:53 20:06 by mars01 »
|
Logged
|
|
|
|
sfiga69
Active Member
Offline
Posts: 188
Thank You
-Given: 198
-Receive: 159
In the order is preserved, in the mess is created.
|
|
« Reply #9 on: July 02, 2016, 05:37:06 17:37 » |
|
thanks mars01 I try and tell you if it works
|
|
|
Logged
|
|
|
|
kreutz
Active Member
Offline
Posts: 183
Thank You
-Given: 994
-Receive: 125
|
|
« Reply #10 on: July 03, 2016, 03:20:22 15:20 » |
|
Sfiga69, I can't see where you declare the interrupt type (rising edge, falling edge, etc) for int0 on the code above, and where you enable int0 specifically after enabling all interrups. At least in my older versions of BascomAVR you need to do that.
For example (on this code for an Atmega16):
Config Portd = &B11110011 ' PORTD AS output 0,1,4.5.6.7 and ' input portd2(Int0), portd3 (Int1)
'====================================== '---------------- Config Int0 = Rising 'PORTD.2 ZERO CROSING INTERRUPT PULSES ' 'ACTIVE HIGH USE THE RISING EDGE
Enable interrupts Enable Int0
|
|
« Last Edit: July 03, 2016, 04:34:19 16:34 by kreutz »
|
Logged
|
|
|
|
mars01
V.I.P
Hero Member
Offline
Posts: 537
Thank You
-Given: 696
-Receive: 1774
|
|
« Reply #11 on: July 03, 2016, 04:30:33 16:30 » |
|
Hi @kreutz, The OP is not working with the external interrupt INT0 but with pin change interrupt PCINT0:5 specifically with source 3 for the pin change interrupt, PCINT3.
@sfiga69, if you test the code that I posted and you use a mechanical button, make sure that you use a low pass filter on the interrupt pin to counter the bouncing of the contacts otherwise you might not see what you expect.
|
|
« Last Edit: July 03, 2016, 04:33:25 16:33 by mars01 »
|
Logged
|
|
|
|
kreutz
Active Member
Offline
Posts: 183
Thank You
-Given: 994
-Receive: 125
|
|
« Reply #12 on: July 03, 2016, 04:45:41 16:45 » |
|
From the BascomAVR help file:
"There are multiple interrupt sources and it depends on the used chip which are available. To allow the use of interrupts you must set the global interrupt switch with an ENABLE INTERRUPTS statement. This only allows that interrupts can be used. You must also set the individual interrupt switches on! ENABLE TIMER0 for example allows the TIMER0 interrupt to occur. With the DISABLE statement you turn off the switches..."
My partial code above is just an example.
Posted on: July 03, 2016, 05:40:19 17:40 - Automerged
mars01;
I will look into my old programs for a reference example on pin change interrupt but, basically, they should be similar.
|
|
« Last Edit: July 03, 2016, 04:59:25 16:59 by kreutz »
|
Logged
|
|
|
|
kreutz
Active Member
Offline
Posts: 183
Thank You
-Given: 994
-Receive: 125
|
|
« Reply #13 on: July 04, 2016, 03:02:48 03:02 » |
|
|
|
« Last Edit: July 04, 2016, 03:06:15 03:06 by kreutz »
|
Logged
|
|
|
|
sfiga69
Active Member
Offline
Posts: 188
Thank You
-Given: 198
-Receive: 159
In the order is preserved, in the mess is created.
|
|
« Reply #14 on: July 04, 2016, 12:09:02 12:09 » |
|
thanks at all, solved!!! In basic the problem is a configuration of pin PB3. @mars01, your code work.. I translated into basic your code in C and now works in particular: In C DDRB = 0b00000010; PORTB3_bit = 0; In basic Ddrb.3 = 0 ' PB3 = input for PCINT3 Config Portb.3 = 0 ' portb.3 disable pullup then moving before the interrupt configuration. in this way, it works correctly in 2 configurations $prog &HFF , &HF1 , &HDF , &HFF
$regfile = "attiny85.dat" $crystal = 16000000 $hwstack = 40 $swstack = 40 $framesize = 40
Ddrb.1 = 1 ' PB1 = output for led Ddrb.3 = 0 ' PB3 = input for PCINT3 Config Portb.3 = 0 ' portb.3 disable pullup
On Pcint0 Isr_int0 Set Gimsk.5 Set Pcmsk.3
Start1:
Enable Interrupts
Do
Loop End
Return
'*************************************************************************** '* interrupt routine INT0 '***************************************************************************
Isr_int0:
Toggle Portb.1
Return
for debouncing, no problem in fact P1 or P2 is a Reflective photosensor. this is a part of tachometer for spindler of my CNC. when I finished my puzzle, it will be published in projects thanks again to all
|
|
« Last Edit: July 04, 2016, 08:47:14 20:47 by sfiga69 »
|
Logged
|
|
|
|
sfiga69
Active Member
Offline
Posts: 188
Thank You
-Given: 198
-Receive: 159
In the order is preserved, in the mess is created.
|
|
« Reply #15 on: July 04, 2016, 08:37:00 20:37 » |
|
Sfiga69, I can't see where you declare the interrupt type (rising edge, falling edge, etc) for int0 on the code above, and where you enable int0 specifically after enabling all interrups. At least in my older versions of BascomAVR you need to do that.
in ATtiny85 only INT0 can select rising, falling and change. for PCINT0 (0:5) any change level triggers interrupt
|
|
|
Logged
|
|
|
|
|