PWM/PPM Capture issue with Atom Pro 28

Working on the code to capture pulses using WKP.
I did it on a single pin just to ensure it is working…it works…BUT: HSERVO function doesnt work anymore…
Here it is the code…

[code];Interrupt init
ONINTERRUPT WKPINT_0,handle_intp0

PMR5.bit0 = 1 ;enables pin as WKP interrupt instead of normal I/O
IEGR2.bit0 = 0 ;0 = Pin will interrupt on a falling edge, 1 to interrupt on a rising edge.

; TimerW regs
TCRW.bit5 = 1 ;TIMERW counts on clk/8
TCRW.bit4 = 1 ;TIMERW counts on clk/8
TCRW.bit7 = 0 ;TCNT free running counter
TMRW.bit7 = 1 ;TCNT free running counter

ENABLE WKPINT_0
ENABLEHSERVO

;Variable declaration
pulse_ch1 var long
pass0 var byte

pass0 = 0

control_loop

HSERVO [P10\pulse_ch1*10]

;HPWM 10,320000,pulse_ch110
serout S_OUT,i2400,"ch1 ", dec pulse_ch1, 13]
;pulsout 10, pulse_ch1
2
;servo P10, (pulse_ch1-1500)*2, 2
goto control_loop

handle_intp0
If pass0 = 0 then
TCNT = 0
IEGR2.bit0 = 0 ;interrupt on a falling edge
pass0 = 1
elseif pass0 = 1
pulse_ch1 = TCNT/2 ; divide by 2 to obtain us
IEGR2.bit0 = 1 ;interrupt on a rising edge
pass0 = 0
endif
Resume[/code]

As you can see i also tried other ways to drive servos but none seems to work, seems to be a timing problem caused by the capture code.
ACIDTECH come to help!!! :stuck_out_tongue: :stuck_out_tongue:

The 8.0.1.0 HSERVO had a bug. It was causing pulses on unrelated pins. The reason for this is probably related to the problem you are having. Iv’e fixed that and gave the customer the updated files to confirm. If he confirms I’ll updat ethe 8.0.1.0 release to 8.0.1.1.

The problem you are see is caused because HPWM does not wait until the end of a pulzse before it will change the period and duty you specify. This will cause glitching in the pulse signal. The next release of AtomPro basic will have a new version of HPWM that has a new argument to tell it to wait until the end of the current pulse before changing the period and duty. This will alow smooth pulse width changes. The new syntax is HPWM pin,period,duty{,wait}. “Wait” is zero to not wait or non-sero to wait. 8.0.1.1 will have this optional argument when it is released.

Acidtech,
That HSERVO bug was probably causing glitches when i tested PULSIN to capture pulses from the rc receiver, i have detected that. Good to know it is a known bug soon to be solved! (may I have 8.0.1.1 release NOW? :smiley: )

Is it possible that setting different TCRW and TMRW values for TimerW (like i did in the above code to activate the 16bit TCNT clock) is deactivating the HSERVO function, because that is the problem im having now.

Thanks a lot for your help Acidtech

Edit:
Just read the above post about HPWM, you posted it while i was typing this one.

As soon as I hear back from the other customer I’ll be making the new 8.0.1.1 release available(assuming I’ve fixed the problem). As for the other, do not mess with TimerW registers if you are using HSERVO. It uses TimerW so you will screw up HSERVO. HPWM and HSERVO are mutually exclusive since both want to use TimerW.

I think the test version may have fixed the problem. It fixed the problem in my first test program. I had a problem with a second test program, but found problem was in the test program.

There was a problem That I can not link my full blown BRAT code, but assuming that the updated lib fixes that, I think it may be good to go!

Kurt

Acidtech,
So if I use TimerW for pulse counting i wont be able to use HSERVO and HPWM, any other solution for interrupt capturing pulses (other than TimerW) and still be able to use HSERVO and/or HPWM?
Thank You

To read a pulse you could use the WKP pins and one of the other timers. Setup timerA int to keep track of time. Then when WKP trips on the front edge of your pulse save the current time. Then set WKP to trip on the falling edge and resume. When WKP trips on the falling edge take the difference from the first reading from the second. There’s your pulse width in whatever time base you setup TimerA to run at. Siz WKP pins means upto six different pulse signals could be read.

Going to the manual to study TimerA then! :open_mouth: :open_mouth:
Will post the code when its done.
Thank you Acid!

Acidtech,
From what ive read Timer A has a resolution of 8 bits, im not finding a way to read the pulse width with it. Im using TCA counter.
How should i set up timerA registers to get the proper resolution?
Thank You!

AcidTech could probably answer this better than I can, but I am playing around with the TV Brat code. What I do in my code is to set
TMA=0x04
This will set TCA equal to the clock/256. You can experiment with different values of this, depending on the resolution you require.

Then at the beginning of what I am trying to time, I will do something like
TMA=0x0c
This clears TCA.
TMA=0x04
Again sets the counter to clock/256

Then when I get the end condition, I simply grab the value aut of TCA.
I also check irr1.bit6 if it is set than I know there was an overflow.

If the period you are trying to time exceeds the TCA going to 255 than you can also setup an interrupt when the overflow happens and increment a global timer tick. The TV Brat code that is posted in the BIPED section shows this code.

Good Luck