|
|
View previous topic :: View next topic |
Author |
Message |
apakSeO
Joined: 07 Dec 2016 Posts: 60 Location: Northeast USA
|
PIC16F1779 INT_PWM Interrupt Seemingly not working |
Posted: Fri Feb 22, 2019 12:50 pm |
|
|
PIC16F1779 / CCS v5.081
This PIC has a 16-bit PWM module I have been working with for a while now. It has dedicated timers for the PWM modules, and dedicated period, duty, phase, and offset registers.
I've loaded the period, duty, and phase registers manually to get a working 50% duty cycle on my PWM12 output pin. Scope confirms.
psuedocode:
Code: |
PWM12PR = 0xBC40;
PWM12DC = 0x7D7D;
PWM12PH = 0x0000;
PWM12OF = 0x1234;
|
Now according to the PIC datasheet, I should be able to trigger an interrupt anywhere during the PWM period by (1) loading a value into the module's Offset Register (2) enabling the interrupt This is mentioned explicitly in section 26.6 of the datasheet for PIC16F1779
First I found that CCS v5.081 does not enable the interrupt using the usual method,it does not set the appropriate bit using:
Code: |
enable_interrupts(INT_PWM12);
|
So I mapped the register and enabled the bit that sets the Offset Interrupt manually:
Code: |
#byte PWM12INTIE = 0x0DCC
#bit PWM12INTIE_OFIE = PWM12INTIE.3
PWM12INTIE_OFIE = 1;
|
Then finally I specify my interrupt handler with some test code:
Code: |
#int_pwm12
void pwm12_offsetMatch_isr(void)
{
output_high(PIN_A0);
delay_us(200);
output_low(PIN_A0);
}
|
I pause execution during a debug mode and I find that ALL the interrupt flags are set for Phase, Duty, Period, and Offset interrupts:
... but it seems the interrupt doesn't trigger.
I've found the PWM stuff on this PIC generally isn't working the way the datasheet says probably because of the bewildering variety of ways to set it up that is not easily translated to the CCS compiler. So it doens't surprise me that the interrupt vector might not be working correctly either.
Can anybody help me determine what is happening here, why is my isr never getting called? [/code] |
|
|
apakSeO
Joined: 07 Dec 2016 Posts: 60 Location: Northeast USA
|
|
Posted: Fri Feb 22, 2019 2:09 pm |
|
|
Test code below:
Code: |
#include <16F1779.h>
#device PIC16F1779
#use delay(INTERNAL=16MHZ, CLOCK=8MHZ)
#fuses NOWDT
// EN PWM mirror register
#byte PWMEN = 0x0D8E
// PWM12 config registers
#byte PWM12CON = 0x0DCB
#byte PWM12CLKCON = 0x0DCE
#byte PWM12PRH = 0x0DC6
#byte PWM12PRL = 0x0DC5
#byte PWM12DCH = 0x0DC4
#byte PWM12DCL = 0x0DC3
#byte PWM12PHH = 0x0DC2
#byte PWM12PHL = 0x0DC1
#byte PWM12OFCON = 0x0DD0
#byte PWM12OFH = 0x0DC8
#byte PWM12OFL = 0x0DC7
#byte PWM12LDCON = 0x0DCF
#bit PWM12LDA = PWM12LDCON.7 // Must set this to '1' to load PH,DC,PR,OF
// registers immediately upon writing to them
// This bit is cleared by pwm module automatically
#byte PWM12INTIE = 0x0DCC
#bit PWM12INTIE_OFIE = PWM12INTIE.3
#define HIBYTE(x) ((x) >> 8)
#define LOBYTE(x) ((x) & 0x00FF)
void main(void)
{
// Set all PORTB as outputs
set_tris_b(0x00);
// Route PWM12 module to RB5
#pin_select PWM12OUT=PIN_B5
// Clock & control
PWM12CLKCON = 0x00; // No prescaler; clock source is Fosc
PWM12CON = 0x00; // Standard PWM mode polarity active high; PWM module is not enabled yet
// Period control
PWM12LDA = 1; // Must be '1' for immediate effect
PWM12PRH = HIBYTE(0x4000);
PWM12PRL = LOBYTE(0x4000);
// Phase control
PWM12LDA = 1; // Must be '1' for immediate effect
PWM12PHH = HIBYTE(0x0000);
PWM12PHL = LOBYTE(0x0000);
PWM12LDA = 1; // Offset register loaded with 0x1000
PWM12OFH = HIBYTE(0x1000);
PWM12OFL = LOBYTE(0x1000);
// Duty control
PWM12LDA = 1; // Must be '1' for immediate effect
PWM12DCH = HIBYTE(0x2000);
PWM12DCL = LOBYTE(0x2000);
PWMEN = 0x08; // PWM12 output is enabled
// Enable interrupt when PWM12 offset match occurs
// Use for ADC read triggering
// Should emulate the effects of enable_interrupts(INT_PWM12)
PWM12INTIE_OFIE = 1;
enable_interrupts(GLOBAL);
while(TRUE)
{
}
}
#INT_PWM12
void pwm12_offsetMatch_isr(void)
{
output_high(PIN_A0);
delay_us(200);
output_low(PIN_A0);
}
|
|
|
|
|
|
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
|