News:

Let's find out together what makes a PIC Tick!

Main Menu

Int0 + Int1 on a pic18f25k80

Started by TimB, Feb 01, 2022, 07:14 PM

Previous topic - Next topic

TimB



Hi all

I'm trying to figure out what's different about a pic18f25k80 that is preventing a simple routine working.
I just want to be sure a fan is working that has the inputs tied to RB0 and RB1 (Int0 and Int1)

I do not have the 25k80 in my very old version of the VSM but I tested it with the 25k22 in the VSM and it works.

Scope shows the signal getting to the pic. Its a nice square set of pulses (they are pulled up)

This the crux of the code written for the amicus board but for some reason the 25k80 is not seeing the flag change




    Include "amicus18.inc"

    Dim xFan1Int As  INTCONbits_INT0IF
    Dim xFan2Int As  INTCON3bits_INT1IF


    dim btemp1 as byte
    Dim bTemp2 as byte

    ; PortB 0 + 1  change on going high

     INTCON2bits_INTEDG0 = 1
     INTCON2bits_INTEDG1 = 1

    While 1 = 1

    delayms 500
    if xFan1Int = 1 then
        Inc btemp1
    Endif
    xFan1Int = 0

    if xFan2Int = 1 then
        Inc btemp2
    Endif
    xFan2Int = 0

    Wend



TimB


Ok found the issue

For some reason ANCON1 was loaded with %00000111

Cannot find out why but clearing it sorted the problem.

top204

#2
I'm afraid it is my fault, for not reading the datasheet for these devices and finding out they have, yet again, altered the way the pins are set from analogue to digital. I have the ANCONx SFRs set, when they should be cleared! So the device starts the program in its default mode of analogue inputs.

At the beginning of your program, add the code:

    Clear ANCON0
    Clear ANCON1

I tried the code below, and it worked after I cleared the SFRs:

    Device = 18F25K80
    Declare Xtal = 16
   
    Declare RSOut_Baud = 9600
    Declare RSOut_Pin = PORTC.6

$define INT0_Flag() INTCONbits_INT0IF                               ' The INT0 flag
$define INT0_FlagClear() Clear INT0_Flag()                          ' Clear the INT0 interrupt flag
$define INT0_RisingEdgeSet()  Set INTCON2bits_INTEDG0               ' Set INT0 for a rising edge
$define INT0_FallingEdgeSet() Clear INTCON2bits_INTEDG0             ' Set INT0 for a falling edge
$define INT0_Enable() Set INTCONbits_INT0IE                         ' Enable an INT0 Interrupt
$define INT0_Disable() Clear INTCONbits_INT0IE                      ' Disable an INT0 Interrupt
 
'----------------------------------------------------------------------
' The main program starts here
'
Main:
    Clear ANCON0                                                 
    Clear ANCON1                                                 

    RsOutLn "Wait"
   
    PinInput PORTB.0
    INT0_FallingEdgeSet()
   
    Do
        If INT0_Flag() = 1 Then
            INT0_FlagClear()
            RsOutLn "INT0 Activated"
        EndIf
    Loop

The circuit was a pull-up resistor on PORTB.0 with the button going to ground.

I'll make changes to the PIC18FxxK80 .def files and clear the SFRs so the pins default to digital before the user program starts. I truly wish they would make their mind up with SFR settings!!! One device family needs them set, another device family needs them cleared for analogue and digital mode... Why not all devices clear or all devices set? It's getting to the point of incompetence from them!!