Shop OBEX P1 Docs P2 Docs Learn Events
Invert pin state of phsa — Parallax Forums

Invert pin state of phsa

Is there a convenient way to have phsa of a counter output low for the determined accumulation instead of high, and otherwise be high. I would like to use the counter with a pnp transistor.

Comments

  • jmgjmg Posts: 15,144
    mikea wrote: »
    Is there a convenient way to have phsa of a counter output low for the determined accumulation instead of high, and otherwise be high. I would like to use the counter with a pnp transistor.

    In which mode ? - you could preload it so the bit.31 starts high, then overflows to 0 ?
  • I have to check the code, but i believe it's nco %00100. How do you preload it?
  • jmgjmg Posts: 15,144
    mikea wrote: »
    I have to check the code, but i believe it's nco %00100. How do you preload it?

    You just write to the register, but you will need to update for every pulse, otherwise you just get a constant NCO frequency out.

    There is also a %00101 NCO differential mode, that outputs APIN= PHSx[31] & BPIN = !PHSx[31]
    APIN > 31 disables mapping, as that's non-existent Port B, so here using BPIN inverts.
  • AribaAriba Posts: 2,682
    I think this is for PWM output. If you want inverted PWM, you need to write a positive value into PHSx for the pulse time instead of a negative value, and the FRQx must be -1 instead of +1, so that the counter counts down.

    NCO mode outputs the MSB of PHSx to the pin. With a negative startvalue the pin goes high. The counter counts up until it goes over zero and then the MSB and therefore the pin goes low.
    If you start with a positive value and count down it's the other way around.

    Andy

  • Thank you both. Yes this is for pwm, i reversed the +/- of frqa,and phsa and it works perfectly. It's useful to know about differential output for the counters also. This pwm is switching a pnp transistor, is it a good idea to use a pullup resistor 10k or so like you would for a mosfet?
  • jmgjmg Posts: 15,144
    mikea wrote: »
    This pwm is switching a pnp transistor, is it a good idea to use a pullup resistor 10k or so like you would for a mosfet?
    With a CMOS output that is not needed. PNP needs drive to turn on, so a floating pin at reset is not an issue.
    PNP does need a series base resistor, I presume you have ?
    How fast is this switching ?

  • Yes, series resistors for base and emitter/collector. Switching is 1000 hz
Sign In or Register to comment.