View previous topic :: View next topic |
Author |
Message |
sebalitter
Joined: 05 May 2015 Posts: 47
|
16F1823 IOC interrupt |
Posted: Mon Nov 04, 2024 12:09 pm |
|
|
Hello
the IOC_A4 interrupt is no working correctly on switching states
PCH v5.115.
Any ideas?
Code: |
#include <16F1823.h>
#device adc=10
#fuses INTRC_IO NOWDT BROWNOUT PUT NOLVP
#use delay(clock = 4000000) //Configuracion reloj interno
#define line_R PIN_A4
#define led_R PIN_A1
short alarm = FALSE;
void inicializacion() {
output_float(line_R);// Make pin A4 into an input.
output_drive(led_R); // Make pin A1 into an output.
//port_a_pullups(true);
//ext_int_edge(L_TO_H);
// turn on interrupts
clear_interrupt(INT_IOC); // Clear external interrupt flag bit
enable_interrupts(INT_IOC_A4_L2H);
enable_interrupts(INT_IOC);
enable_interrupts(GLOBAL);
}
#INT_IOC
void ioc_isr(void){
if(interrupt_active(INT_IOC_A4))
alarm = 1;
}
void main()
{
inicializacion();
while(TRUE){
if(alarm){
output_toggle(led_R);
delay_ms(1000);
alarm= 0;
//clear_interrupt(INT_IOC);
}
}
}
|
Last edited by sebalitter on Mon Nov 04, 2024 3:30 pm; edited 2 times in total |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Nov 04, 2024 2:15 pm |
|
|
Maybe I'm wrong, but I feel that your logic is not the soundest here. What is the point of checking if the interrupt is active once you are already there? It seems by the way you coded it, it will arrive in your interrupt routine every time there is an L2H change. You clear the interrupt. Output high led_R. Else will never get executed, since you only come there with an active interrupt and you clear that right away. How do you expect to come to the else part?
What do you want to happen? Turn on the led for 200ms on every interrupt?
And as it was reiterated here like million of times, never use delays inside interrupts. They are meant to be serviced as quickly as possible. Set a flag there, clear some bits, restart a timer, change the logic for the next interrupt. No heavy mathematics, no delays. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Nov 04, 2024 2:41 pm |
|
|
As a side note. Main should do all the heavy work, interrupts are there just to tell the main what to do. It depends on what you are trying to control, but it is always a good idea to run your pic as fast as it can reliably work. Gives you more instructions between two interrupts to do what interrupt commanded. Less time to come to the interrupt routine itself and less time spent there. A win-win situation. |
|
|
sebalitter
Joined: 05 May 2015 Posts: 47
|
|
Posted: Mon Nov 04, 2024 3:18 pm |
|
|
PrinceNai wrote: | As a side note. Main should do all the heavy work, interrupts are there just to tell the main what to do. It depends on what you are trying to control, but it is always a good idea to run your pic as fast as it can reliably work. Gives you more instructions between two interrupts to do what interrupt commanded. Less time to come to the interrupt routine itself and less time spent there. A win-win situation. |
Thanks. I changed the code but it still doesn't enter the interrupt.
Do I have to put a clean_interrupt somewhere? Are the fuses OK? |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Nov 04, 2024 3:45 pm |
|
|
Not entering and not working correctly isn't the same :-). How do you check if the interrupt was ever fired? In your code pull-ups are not enabled (commented out). |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Nov 04, 2024 3:48 pm |
|
|
As always, the basic 1s blink led is useful to tell if timings and settings are ok and that your Pic is alive. An example is maybe two threads down. So two questions. Does your Pic work with the desired speed? How do you know it doesn't enter the interrupt? Your new code? |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Nov 04, 2024 4:24 pm |
|
|
Maybe this could be under sticky. The code does what you wrote, not what you thought it would do |
|
|
sebalitter
Joined: 05 May 2015 Posts: 47
|
|
Posted: Mon Nov 04, 2024 4:29 pm |
|
|
PrinceNai wrote: | As always, the basic 1s blink led is useful to tell if timings and settings are ok and that your Pic is alive. An example is maybe two threads down. So two questions. Does your Pic work with the desired speed? How do you know it doesn't enter the interrupt? Your new code? |
It's working now. There was a false contact on the trigger.
Could you tell me how you deal with false contacts?
What is the best way to work with prototype PCBs? |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Nov 04, 2024 4:59 pm |
|
|
False contacts? Do yo mean debouncing?
Last edited by PrinceNai on Mon Nov 04, 2024 6:59 pm; edited 1 time in total |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Nov 04, 2024 6:56 pm |
|
|
For the forum. What is working and what you did to make it work? Maybe your code? It will help others for sure. |
|
|
sebalitter
Joined: 05 May 2015 Posts: 47
|
A #DEVICE required |
Posted: Fri Nov 08, 2024 4:24 pm |
|
|
PrinceNai wrote: | For the forum. What is working and what you did to make it work? Maybe your code? It will help others for sure. |
im trying to Sends a message when the power is cut off.
For this, use the interrupt on change and the GSM A6. together with the code you posted in
[url]
https://www.ccsinfo.com/forum/viewtopic.php?p=225208
[/url]
I will publish the code working here. let me fix some bugs first.
I can't compile, it gives me an error
functions.c:0:0: Error#128 A #DEVICE required before this line:
the header is this:
Code: |
#include <16F1823.h>
//#include "test.h" //fuses, uses
#device PASS_STRINGS = IN_RAM //copy all the strings to RAM to allow access with pointers
#device adc=10 //10 bit AD resolution
#device ICD=TRUE
#FUSES DEBUG //No Watch Dog Timer
#include <stdlib.h>
#FUSES WDT //Watch Dog Timer
//#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc, high power 16MHz-25MHz
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES PUT
#use delay(crystal=20000000) //20Mhz clock
//#use delay(internal=32000000)
#use rs232(parity=N,xmit=PIN_C5,rcv=PIN_C4,bits=8,stream=GSM,errors)
#use i2c(Master,slow,sda=PIN_C2,scl=PIN_C1 ) // ,force_hw)
#include <defs.h> //definitions of pins and registers
#include <string.h>
#include <ctype.h>
//***********************************************************************
// includes
//***********************************************************************
#include "i2c_Flex_LCD.c"
#include <functions.c> //all the functions
|
functions.c has just some functions like
void Blink_Led (void){
output_low(OK_STATUS);
delay_ms(20);
output_high(OK_STATUS);
}
any ideas?
Last edited by sebalitter on Sat Nov 09, 2024 7:39 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Sat Nov 09, 2024 4:05 am |
|
|
Two things.
First, your include of the lcd driver should be after the fuses.
The sequence should always be:
Processor
Fuses
Clock
Then and only then other includes.
The fuses and clock can be swapped (depends on whether you want the
clock setting to set the clock fuses, or want to override these yourself).
Now the key thing missing from what you post is the clock setting.
If that doesn't fix it, post what is in the start of your functions.c |
|
|
sebalitter
Joined: 05 May 2015 Posts: 47
|
|
Posted: Sat Nov 09, 2024 7:42 am |
|
|
Ttelmah wrote: | Two things.
First, your include of the lcd driver should be after the fuses.
The sequence should always be:
Processor
Fuses
Clock
Then and only then other includes.
The fuses and clock can be swapped (depends on whether you want the
clock setting to set the clock fuses, or want to override these yourself).
Now the key thing missing from what you post is the clock setting.
If that doesn't fix it, post what is in the start of your functions.c |
Sorry, I forgot to add the test.h that has all those settings. I changed it.
still getting:
functions.c:0:0: Error#128 A #DEVICE required before this line |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Sat Nov 09, 2024 8:13 am |
|
|
So, as I said, you need to show us the first few lines of this file, |
|
|
sebalitter
Joined: 05 May 2015 Posts: 47
|
|
Posted: Sat Nov 09, 2024 8:20 am |
|
|
Ttelmah wrote: | So, as I said, you need to show us the first few lines of this file, |
functions.c
Code: |
void Blink_Led (void);
void Blink_CO_Led(void);
void Init_GSM (void);
void Get_Baudrate(void);
void Set_Baudrate ();
void Clear_UART_Buffer();
void Wait_OK_Response(void);
void Wait_ONLINE_Response(void);
void Wait_Arrow_Space(void);
void Check_Registration(void);
void GSM_Send(char *s);
unsigned ComposeMessage(char* Message);
// ************************** BLINK OK LED ************************************
void Blink_Led(){
output_low(OK_STATUS);
delay_ms(20);
output_high(OK_STATUS);
}
// ************************** BLINK CO LED ************************************
void Blink_CO_Led(){
output_low(CO_LED);
delay_ms(20);
output_high(CO_LED);
}
....
|
|
|
|
|