CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

16F1619 How to use AT interrupts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dmitrboristuk



Joined: 26 Sep 2020
Posts: 63

View user's profile Send private message

16F1619 How to use AT interrupts
PostPosted: Mon Jan 27, 2025 3:21 am     Reply with quote

This topic is related to my previous post where there were problems with BRA/BRW. The problem turned out to be deeper. When analyzing with an oscilloscope, it turned out that the AT1MISSIF interruption does not work. I moved the code to a separate project and tried to view it. The AT_PHASE_INTERRUPT and AT_PERIOD_INTERRUPT interrupts work correctly, but there is no effect from AT_MISSING_PULSE_INTERRUPT. Moreover, it is absent both in fixed mode and in adaptive mode. Can you take a look with your authoritative eye and show me what I did wrong.

Code:

// CCS compiller PCM 5.115
#include <78778.h>

#pin_select ATIN = pin_B5   // from Gen 23...68 Hz

#int_AT1
void at (void)
{
   if (at_interrupt_active(AT_PERIOD_INTERRUPT))    // very good!
      {
        output_high(pin_A5);               // 27 us
    for (int8 i = 0; i < 20; ++i)
    {
        #asm
        nop
        nop
        #endasm
    }
        output_low(pin_A5);
        at_clear_interrupts(AT_PERIOD_INTERRUPT);
      }
     
if (at_interrupt_active(AT_PHASE_INTERRUPT))     // very good! ~F*600
  {
          output_high(pin_A2);               // 27 us
    for (int8 i = 0; i < 20; ++i)
    {
        #asm
        nop
        nop
        #endasm
    }
        output_low(pin_A2);
    at_clear_interrupts(AT_PHASE_INTERRUPT);
  }
if (at_interrupt_active(AT_MISSING_PULSE_INTERRUPT))   // no effect
  {
          output_high(pin_A0);               // 27 us
    for (int8 i = 0; i < 20; ++i)
    {
        #asm
        nop
        nop
        #endasm
    }
        output_low(pin_A0);
    at_clear_interrupts(AT_MISSING_PULSE_INTERRUPT);
  }
}

void main()
{
setup_at(
  AT_ENABLED
| AT_SINGLE_PULSE_MODE
//| AT_FIXED_MISSING_PULSE_MODE
| AT_FIXED_MISSING_PULSE_MODE
| AT_RISING_EDGE_ATSIG
| AT_CLOCK_PRESCALAR_DIV_8
| AT_PRESCALAR_RESET_EVERY_PERIOD
| AT_MISSING_PULSE_ACTIVE_HIGH
| AT_PERIOD_CLOCK_ACTIVE_HIGH
| AT_PHASE_CLOCK_ACTIVE_HIGH
| AT_CLOCK_HFINTOSC
| AT_INPUT_ATIN
);

at_set_resolution (599);
at_set_missing_pulse_delay(-900);  // non for adaptive

at_enable_interrupts(AT_PHASE_INTERRUPT);
at_enable_interrupts(AT_MISSING_PULSE_INTERRUPT);
at_enable_interrupts(AT_PERIOD_INTERRUPT);

enable_interrupts(INT_AT1);
enable_interrupts(GLOBAL);

   while(TRUE);

}
temtronic



Joined: 01 Jul 2010
Posts: 9342
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 27, 2025 6:33 am     Reply with quote

I don't have that PIC so can't test but...

I'd reduce code to minimal code,compile,test, and then dump the listing, grab the datasheet and confirm the proper registers ARE being configured correctly.
Perhaps the compiler version is setting the wrong bit ,either in setup or interrupt enable ??
I don't know... but the listing file (project.LST) is what you need to quickly figure this out.

WOW, that internal peripheral is far more powerful than the first PICs I played with !!! Had a quik read of the 'AT chapter' and 2 things. One SEVERAL registers need to be setup and if setup correctly, unless you HAVE a 'missing pulse', you don't get an interrupt. So, so you have a means to send the PIC a valid 'missing pulse'
dmitrboristuk



Joined: 26 Sep 2020
Posts: 63

View user's profile Send private message

