Hi, I am trying to do some basic PWM input using input capture with the ECT. I do not understand why it is not working. I've got a HCS12 (9S12DP256). Here's some code: PWME EQU $A0 PWMPOL EQU $A1 PWMCLK EQU $A2 PWMPRCLK EQU $A3 PWMCAE EQU $A4 PWMCTL EQU $A5 PWMSCLA EQU $A7 PWMPER0 EQU $B4 PWMDTY0 EQU $BC TIOS EQU $40 ;SELECT I/O DIRECTION TNCT EQU $44 ;44-45 TIMER COUNT REG TSCR1 EQU $46 ;TIMER SYSTEM CR 1 - BASIC TIMER PROPERTIES TCTL4 EQU $4B ;TIMER CR 4 - SET CAPTURE EDGE TIE EQU $4C ;TIMER INTERUPT ENABLE TSCR2 EQU $4D ;TIMER SYSTEM CR 2 TFLG1 EQU $4E ;FLAGS INDICATING INTERUPT (NON HARDWARE) TFLG2 EQU $4F ;MSB SET WHEN TIMER OVERFLOWS TC0 EQU $50 ;16-BIT REG /W COUNTER VALUE ORG RAM_START ;GENERATE OUTPUT PWM MOVB #$00,PWMCTL ; MOVB #$03,PWMCLK ;SA CLOCK MOVB #$FF,PWMPRCLK ; /128 = 62500HZ MOVB #$FF,PWMSCLA ;625000/(2(255+1) = 122 MOVB #$03,PWMPOL ;ACTIVE HIGH MOVB #$00,PWMCAE ;LEFT ALIGNED MOVB #$02,PWMPER0 ;new 1/122 * 2 MOVB #$7F,PWMDTY0 ;PWMDTY0/PWMPER0 * 100% MOVB #$03,PWME ;EN PWM CH0 ;START INPUT CAPTURE MOVB #$90,TSCR1 ;EN COUNTER, EN FFC MOVB #$00,TIOS MOVB #$01,TCTL4 ;CAPTURE RISING EDGE ON CH0 MOVB #$FF,TIE ;REG INTERUPTS OCCUR MOVB #$00,TSCR2 ;SLOWEST SAMPLE TIME MOVB #$80,TFLG2 LOOP: LDAA TFLG2 TSTA ;TEST IF OVERFLOW BNE OFLOW NOP LDAA TFLG1 TSTA ;TEST IF INTERUPT BIT SET BEQ LOOP NOP LDD TC0 JMP PAST OFLOW: CLRA LDAB #$01 PAST: NOP |
|

