Wow! 7 years & still adding pages! A conversation with Daryl led me here. I want to have an event occur just prior to the end of a PWM period. I was told it had to be done in assembly. My project is based on the PIC16F1828, uses CCP for PWM, DSM (Digital Signal Modulation) to embed HF within a slower PWM clock, and just before the Off/On I need to trigger an event. Got it working thanks to Daryl. Here's what it looks like:
The code looks like this:
define OSC 32
define ADC_BITS 8
define ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
#CONFIG
CONFIG1_FOSC_INTOSC
CONFIG1_MCLRE_OFF
CONFIG1_CLKOUTEN_OFF
CONFIG2_PLLEN_ON
#endconfig
OSCCON = %11110011
TRISA = %00111100
TRISB = %01100000
TRISC = %11001011
ANSELA = %00011111
ANSELB = %01100000
ANSELC = %11001011
WPUA = 0
WPUB = 0
WPUC = 0
MDSRC = %10000010 'DSM Activated (.7) on CCP1 (RC5) (<3:0>
MDCARH = %10000011 'OOK Mode
MDCARL = %10100000 'Disables Low Carrier Signal; OOK Mode
MDCON = %11000000 '.7 Enables OOK, .3 Current State (read only)
CLKRCON = %10110000
b0 var byte
b1 var byte
b1 = 0
LED1 VAR PORTC.5
TPS_In var PORTC.7 'AN9
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR2_INT, _SetTR4, PBP, yes
INT_Handler TMR4_INT, _GP, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'T1CON = %00110001 ; Prescaler=8, TMR1ON
@ INT_ENABLE TMR2_INT ; enable Timer 2 interrupts
Main:
adcin 9, b0
hpwm 1, b0, 1056
PAUSE 1
GOTO Main
'---[TMR1 - interrupt handler]--------------------------------------------------
SetTR4:
T4CON = T2CON
PR4 = PR2
TMR4 = TMR2 - 246
@ INT_ENABLE TMR4_INT
@ INT_RETURN
GP:
pulsout PORTC.5, 5
@ INT_DISABLE TMR4_INT
'@ INT_CLEAR TMR1_INT
@ INT_RETURN
end
All I can say is, I'm so glad I found ME Labs and now this forum. Overwhelming thanks to Charles, Daryl, and many whose work I've gleened from, but have yet to get to know personally.
Mike
Bookmarks