PDA

View Full Version : What happens if interrupt breaks PULSIN, PULSOUT, ADCIN, PWM, etc statements?



CuriousOne
- 13th February 2017, 06:54
Hello.

Say there is some code, which runs in loop, and measures frequency at one pin, measures voltage at another pin and does something extra.

There is also an interrupt configured, so when signal on certain pin gets high, another piece of code is launched, which will take about 1 millisecond to execute. What will happen? as I understand, all above mentioned operations will be disrupted, and measurements need to be retaken, correct?

HenrikOlsson
- 13th February 2017, 07:20
If you're using PBP ON INTERRUPT then nothing happens because it always waits for the current command to "complete" before servicing the interrupt.

If you're using "real" interrupts (in ASM or using DT-INTS for example) then it's different:

If an interrupt occurs in the middle of a...
...PULSOUT command the width of the generated pulse will be extended by the amount of time that the interrupt takes.
...PULSIN command the measured width will be off by (up to) the amount of time that the interrupt takes.
...PWM command the PWM "signal" will just stop being generated for the duration of the interrupt. (Not applicable for HPWM of course).
...ADCIN command generally nothing happens. There's usually no harm in sampling the signal longer than needed and once sampled the actual conversion is done without software.

Generally speaking whatever the PIC is doing is put on hold for the duration of the interrupt + context save/restore. This means that ALL commands using software timing will be affected.

/Henrik.

CuriousOne
- 13th February 2017, 08:40
Yes I want to use "real" interrupts, since the task is to be executed in time. Thanks a lot.

CuriousOne
- 13th February 2017, 09:03
So if I understood correctly, if PULSOUT was generating "1" at moment of triggering, output will be held "1" till the interrupt completes? that is bad....

HenrikOlsson
- 13th February 2017, 10:19
Correct, if you have PULSOUT generating a 100us pulse and an interrupt occurs while the pulse is being generated the actual pulsewidth will be "extended" for the duration of the interrupt. Bad, perhaps, but that's how interrupts work, they interrupt whatever the processor is doing (ie keeping track of time in order to generate a 100us wide pulse) and goes off doing something else, more important. If generating the 100us pulse is the most important/critical task then perhaps THAT should be done using interrupts.

/Henrik.

CuriousOne
- 13th February 2017, 12:26
Ok, so I have to move additional routine, which will ensure that output is "0", when interrupt will happen.

Art
- 17th February 2017, 02:53
If the application allows you can disable interrupts while
those commands are running, and re-Enable straight after.
No good for some applications such as a real time counter
but in others you coupd get away with it.

CuriousOne
- 19th February 2017, 08:02
Two more interrupt/timer/pwm questions, if you don't mind.

1. Is it possible to configure timer to enable-disable hpwm generator at predefined time amounts? say, 1 second on, 1 second off. So all this code will run in background, without taking CPU time?
2. Is it possible to change interrupt type on the fly? Say, interrupt was set to rising edge, it happened, and now changed to falling edge ?

HenrikOlsson
- 19th February 2017, 10:39
1) For a short answer I would say no, not really but a standard timer interrupt can easily be used (which then obviously uses a combination of hardware (the timer) and software (the interrupt service routine). For a 100% hardare solution, I guess it depends on which PIC you're using and what features/peripherals it's got. It's possible that it's doable by combining for example the special event triggers and/or the configurable logic cell available on some devices but I haven't looked into it so I can't say for sure if it's possible or not.

2) Sure, no problems with that.

/Henrik.

CuriousOne
- 20th February 2017, 05:38
Thanks!

For the #1, I've read 16F1829 datasheet, and it says that it can emulate 555 timer in hardware, so I guess, it might be possible to do what I want.

For the #2, I see this In the following way:

Interrupt was set to rising edge, it happened, and code is launched, which does what it should do, in loop. Same time, interrupt type is changed to falling edge, so when signal on interrupt pin gets low, code is terminated and main code execution continues. This is what I want to do.

JimAvanti
- 6th March 2017, 21:56
Can you just turn the interrupt off just before executing the Pulsout command and then turn it back on just after it is complete?