Measuring PWM /w input capture ECT
Started by ●December 26, 2002
Reply by ●December 30, 20022002-12-30
Please guys I'm really stuck here. I'm trying to do my 4th year
ECE project and this code is driving me nuts. Thanks. --- In , "jeffguilfoil <jeffguilfoil@y...>" <jeffguilfoil@y...> wrote: > Hi, > I am trying to do some basic PWM input using input capture with the > ECT. I do not understand why it is not working. I've got a HCS12 > (9S12DP256). Here's some code: > > PWME EQU $A0 > PWMPOL EQU $A1 > PWMCLK EQU $A2 > PWMPRCLK EQU $A3 > PWMCAE EQU $A4 > PWMCTL EQU $A5 > PWMSCLA EQU $A7 > PWMPER0 EQU $B4 > PWMDTY0 EQU $BC > > TIOS EQU $40 ;SELECT I/O DIRECTION > TNCT EQU $44 ;44-45 TIMER COUNT REG > TSCR1 EQU $46 ;TIMER SYSTEM CR 1 - BASIC TIMER > PROPERTIES > TCTL4 EQU $4B ;TIMER CR 4 - SET CAPTURE EDGE > TIE EQU $4C ;TIMER INTERUPT ENABLE > TSCR2 EQU $4D ;TIMER SYSTEM CR 2 > TFLG1 EQU $4E ;FLAGS INDICATING INTERUPT (NON > HARDWARE) > TFLG2 EQU $4F ;MSB SET WHEN TIMER OVERFLOWS > TC0 EQU $50 ;16-BIT REG /W COUNTER VALUE > > ORG RAM_START > > ;GENERATE OUTPUT PWM > > MOVB #$00,PWMCTL ; > MOVB #$03,PWMCLK ;SA CLOCK > MOVB #$FF,PWMPRCLK ; /128 = 62500HZ > MOVB #$FF,PWMSCLA ;625000/(2(255+1) = 122 > MOVB #$03,PWMPOL ;ACTIVE HIGH > MOVB #$00,PWMCAE ;LEFT ALIGNED > MOVB #$02,PWMPER0 ;new 1/122 * 2 > MOVB #$7F,PWMDTY0 ;PWMDTY0/PWMPER0 * 100% > MOVB #$03,PWME ;EN PWM CH0 > ;START INPUT CAPTURE > > MOVB #$90,TSCR1 ;EN COUNTER, EN FFC > MOVB #$00,TIOS > MOVB #$01,TCTL4 ;CAPTURE RISING EDGE ON CH0 > MOVB #$FF,TIE ;REG INTERUPTS OCCUR > MOVB #$00,TSCR2 ;SLOWEST SAMPLE TIME > MOVB #$80,TFLG2 > > LOOP: LDAA TFLG2 > TSTA ;TEST IF OVERFLOW > BNE OFLOW > NOP > LDAA TFLG1 > TSTA ;TEST IF INTERUPT BIT SET > BEQ LOOP > NOP > LDD TC0 > JMP PAST > > OFLOW: > CLRA > LDAB #$01 > > PAST: > NOP |
|
Reply by ●December 30, 20022002-12-30
In a message dated 12/30/02 7:15:36 PM Eastern Standard Time, writes: > Please guys I'm really stuck here. I'm trying to do my 4th year ECE > project and this code is driving me nuts. Hi Jeff. Why not just run the pwm into an rc lo pass filter, and run that into an a/d input? The a/d reads the avg voltage of the pwn waveform from the cap. This is exactly what you want, right? |
|
Reply by ●December 31, 20022002-12-31
> ECT. I do not understand why it is not working. I've got a HCS12
Your PWM regs are not initialized correctly, specially the PWMPER0. This one works for me, change the clock for higher freq. PWME0 equ $01 PWME1 equ $02 PWME2 equ $04 PWME3 equ $08 PWME4 equ $10 PWME5 equ $20 PWME6 equ $40 PWME7 equ $80 ***************************** Program ******************************* CodeSec: SECTION PWMInit bset DDRP,PWME0+PWME1 ;Bit 1,0 = o/p movb #%00000000, PWME ;All channels disabled movb #%00000000, PWMPOL ;Low during duty cycle movb #%00000000, PWMCLK ;Clock SA & Clock SB movb #%01110111, PWMPRCLK ;Clock A = Bus Clock / 128, Clock B = Bus Clock / 128 movb #%00000000, PWMCAE ;All channels operate in Left Aligned Output Mode movb #%00001100, PWMCTL ;No concatenation movb #%00000000, PWMSCLA ;Clock SA = Clock A / ( 2 * 256) movb #%00000000, PWMSCLB ;Clock SB = Clock B / ( 2 * 256) movb #%11111111, PWMPER0 movb #%11111111, PWMPER1 clr grey_area_flg1 ;This flag is used in close proximity of the sensors clr grey_area_flg2 ;This flag is used in close proximity of the sensors clr check_eye_flag movw #go_Forward,RobotState rts go_Robot_ready bset PWME,PWME0+PWME1 ;enable PWM0 and PWM1 movw #go_check_Front,RobotState rts go_check_Back rts go_Turn_on_a_dime ;Enable Right Servo movb #%11111000, PWMDTY0 movb #%11111000, PWMDTY1 bset PWME,PWME0+PWME1 ;enable PWM0 and PWM1 rts |
|
Reply by ●December 31, 20022002-12-31
--- In , BobGardner@a... wrote: > Hi Jeff. Why not just run the pwm into an rc lo pass filter, and run that > into an a/d input? The a/d reads the avg voltage of the pwn waveform from the > cap. This is exactly what you want, right? > Thanks for the reply. Yes, I suppose the results using your technique are what I'm looking for. I will be using a signal from a automobile crank angle sensor, so the length of the highs changes perportionally with the length of the lows. Do you see any problems with your suggested approach? The only issue I see is what if the start of the sample doesn't land on the same part of the pulse wave and the sample time is rather short the value might quiet different. Thoughts? Jeff |
|
Reply by ●December 31, 20022002-12-31
--- In , "zeta_alpha2002 <zeta_alpha2002@y...>" <zeta_alpha2002@y...> wrote: > > ECT. I do not understand why it is not working. I've got a HCS12 > > Your PWM regs are not initialized correctly, specially the PWMPER0. > This one works for me, change the clock for higher freq. Thanks for the reply. I tried the settings you suggested, it's still not working. If I do 62500hz/256 = 122hz output (PWMCLK=$03 SA clock, PWMPRCLK=$0F SA = 8mhz/128, PWMSCLA=$00 SAb500hz/2, PWMPER0=$0F SA2500/256) and select input capture of 8mhz/256 = 32500hz sample. The 16-bit input capture register never fills and the timer always overflows. I've tested the PWM output on it's slowest setting with a multimeter and it is working. Feeding the PWM output into the input capture pin always results in timer overflow. Any ideas? Thanks again, Jeff |
|
Reply by ●December 31, 20022002-12-31
In a message dated 12/31/02 6:12:39 PM Eastern Standard Time, writes: > Yes, I suppose the results using your technique are what I'm looking > for. I will be using a signal from a automobile crank angle sensor, > so the length of the highs changes perportionally with the length of > the lows. Do you see any problems with your suggested approach? The > only issue I see is what if the start of the sample doesn't land on > the same part of the pulse wave and the sample time is rather short > the value might quiet different. Thoughts? Well, you're the engine controller expert..... but I'll say that the rc analog averager will give you an average over several crank revs depending on the rc time constant... is this tolerable or do you need the instantaneous crank angle of that particular rev? |
Reply by ●January 1, 20032003-01-01
This one works for me. I used PWM1 output and IC3 to measure PWM1. I got 1/(32640 counts * 125E-9)=~245hz. I verified result with frequency counter. Var2 is the result of the difference between 1st and 2nd capture of falling edges. Note that if the frequency is doubled then there would be a problem with overflow, so some readjustment is required for your apps. Hope this one would help - good luck. bset TSCR1,%10000000 ;TEN=1 - Enable timer bset TIE,%1000 ;Enable input capture 3 bset TFLG1,%1000 ;Clear input capture 3 interrupt movb #%10000000,TCTL4 ;Capture on Falling edge clr capFlag PWMInit bset DDRP,PWME0+PWME1 ;Bit 1,0 = o/p movb #%00000000, PWME ;All channels disabled movb #%00000000, PWMPOL ;Low during duty cycle movb #%00000000, PWMCLK ;Clock SA & Clock SB movb #%01110111, PWMPRCLK ;Clock A = Bus Clock / 128, Clock B = Bus Clock / 128 movb #%00000000, PWMCAE ;All channels operate in Left Aligned Output Mode movb #%00001100, PWMCTL ;No concatenation movb #%00000000, PWMSCLA ;Clock SA = Clock A / ( 2 * 256) movb #%00000000, PWMSCLB ;Clock SB = Clock B / ( 2 * 256) movb #%11111111, PWMPER0 movb #%11111111, PWMPER1 movb #%11111000, PWMDTY0 movb #%10000000, PWMDTY1 bset PWME,PWME0+PWME1 ;enable PWM0 and PWM1 rts ;--------------------------------- --------- IC3Int ldd TC3 pshd ;Save momentarily ldaa capFlag ;Check if 1st or 2nd capture bne SecondCap ;If flag is set then it is 2nd falling edge puld std Var1 ;1st Capture movb #1,capFlag bra ICex ;Wait until next capture SecondCap puld subd Var1 ;Subtract from 1st Capture std Var2 ;Result in Var2 clr capFlag ICex movb #%00001000,TFLG1 ;Clear input capture 3 interrupt rti --- In , "jeffguilfoil <jeffguilfoil@y...>" <jeffguilfoil@y...> wrote: > --- In , "zeta_alpha2002 <zeta_alpha2002@y...>" > <zeta_alpha2002@y...> wrote: > > > ECT. I do not understand why it is not working. I've got a > HCS12 > > > > Your PWM regs are not initialized correctly, specially the > PWMPER0. > > This one works for me, change the clock for higher freq. > > Thanks for the reply. > > I tried the settings you suggested, it's still not working. If I do > 62500hz/256 = 122hz output (PWMCLK=$03 SA clock, PWMPRCLK=$0F SA = > 8mhz/128, PWMSCLA=$00 SAb500hz/2, PWMPER0=$0F SA2500/256) and > select input capture of 8mhz/256 = 32500hz sample. The 16-bit input > capture register never fills and the timer always overflows. > > I've tested the PWM output on it's slowest setting with a multimeter > and it is working. Feeding the PWM output into the input capture pin > always results in timer overflow. > > Any ideas? > Thanks again, > Jeff |
|
Reply by ●January 2, 20032003-01-02
Do you have any code that can do that, I would be very interested in
getting the sub routine and examining that. Is that like a mag pickup input to the unit, this crank sensor. What would be the sampling rate of the a/d what is the frequency ranges of the input signal? I am working on something similar but don't know if its the same or not. Stephen Mac Neil -----Original Message----- From: jeffguilfoil <> [mailto:] Sent: Tuesday, December 31, 2002 7:12 PM To: Subject: [68HC12] Re: Measuring PWM /w input capture ECT (Please help) --- In , BobGardner@a... wrote: > Hi Jeff. Why not just run the pwm into an rc lo pass filter, and run that > into an a/d input? The a/d reads the avg voltage of the pwn waveform from the > cap. This is exactly what you want, right? > Thanks for the reply. Yes, I suppose the results using your technique are what I'm looking for. I will be using a signal from a automobile crank angle sensor, so the length of the highs changes perportionally with the length of the lows. Do you see any problems with your suggested approach? The only issue I see is what if the start of the sample doesn't land on the same part of the pulse wave and the sample time is rather short the value might quiet different. Thoughts? Jeff -------------------- |
|
Reply by ●January 2, 20032003-01-02
I don't have code working yet, that's why I posted here. :)
Judging from the way the CAS signal looks I would guess that it's mag pickup or something. A pulse is created every crankshaft rotation figure 7000RPM ~= 117hz. I'm reluctant to do the A/D method because my sample periods will be pretty short and I think doing it with assured accuracy is pretty much the input capture method. I'll give it a try if/when I rule out the input capture. Input capture should work, but I can't get it to! I starting to feel like a real idiot. :) --- In , "Stephen Mac Neil" <macneil@d...> wrote: > Do you have any code that can do that, I would be very interested in getting > the sub routine and examining that. Is that like a mag pickup input to the > unit, this crank sensor. What would be the sampling rate of the a/d what is > the frequency ranges of the input signal? I am working on something similar > but don't know if its the same or not. > > Stephen Mac Neil > -----Original Message----- > From: jeffguilfoil <jeffguilfoil@y...> > [mailto:jeffguilfoil@y...] > Sent: Tuesday, December 31, 2002 7:12 PM > To: > Subject: [68HC12] Re: Measuring PWM /w input capture ECT (Please help) > > > --- In , BobGardner@a... wrote: > > Hi Jeff. Why not just run the pwm into an rc lo pass filter, and > run that > > into an a/d input? The a/d reads the avg voltage of the pwn > waveform from the > > cap. This is exactly what you want, right? > > > > Thanks for the reply. > > Yes, I suppose the results using your technique are what I'm looking > for. I will be using a signal from a automobile crank angle sensor, > so the length of the highs changes perportionally with the length of > the lows. Do you see any problems with your suggested approach? The > only issue I see is what if the start of the sample doesn't land on > the same part of the pulse wave and the sample time is rather short > the value might quiet different. Thoughts? > > Jeff > > > -------------------- > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. |
