21 #DEFINE PWMSS_CLK 100e6
23 #DEFINE PWMSS_CLK_2 50e6
36 CONSTRUCTOR PwmssUdt(
BYVAL T
AS Pruio_
PTR)
41 i += 1 : .DRam[i] = &h48300000uL
42 i += 1 : .DRam[i] =
IIF(.DevAct
AND PRUIO_ACT_PWM0, &h44E000D4uL, 0)
44 i += 1 : .DRam[i] = &h48302000uL
45 i += 1 : .DRam[i] =
IIF(.DevAct
AND PRUIO_ACT_PWM1, &h44E000CCuL, 0)
47 i += 1 : .DRam[i] = &h48304000uL
48 i += 1 : .DRam[i] =
IIF(.DevAct
AND PRUIO_ACT_PWM2, &h44E000D8uL, 0)
67 VAR p_mem = .MOffs + .DRam[InitParA] _
68 , p_raw =
CAST(
ANY PTR, .DRam) + PRUIO_DAT_PWM
69 FOR i
AS LONG = 0
TO PRUIO_AZ_PWMSS
72 p_raw +=
SIZEOF(PwmssArr)
75 Conf(i) = p_mem + .DSize
80 .DeAd = 0 : .ClVa = &h30000 : p_mem += 16 : _
81 Init(i)->DeAd = 0 : Init(i)->ClAd = 0 :
CONTINUE FOR
84 .CLKCONFIG = &b0100010001
96 p_mem +=
SIZEOF(PwmssSet)
119 ,
BYVAL Freq
AS Float_t
PTR = 0 _
120 ,
BYVAL Duty
AS Float_t
PTR = 0)
AS ZSTRING PTR
123 IF 2 <> .ClVa
THEN Top->Errr = E0 :
RETURN E0
124 IF 0 =
BIT(.ECCTL2, 9)
THEN Top->Errr = E9 :
RETURN E9
125 IF Freq
THEN *Freq = PWMSS_CLK / .CAP1
126 IF Duty
THEN *Duty = .CAP2 / .CAP1
150 ,
BYVAL F
AS Float_t _
151 ,
BYVAL D
AS Float_t = 0.)
AS ZSTRING PTR
153 STATIC AS CONST Float_t _
154 f_min = PWMSS_CLK / &hFFFFFFFFuL
156 cnt(...) = {0, 0, 0} _
157 , cmp(...) = {0, 0, 0}
161 IF 2 <> Conf(Nr)->ClVa
THEN .Errr = E0 :
RETURN E0
162 IF 0 = cnt(Nr)
ANDALSO _
163 0 >= F
THEN .Errr = E1 :
RETURN E1
165 IF F < f_min
ORELSE _
166 F > PWMSS_CLK_2
THEN .Errr = E2 :
RETURN E2
167 cnt(Nr) =
CUINT(PWMSS_CLK / F)
169 IF D >= 0
THEN cmp(Nr) =
IIF(D > 1., cnt(Nr),
CUINT(cnt(Nr) * D))
171 Conf(Nr)->CAP1 = cnt(Nr)
172 Conf(Nr)->CAP2 = cmp(Nr)
173 IF Conf(Nr)->ECCTL2 <> PwmMode
THEN
174 Conf(Nr)->ECCTL2 = PwmMode
179 IF .DRam[0] > PRUIO_MSG_IO_OK
THEN RETURN 0
185 .DRam[2] = Conf(Nr)->DeAd + &h100
186 .DRam[1] = r
OR (PRUIO_COM_CAP_PWM
SHL 24)
208 ,
BYVAL Dur1
AS Float_t
PTR _
209 ,
BYVAL Dur2
AS Float_t
PTR)
AS ZSTRING PTR
211 IF Dur1 = 0
ORELSE Dur2 = 0
THEN Top->Errr = @
"pass pointers" :
RETURN Top->Errr
213 VAR dur = *Dur1 + *Dur2 _
214 , dmx = 1000. * &hFFFFFFFF / PWMSS_CLK _
215 , dmn = 1000. * 2 / PWMSS_CLK
218 IF 2 <> .ClVa
THEN Top->Errr = E0 :
RETURN E0
219 IF 0 =
BIT(.ECCTL2, 9)
THEN Top->Errr = E9 :
RETURN E9
220 IF BIT(.ECCTL2, 4)
THEN
221 *Dur2 = 1000. * .CAP2 / PWMSS_CLK
222 *Dur1 = 1000. * .CAP1 / PWMSS_CLK - *Dur2
231 *Dur1 = *Dur1 / dur * dmx
232 *Dur2 = *Dur2 / dur * dmx
234 *Dur1 = 1000. *
CULNG(*Dur1 / dur * PWMSS_CLK)
235 *Dur2 = 1000. *
CULNG(*Dur2 / dur * PWMSS_CLK)
259 ,
BYVAL Dur1
AS Float_t _
260 ,
BYVAL Dur2
AS Float_t _
261 ,
BYVAL Mode
AS SHORT)
AS ZSTRING PTR
263 STATIC AS CONST Float_t _
264 d_min = 1000. * &h2 / PWMSS_CLK _
265 , d_max = 1000. * &hFFFFFFFFuLL / PWMSS_CLK
267 VAR dur = Dur1 + Dur2
269 IF 2 <> .ClVa
THEN Top->Errr = E0 :
RETURN E0
276 .ECCTL2 =
IIF(Mode
AND &b01, PwmMode
OR &b10000000000, PwmMode)
277 CASE IS < d_min :
Top->Errr =
Top->TimSS->E3 :
RETURN Top->Errr
278 CASE IS > d_max :
Top->Errr =
Top->TimSS->E4 :
RETURN Top->Errr
281 IF 0.01 >= Dur1
THEN Top->Errr =
Top->TimSS->E3 :
RETURN Top->Errr
282 Raw(Nr)->CMax = (Mode
AND &b111111110)
SHR 1
283 .ECCTL2 = PwmMode
OR IIF(Mode
AND &b01, &b10010000000, &b00010000000)
285 .ECCTL2 =
IIF(Mode
AND &b01, PwmMode
OR &b10000000000, PwmMode)
287 .CAP1 =
CULNG(.001 * dur * PWMSS_CLK)
288 VAR x =
CULNG(Dur2 / dur * .CAP1)
289 .CAP2 =
IIF(x > 0, x, 1)
295 IF .DRam[0] > PRUIO_MSG_IO_OK
THEN RETURN 0
298 .DRam[5] = Conf(Nr)->TSCTR
299 .DRam[4] = Conf(Nr)->CAP2
300 .DRam[3] = Conf(Nr)->CAP1
301 .DRam[2] = Conf(Nr)->DeAd + &h100
302 .DRam[1] = Conf(Nr)->ECCTL2
OR (PRUIO_COM_CAP_TIM
SHL 24)
325 ,
BYVAL F
AS Float_t
PTR = 0 _
326 ,
BYVAL Du
AS Float_t
PTR = 0 _
327 ,
BYVAL Mo
AS UInt8)
AS ZSTRING PTR
330 IF 2 <> .ClVa
THEN Top->Errr = E0 :
RETURN E0
331 VAR p =
CAST(UInt32, .TBPRD)
333 VAR d1 = (.TBCTL
SHR 7)
AND &b111, d2 = (.TBCTL
SHR 10)
AND &b111
334 VAR cg = p *
IIF(d1, d1
SHL 1, 1) * (1
SHL d2)
335 *F = PWMSS_CLK /
IIF(
BIT(.TBCTL, 1), cg
SHL 1, cg)
338 VAR c =
CAST(UInt32,
IIF(Mo, .CMPB, .CMPA))
339 IF BIT(.TBCTL, 1)
THEN
341 IF IIF(Mo, .AQCTLB, .AQCTLA)
AND &b010001000000
THEN c = p - c
371 ,
BYVAL F
AS Float_t _
372 ,
BYVAL Da
AS Float_t = 0. _
373 ,
BYVAL Db
AS Float_t = 0.)
AS ZSTRING PTR
375 STATIC AS CONST Float_t _
376 f_min = PWMSS_CLK_2 / &h6FFF900
378 freq(...) = {0., 0., 0.} _
379 , d_a(...) = {0., 0., 0.} _
380 , d_b(...) = {0., 0., 0.}
382 cnt(...) = {0, 0, 0} _
383 , c_a(...) = {0, 0, 0} _
384 , c_b(...) = {0, 0, 0}
388 IF 2 <> .ClVa
THEN Top->Errr = E0 :
RETURN E0
390 IF F <= 0.
THEN Top->Errr = E1 :
RETURN E1
392 IF F > 0.
ANDALSO freq(Nr) <> F
THEN cnt(Nr) = 0
396 VAR cycle =
IIF(F > f_min
ANDALSO F <= PWMSS_CLK_2,
CUINT(.5 + PWMSS_CLK / F), 0uL)
397 IF 2 > cycle
THEN Top->Errr = E2 :
RETURN E2
400 IF cycle <= &h10000
ANDALSO 0 =
BIT(
Top->Pwm->ForceUpDown, Nr)
THEN
402 ELSEIF cycle < &h20000
THEN
403 cnt(Nr) = cycle
SHR 1
406 VAR fac = cycle
SHR 17 _
407 , x1 = 1 +
CINT(
INT(
LOG(fac / 14) / LOG2))
408 IF x1 < 0
THEN x1 = 0
409 VAR x2 = (fac
SHR x1) \ 2 + 1
410 cnt(Nr) =
CUINT(.5 + PWMSS_CLK_2 / F / (
IIF(x2, x2
SHL 1, 1)
SHL x1))
411 ctl = 2 + x2
SHL 7 + x1
SHL 10
413 ctl
OR= (3
SHL 14) + (
Top->Pwm->Cntrl(Nr)
AND &b0010000001111100)
421 IF Da >= 0.
THEN d_a(Nr) =
IIF(Da > 1., 1., Da) : c_a(Nr) = 0
423 IF BIT(.TBCTL, 1)
ORELSE BIT(
Top->Pwm->ForceUpDown, Nr)
THEN
425 THEN .AQCTLA =
Top->Pwm->AqCtl(0, Nr, 2) : c_a(Nr) =
CUINT((cnt(Nr)
SHL 1) * (1 - d_a(Nr))) _
426 ELSE .AQCTLA =
Top->Pwm->AqCtl(0, Nr, 1) : c_a(Nr) =
CUINT((cnt(Nr)
SHL 1) * d_a(Nr))
428 .AQCTLA =
Top->Pwm->AqCtl(0, Nr, 0) : c_a(Nr) =
CUINT(.5 + (cnt(Nr) + 1) * d_a(Nr))
433 IF Db >= 0.
THEN d_b(Nr) =
IIF(Db > 1., 1., Db) : c_b(Nr) = 0
435 IF BIT(.TBCTL, 1)
ORELSE BIT(
Top->Pwm->ForceUpDown, Nr)
THEN
437 THEN .AQCTLB =
Top->Pwm->AqCtl(1, Nr, 2) : c_b(Nr) =
CUINT((cnt(Nr)
SHL 1) * (1 - d_b(Nr))) _
438 ELSE .AQCTLB =
Top->Pwm->AqCtl(1, Nr, 1) : c_b(Nr) =
CUINT((cnt(Nr)
SHL 1) * d_b(Nr))
440 .AQCTLB =
Top->Pwm->AqCtl(1, Nr, 0) : c_b(Nr) =
CUINT(.5 + (cnt(Nr) + 1) * d_b(Nr))
445 IF Top->DRam[0] > PRUIO_MSG_IO_OK
THEN RETURN 0
447 WHILE Top->DRam[1] :
WEND
448 Top->DRam[5] = .TBCNT + .TBPRD
SHL 16
449 Top->DRam[4] = .AQCTLA + .AQCTLB
SHL 16
450 Top->DRam[3] = .CMPA + .CMPB
SHL 16
451 Top->DRam[2] = .DeAd + &h200
452 Top->DRam[1] =
IIF(ctl, ctl, 0) + PRUIO_COM_PWM
SHL 24
470 CONSTRUCTOR PwmMod(
BYVAL T
AS Pruio_
PTR)
490 BYVAL Ball
AS UInt8 _
491 ,
BYVAL Hz
AS Float_t
PTR = 0 _
492 ,
BYVAL Du
AS Float_t
PTR = 0)
AS ZSTRING PTR
496 SELECT CASE AS CONST Ball
497 CASE &h24 : e =
IIF(ModeCheck(Ball,2), .PwmSS->E3, .TimSS->pwm_get(0, Hz, Du))
498 CASE &h27 : e =
IIF(ModeCheck(Ball,2), .PwmSS->E3, .TimSS->pwm_get(1, Hz, Du))
499 CASE &h26 : e =
IIF(ModeCheck(Ball,2), .PwmSS->E3, .TimSS->pwm_get(2, Hz, Du))
500 CASE &h25 : e =
IIF(ModeCheck(Ball,2), .PwmSS->E3, .TimSS->pwm_get(3, Hz, Du))
501 CASE &h09 : e =
IIF(ModeCheck(Ball,4), .PwmSS->E3, .PwmSS->pwm_pwm_get(2, Hz, Du, 1))
502 CASE &h08 : e =
IIF(ModeCheck(Ball,4), .PwmSS->E3, .PwmSS->pwm_pwm_get(2, Hz, Du, 0))
503 CASE &h33 : e =
IIF(ModeCheck(Ball,2), .PwmSS->E3, .PwmSS->pwm_pwm_get(1, Hz, Du, 1))
504 CASE &h32 : e =
IIF(ModeCheck(Ball,2), .PwmSS->E3, .PwmSS->pwm_pwm_get(1, Hz, Du, 0))
505 CASE &h28 : e =
IIF(ModeCheck(Ball,3), .PwmSS->E3, .PwmSS->pwm_pwm_get(2, Hz, Du, 1))
506 CASE &h29 : e =
IIF(ModeCheck(Ball,3), .PwmSS->E3, .PwmSS->pwm_pwm_get(2, Hz, Du, 0))
507 CASE &h12 : e =
IIF(ModeCheck(Ball,6), .PwmSS->E3, .PwmSS->pwm_pwm_get(1, Hz, Du, 0))
508 CASE &h13 : e =
IIF(ModeCheck(Ball,6), .PwmSS->E3, .PwmSS->pwm_pwm_get(1, Hz, Du, 1))
509 CASE &h55 : e =
IIF(ModeCheck(Ball,3), .PwmSS->E3, .PwmSS->pwm_pwm_get(0, Hz, Du, 1))
510 CASE &h54 : e =
IIF(ModeCheck(Ball,3), .PwmSS->E3, .PwmSS->pwm_pwm_get(0, Hz, Du, 0))
511 CASE &h65 : e =
IIF(ModeCheck(Ball,1), .PwmSS->E3, .PwmSS->pwm_pwm_get(0, Hz, Du, 1))
512 CASE &h64 : e =
IIF(ModeCheck(Ball,1), .PwmSS->E3, .PwmSS->pwm_pwm_get(0, Hz, Du, 0))
513 CASE &h67 : e =
IIF(ModeCheck(Ball,4), .PwmSS->E3, .PwmSS->cap_pwm_get(2, Hz, Du))
514 CASE &h5D : e =
IIF(ModeCheck(Ball,4), .PwmSS->E3, .PwmSS->cap_pwm_get(1, Hz, Du))
515 CASE &h59 : e =
IIF(ModeCheck(Ball,0), .PwmSS->E3, .PwmSS->cap_pwm_get(0, Hz, Du))
517 CASE ELSE : e = .PwmSS->E4
518 END SELECT :
IF e
THEN .Errr = e :
RETURN .Errr
565 BYVAL Ball
AS UInt8, _
566 BYVAL Hz
AS Float_t, _
567 BYVAL Du
AS Float_t)
AS ZSTRING PTR
570 SELECT CASE AS CONST Ball
571 CASE &h24 :
IF ModeCheck(Ball,2)
THEN ModeSet(Ball, &h0A)
572 RETURN .TimSS->pwm_set(0, Hz, Du)
573 CASE &h27 :
IF ModeCheck(Ball,2)
THEN ModeSet(Ball, &h0A)
574 RETURN .TimSS->pwm_set(1, Hz, Du)
575 CASE &h26 :
IF ModeCheck(Ball,2)
THEN ModeSet(Ball, &h0A)
576 RETURN .TimSS->pwm_set(2, Hz, Du)
577 CASE &h25 :
IF ModeCheck(Ball,2)
THEN ModeSet(Ball, &h0A)
578 RETURN .TimSS->pwm_set(3, Hz, Du)
579 CASE &h09 :
IF ModeCheck(Ball,4)
THEN ModeSet(Ball, &h0C)
580 RETURN .PwmSS->pwm_pwm_set(2, Hz, -1., Du)
581 CASE &h08 :
IF ModeCheck(Ball,4)
THEN ModeSet(Ball, &h0C)
582 RETURN .PwmSS->pwm_pwm_set(2, Hz, Du, -1.)
583 CASE &h33 :
IF ModeCheck(Ball,2)
THEN ModeSet(Ball, &h0A)
584 RETURN .PwmSS->pwm_pwm_set(1, Hz, -1., Du)
585 CASE &h32 :
IF ModeCheck(Ball,2)
THEN ModeSet(Ball, &h0A)
586 RETURN .PwmSS->pwm_pwm_set(1, Hz, Du, -1.)
587 CASE &h28 :
IF ModeCheck(Ball,3)
THEN ModeSet(Ball, &h0B)
588 RETURN .PwmSS->pwm_pwm_set(2, Hz, -1., Du)
589 CASE &h29 :
IF ModeCheck(Ball,3)
THEN ModeSet(Ball, &h0B)
590 RETURN .PwmSS->pwm_pwm_set(2, Hz, Du, -1.)
591 CASE &h12 :
IF ModeCheck(Ball,6)
THEN ModeSet(Ball, &h0E)
592 RETURN .PwmSS->pwm_pwm_set(1, Hz, Du, -1.)
593 CASE &h13 :
IF ModeCheck(Ball,6)
THEN ModeSet(Ball, &h0E)
594 RETURN .PwmSS->pwm_pwm_set(1, Hz, -1., Du)
595 CASE &h55 :
IF ModeCheck(Ball,3)
THEN ModeSet(Ball, &h0B)
596 RETURN .PwmSS->pwm_pwm_set(0, Hz, -1., Du)
597 CASE &h54 :
IF ModeCheck(Ball,3)
THEN ModeSet(Ball, &h0B)
598 RETURN .PwmSS->pwm_pwm_set(0, Hz, Du, -1.)
599 CASE &h65 :
IF ModeCheck(Ball,1)
THEN ModeSet(Ball, &h09)
600 RETURN .PwmSS->pwm_pwm_set(0, Hz, -1., Du)
601 CASE &h64 :
IF ModeCheck(Ball,1)
THEN ModeSet(Ball, &h09)
602 RETURN .PwmSS->pwm_pwm_set(0, Hz, Du, -1.)
603 CASE &h67 :
IF ModeCheck(Ball,4)
THEN ModeSet(Ball, &h0C)
604 RETURN .PwmSS->cap_pwm_set(2, Hz, Du)
605 CASE &h59 :
IF ModeCheck(Ball,0)
THEN ModeSet(Ball, &h08)
606 RETURN .PwmSS->cap_pwm_set(0, Hz, Du)
607 CASE &h5D :
IF ModeCheck(Ball,4)
THEN ModeSet(Ball, &h0C)
608 RETURN .PwmSS->cap_pwm_set(1, Hz, Du)
609 CASE &h58 :
IF ModeCheck(Ball,2)
THEN ModeSet(Ball, &h0A)
610 RETURN .PwmSS->cap_pwm_set(1, Hz, Du)
613 END SELECT : .Errr = .PwmSS->E4 :
RETURN .Errr
649 BYVAL Mask
AS UInt8)
AS ZSTRING PTR
651 IF .MuxFnr < 1
ORELSE .MuxFnr > 255
THEN RETURN @
"libpruio LKM missing"
652 PRINT #.MuxFnr,
"FF" &
HEX(Mask, 2) :
SEEK #.MuxFnr, 1 :
RETURN 0
690 CONSTRUCTOR CapMod(
BYVAL T
AS Pruio_
PTR)
721 BYVAL Ball
AS UInt8 _
722 ,
BYVAL FLow
AS Float_t = 0.)
AS ZSTRING PTR
726 SELECT CASE AS CONST Ball
727 CASE &h67 :
IF ModeCheck(Ball,4)
THEN ModeSet(Ball, &h24)
729 CASE &h5C :
IF ModeCheck(Ball,4)
THEN ModeSet(Ball, &h24)
731 CASE &h59 :
IF ModeCheck(Ball,0)
THEN ModeSet(Ball, &h20)
732 CASE &h58 :
IF ModeCheck(Ball,1)
THEN ModeSet(Ball, &h22)
734 CASE &h5D :
IF ModeCheck(Ball,4)
THEN ModeSet(Ball, &h24)
741 CASE ELSE : .Errr = .PwmSS->E6 :
RETURN .Errr
743 IF 2 <> .PwmSS->Conf(m)->ClVa
THEN .Errr = .PwmSS->E0 :
RETURN .Errr
745 VAR cnt = &hFFFFFFFFul
746 IF FLow > PWMSS_CLK/ &hFFFFFFFFul
THEN
747 cnt =
CUINT(PWMSS_CLK / FLow)
748 IF cnt < 256
THEN cnt = 256
751 .Conf(m)->ECCTL2 = .CapMode
754 IF .DRam[0] > PRUIO_MSG_IO_OK
THEN RETURN 0
757 .DRam[2] = .PwmSS->Conf(m)->DeAd + &h100
758 .DRam[1] = .PwmSS->CapMode + (PRUIO_COM_CAP
SHL 24)
789 BYVAL Ball
AS UInt8 _
790 ,
BYVAL Hz
AS Float_t
PTR = 0 _
791 ,
BYVAL Du
AS Float_t
PTR = 0)
AS ZSTRING PTR
796 IF 2 <> .PwmSS->Conf(m)->ClVa
THEN
799 SELECT CASE AS CONST Ball
800 CASE &h67 :
IF ModeCheck(Ball,4)
THEN e = .PwmSS->E5
ELSE m = 2
801 CASE &h59 :
IF ModeCheck(Ball,0)
THEN e = .PwmSS->E5
802 CASE &h5C :
IF ModeCheck(Ball,4)
THEN e = .PwmSS->E5
ELSE m = 2
803 CASE &h58 :
IF ModeCheck(Ball,1)
THEN e = .PwmSS->E5
ELSE m = 1
804 CASE &h5D :
IF ModeCheck(Ball,4)
THEN e = .PwmSS->E5
ELSE m = 1
808 CASE ELSE : e = .PwmSS->E6
810 END IF :
IF e
THEN .Errr = e :
RETURN .Errr
812 IF .DRam[0] > PRUIO_MSG_IO_OK
THEN
815 .Errr = @
"IO/RB mode not running" :
RETURN .Errr
818 WITH *
Top->PwmSS->Raw(m)
820 IF Hz
THEN *Hz =
IIF(.C2, PWMSS_CLK / .C2, 0.)
821 IF Du
THEN *Du =
IIF(.C2, (.C2 - .C1) / .C2, 0.)
826 Top->Errr =
Top->PwmSS->E5 :
RETURN Top->Errr
846 CONSTRUCTOR QepMod(
BYVAL T
AS Pruio_
PTR)
916 BYVAL Ball
AS UInt8 _
917 ,
BYVAL PMax
AS UInt32 = &h7FFFFFFFul _
918 ,
BYVAL VHz AS Float_t = 25. _
919 ,
BYVAL Scale
AS Float_t = 1. _
920 ,
BYVAL Mo
AS UInt8 = 0)
AS ZSTRING PTR
923 STATIC AS Float_t fmin = PWMSS_CLK / (&hFFFF
SHL 7)
925 IF VHz < fmin
ORELSE VHz > PWMSS_CLK_2
THEN _
926 .Errr = .PwmSS->E2 :
RETURN .Errr
927 SELECT CASE AS CONST Ball
928 CASE &h0D, &h0C, &h0E : m = 2
929 VAR v =
IIF(Mo = PRUIO_PIN_RESET, PRUIO_PIN_RESET, &h2C)
930 IF ModeCheck(&h0C,4)
THEN ModeSet(&h0C,v)
931 IF Ball = &h0C
THEN x = 2 :
EXIT SELECT
932 IF ModeCheck(&h0D,4)
THEN ModeSet(&h0D,v)
933 IF Ball = &h0D
THEN x = 1 :
EXIT SELECT
934 IF ModeCheck(&h0E,4)
THEN ModeSet(&h0E,v)
936 VAR v =
IIF(Mo = PRUIO_PIN_RESET, PRUIO_PIN_RESET, &h2E)
937 IF ModeCheck(&h14,6)
THEN ModeSet(&h14,v)
939 CASE &h35, &h34, &h36 : m = 1
940 VAR v =
IIF(Mo = PRUIO_PIN_RESET, PRUIO_PIN_RESET, &h2A)
941 IF ModeCheck(&h34,2)
THEN ModeSet(&h34,v)
942 IF Ball = &h34
THEN x = 2 :
EXIT SELECT
943 IF ModeCheck(&h35,2)
THEN ModeSet(&h35,v)
944 IF Ball = &h35
THEN x = 1 :
EXIT SELECT
945 IF ModeCheck(&h36,2)
THEN ModeSet(&h36,v)
946 CASE &h2C, &h2D, &h2E : m = 2
947 VAR v =
IIF(Mo = PRUIO_PIN_RESET, PRUIO_PIN_RESET, &h2B)
948 IF ModeCheck(&h2C,3)
THEN ModeSet(&h2C,v)
949 IF Ball = &h2C
THEN x = 2 :
EXIT SELECT
950 IF ModeCheck(&h2E,3)
THEN ModeSet(&h2E,v)
951 IF Ball = &h2D
THEN x = 1 :
EXIT SELECT
952 IF ModeCheck(&h2E,3)
THEN ModeSet(&h2E,v)
953 CASE &h69, &h59, &h68, &h6D, &h6A : m = 0
954 VAR v =
IIF(Mo = PRUIO_PIN_RESET, PRUIO_PIN_RESET, &h29)
955 IF ModeCheck(&h68 ,1)
THEN ModeSet(&h68 ,v)
956 IF Ball = &h59
ORELSE Ball = &h68
THEN x = 2 :
EXIT SELECT
957 IF ModeCheck(&h69,1)
THEN ModeSet(&h69,v)
958 IF Ball = &h69
THEN x = 1 :
EXIT SELECT
959 IF ModeCheck(&h6A ,1)
THEN ModeSet(&h6A ,v)
960 CASE ELSE : .Errr = .PwmSS->E8 :
RETURN .Errr
962 IF 2 <> .PwmSS->Conf(m)->ClVa
THEN .Errr = .PwmSS->E0 :
RETURN .Errr
964 WITH *
Top->PwmSS->Conf(m)
970 .QUPRD =
cuint(PWMSS_CLK /
VHz)
972 VAR ccps = .QUPRD \ &h10000
973 IF ccps > 1
THEN ccps = 1 +
INT(
LOG(ccps) / LOG2)
974 SELECT CASE AS CONST x
976 .QDECCTL = &b1000000000000000
977 .QEPCTL = &b0001000010001110
978 .QCAPCTL = &b1000000000000000
or (ccps
shl 4)
980 .QDECCTL = &b0000000000000000
981 .QEPCTL = &b0001000010001110
982 .QCAPCTL = &b1000000000000010
or (ccps
shl 4)
984 .QDECCTL = &b0000000000000000
985 .QEPCTL = &b0000001010001110
986 .QCAPCTL = &b1000000000000010
or (ccps
shl 4)
988 .QPOSCTL = &b0000000000000000
992 VAR fx = 1
SHL ((.QCAPCTL
SHR 4)
AND &b111) _
993 , fp = 1
SHL (.QCAPCTL
AND &b1111) _
996 FVh(m) = Scale * PWMSS_CLK / .QUPRD
997 FVl(m) = Scale * PWMSS_CLK / fx * fp
998 Prd(m) =
CUINT(fp * t / (-p2 +
SQR(p2 * p2 + t / fp)))
SHL 16
999 IF Top->DRam[0] > PRUIO_MSG_IO_OK
THEN RETURN 0
1001 WHILE Top->DRam[1] :
WEND
1002 Top->DRam[6] = .QCAPCTL
1003 Top->DRam[5] = .QDECCTL
OR .QEPCTL
SHL 16
1004 Top->DRam[4] = .QUPRD
1005 Top->DRam[3] = .QPOSMAX
1006 Top->DRam[2] = .DeAd + &h180
1007 Top->DRam[1] = PRUIO_COM_QEP
SHL 24
1042 BYVAL Ball
AS UInt8 _
1043 ,
BYVAL Posi
AS UInt32
PTR = 0 _
1044 ,
BYVAL Velo
AS Float_t
PTR = 0)
AS ZSTRING PTR
1048 SELECT CASE AS CONST Ball
1049 CASE &h14 : Posi = 0 : m = 1
1050 CASE &h0C : Posi = 0 : m = 2
1051 CASE &h0D, &h0E : m = 2
1052 CASE &h34 : Posi = 0 : m = 1
1053 CASE &h35, &h36 : m = 1
1054 CASE &h2C : Posi = 0 : m = 2
1055 CASE &h2D, &h2E : m = 2
1056 CASE &h59, &h68 : Posi = 0 : m = 0
1057 CASE &h69, &h6D, &h6A : m = 0
1058 CASE ELSE : .Errr = .PwmSS->E0 :
RETURN .Errr
1061 IF .DRam[0] > PRUIO_MSG_IO_OK
THEN
1062 IF Posi
THEN *Posi = 0
1063 IF Velo
THEN *Velo = 0.
1064 .Errr = @
"IO/RB mode not running" :
RETURN .Errr
1067 WITH *
Top->PwmSS->Raw(m)
1069 VAR dx =
CINT(.NPos - .OPos)
1070 IF .PLat > Prd(m)
THEN
1073 *Velo =
IIF(
HIWORD(.PLat),
SGN(dx) * FVl(m) /
HIWORD(.PLat), 0.)
1076 IF Posi
THEN *Posi = .QPos