PostPosted: Mon Jan 27, 2025 7:14 am     Reply with quote

temtronic
I looked at the listing, the names of the registers and bits correspond to the device datasheet.
For the missing pulse I simply disconnect the external generator cord. This is an imitation of the shaft stopping.
at_set_missing_pulse_delay(-900); // non for adaptive
Do I understand correctly that the number is negative? With this value, the interrupt should occur 900 counts after the end of the counter register value of the previous period?
It also does not work with a positive value. In adaptive mode, where this number is not needed, it also does not work.

Code:

78778.h
#include <16F1619.h>
#device ADC=10
#use delay(internal=32MHz) //


Last edited by dmitrboristuk on Mon Jan 27, 2025 7:26 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9342
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 27, 2025 7:22 am     Reply with quote

re: at_set_missing_pulse_delay(-900); // non for adaptive

I don't have any info about this line. To me it says 'pass the number -900, to a function called 'at_set_missing_pulse_delay'.
So it's passing a signed 16 bit ??

just downloaded latest(?) CCS manual 2021 and nothing about 'AT' peripheral in it !

sorry I can't help more
dmitrboristuk



Joined: 26 Sep 2020
Posts: 63

View user's profile Send private message

PostPosted: Mon Jan 27, 2025 7:34 am     Reply with quote

temtronic
In the 2021 manual on pages 216-230 functions for AT
in the function prototype
Code:
_bif void at_set_missing_pulse_delay(signed int16 missing_pulse_delay);

in the datasheet AT1MISS value 2’s complement
Ttelmah



Joined: 11 Mar 2010
Posts: 19634

View user's profile Send private message

PostPosted: Mon Jan 27, 2025 8:22 am     Reply with quote

I suspect the problem is going to be the settings. This is a horrid mode!....
The adaptive should be easier to get working, so I'd suggest you try with
this first. On the adaptive, it takes half the period as it's test value, and
sets the miss, when the count exceeds this by 50%. Now on the fixed
mode, it compares the period counter and the latched value with the
offset you specify. I don't think a -ve value here is ever going to work.
So though it supports using a signed value, I'd start by trying a positive
value here.
temtronic



Joined: 01 Jul 2010
Posts: 9342
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 27, 2025 8:32 am     Reply with quote

thanks for pointing me to the info ! Silly me, I just looked at the 'table of contents' it 'has' to be listed...., saw various internal peripherals but not the AT one...
next time I'll press F3 and see what pops up.

Maybe use Google and see what others are doing ?? Even if in another C, you should be able to convert into workable code.

Still think you need to have a source of 'good pulses' and a KNOWN 'missing pulse'.
dmitrboristuk



Joined: 26 Sep 2020
Posts: 63

View user's profile Send private message

PostPosted: Mon Jan 27, 2025 2:40 pm     Reply with quote

I tried to check on PIC16F1618 2020. It behaves the same way. I don't even know what to do next. These chips have been produced for more than 10 years. Has anyone encountered this behavior?
temtronic
I use single pulse mode. I don't need a disk with many teeth and one missing tooth. It is enough to simply remove the generation and fix the stop after 1.5 T.
Ttelmah
AT also does not work for me with positive numbers. Perhaps there is some range of numbers. But nothing is said about it. Also, the logic of the comparison is not clear. Let's say the current value is subtracted from the captured value of the previous period. After the number becomes zero, negative values ​​​​go. But these are my assumptions, the register where the calculations take place is not available.
Ttelmah



Joined: 11 Mar 2010
Posts: 19634

View user's profile Send private message

PostPosted: Mon Jan 27, 2025 11:10 pm     Reply with quote

Agree. Wonder if there is a Microchip application note on this peripheral?
The data sheet is annoying, talking as if the trigger should happen in
a complex combination of circumstances, but not actually listing the basic
maths involved.
I suspect most users have used the period detection, but not the missing
pulse option. I know this is what I did.
AN1980, gives a lot about pulse width calculations etc., but not the missing
pulse detection.
TB3143, looks to be the one to read. This does show the actual maths
involved.
On the values involved, these depend totally on the frequencies you are
using, and the clock sources you have selected for this peripheral.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group