Shop OBEX P1 Docs P2 Docs Learn Events
New P2 eval board, confused, need help — Parallax Forums

New P2 eval board, confused, need help

Got the new evaluation board. I have the P1 working with a couple frequency counters on inputs. I'm confused on how to do this on the P2. I guess it would use the smart pins in a certain mode.
It looks like the mode may be one of these:
%10101 = For periods in X+ clock cycles, count time
%10110 = For periods in X+ clock cycles, count states
%10111 = For periods in X+ clock cycles, count periods
This is very new to me and I have been reading and searching for some info but not much makes sense yet.
Could one of the more versed people get me started with some example on using the smart pin modes to get a frequency for a P2 beginner. Also not a P1 expert by all means either, so be gentle on me.
As far as I can read I have to set the smart pin mode and then read Z for the measurement.
I just need something to get me started understanding it.

Thanks very much

Comments

  • cgraceycgracey Posts: 14,133
    edited 2019-12-04 01:02
    You'd want to use modes %10101 and %10111 pointed at the same pin, since this would provide precise frequency counting. Mode %10110 could also be used on the same pin if you wanted duty cycle, as well.

    We really need some easy way to operate something low-level, like this frequency counter arrangement, and then show the results on a screen, for easy viewing. I wish I had Spin2 done, but ersmith's compiler may have objects, already, for displaying data on video screens. I could write an example right now, but displaying the data would be the headache.

    Maybe Jmg can show something. He's the driver behind this counter methodology being implemented. It's the best way to measure frequency accurately and quickly.
  • Yeh just a little example to show how to setup those modes pointed at the same pin would help to get me started.
  • Tell me if this would even be close to set for pin 20

    wrpin_(%0000_0000_000_0000000000000_00_10101_0, 20)

    I'm not sure how to set the %P..P: low-level pin control
    I'm confused on the table for this.

    wxpin_ would be the # cycles to track for?
    wypin_ would be %00 A-input rise to B-input rise?

    And then read with
    RQPIN D,S/# {WC} ?


  • cgraceycgracey Posts: 14,133
    CRST1, I've got an example program written to demonstrate those three modes from which you can realize a reciprocal counter. I will post it in a new thread soon.
  • evanhevanh Posts: 15,187
    Chip,
    I've been looking at this just now myself. And got a question I'm not sure is answered in the docs:
    		...
    		setq	extend
    		altd	idx, #carr
    		qdiv	0-0, pa
    		...
    
    Do interrupts get a double blocker there?

  • cgraceycgracey Posts: 14,133
    evanh wrote: »
    Chip,
    I've been looking at this just now myself. And got a question I'm not sure is answered in the docs:
    		...
    		setq	extend
    		altd	idx, #carr
    		qdiv	0-0, pa
    		...
    
    Do interrupts get a double blocker there?

    Yes, they do.
  • ersmithersmith Posts: 5,909
    edited 2019-12-04 13:06
    cgracey wrote: »
    We really need some easy way to operate something low-level, like this frequency counter arrangement, and then show the results on a screen, for easy viewing. I wish I had Spin2 done, but ersmith's compiler may have objects, already, for displaying data on video screens. I could write an example right now, but displaying the data would be the headache.
    Serial output is easy with the smartpins (and you've already posted an example in the other thread). But yes, FlexGUI already has I/O objects.

    I find BASIC is a pretty good way to do simple prototyping. Here's a small program for testing out the smart pin. It uses the "increment on A-rise" smart pin mode to count transitions. I've got it set up to count on the serial rx pin, so you can type characters at it and watch it change based on what you type:
    ''
    '' simple pin transition counter in BASIC
    ''
    const the_pin = 63
    
    ' smart pin mode
    ' 01110 is increment on A-rise
    '                  AAAA BBBB FFF PPPP_PPPPPPPPP TT MMMMM
    const pin_mode = 0b0000_0000_000_0000_000000000_00_01110_0
    const pin_x = 0
    const pin_y = 0
    
    ' set clock to 250MHz
    clkset(0b1_000001_0000011000_1111_10_11, 250_000_000)
    _setbaud(230_400)
    
    print "measuring pin changes on pin "; the_pin
    
    '' setup pin
    asm
      dirl  #the_pin    ' disable pin
      wrpin ##pin_mode, #the_pin
      wxpin ##pin_x, #the_pin
      wypin ##pin_y, #the_pin
      dirh  #the_pin    ' enable pin
    end asm
    
    ' only print results when things change
    var old_val = -1
    var val = 0
    
    do
      pausems 100    ' check 10 times per second
      val = readpin(the_pin)
      if (val <> old_val) then
          print " xval = "; val
          old_val = val
      end if
    loop
    
    ' read current accumulator from a smart pin
    
    function readpin(pin)
      dim q as uinteger
      asm
            rdpin q, pin
      end asm
      
      return q
    end function
    

    To run: save this in a file like "counter.bas". Open flexgui.exe. Use File > Open to select counter.bas. Click on "Compile & Run on P2". It'll open up a terminal window and print:
    ( Entering terminal mode.  Press Ctrl-] to exit. )
    measuring pin changes on pin 63
     xval = 0
    
    Now if you type characters it'll print new "xval" values based on the number of low->high transitions in the character. There will always be at least 1 (for the stop bit).

    Edit: deleted some unused variable declarations in the program, and reduced the pause to 100ms
  • cgraceycgracey Posts: 14,133
    Super, Eric! Looks good.
  • evanhevanh Posts: 15,187
    cgracey wrote: »
    evanh wrote: »
    Do interrupts get a double blocker there?
    Yes, they do.
    Thanks.

  • I tried this approach:
    PUB Main | tmr1
      clkset(oscmode, freq)
      'start the SmartSerial object
      serial.Start(rx, tx, %0000, baud)                    
       
      wrpin_(%0000_0000_000_0000000000000_00_10101_0,7)
      wxpin_(10000,7)
      wypin_(0,7)
       
    repeat
      asm
        rqpin    tmr1,  7  {wc}
      endasm
    
      
    
      serial.str(string(" Tmr "))  
      serial.dec(tmr1)
      serial.str(string("     "))  
    
    

    I have pin 56 and 57 flashing and a jumper from one of them to pin 7
    It just reads 0

  • I changed it to this like your setting:
    PUB Main | tmr1
      clkset(oscmode, freq)
      'start the SmartSerial object
      serial.Start(rx, tx, %0000, baud)                    
       
      asm
        dirl 7
      endasm
    
        wrpin_(%0000_0000_000_0000000000000_00_01110_0,7)
        wxpin_(0,7)
        wypin_(0,7)
    
      asm
        dirh 7
      endasm
      
    repeat
      asm
        rqpin    tmr1,  7  {wc}
      endasm
    
      
    
      serial.str(string(" Tmr "))  
      serial.dec(tmr1)
      serial.str(string("     "))  
    
    

    I have pin 56 and 57 flashing and a jumper from one of them to pin 7
    It still just reads 0


  • ersmith wrote: »
    I find BASIC is a pretty good way to do simple prototyping. Here's a small program for testing out the smart pin. It uses the "increment on A-rise" smart pin mode to count transitions. I've got it set up to count on the serial rx pin, so you can type characters at it and watch it change based on what you type:

    I loaded yours and it does work
    Can you tell me what is wrong with the way I am doing it?
  • @CRST1 : be careful with immediate values. I see in your code some instructions like:
      asm
        dirh 7
      endasm
    
    If this is intended to work on pin 7 then you should write "dirh #7" (with a number sign). Otherwise it reads COG register 7 and then uses that value to determine the pin.

    Also, you may want to use "rdpin" instead of "rqpin". It probably doesn't matter in the accumulate example, but I think reads from the smart pin should be acknowledged in order to reset the period. You can do this either with "akpin" (if you use "rqpin") or by using "rdpin" which does a combination of read and ack.

  • I've compacted the complete program to post.
    I have a jumper from pin 56 to pin 7.
    CON
      oscmode = $010c3f04             'oscilator mode
      freq = 160_000_000              'frequency
      baud = 230400                  
      rx = 63                         'number for receive pin
      tx = 62                         'number for transmit pin
    
    VAR
      long  PulseStack[10]
    OBJ
      serial        : "SmartSerial"
      
    PUB Main | tmr1
      clkset(oscmode, freq)
      'start the SmartSerial object
      serial.Start(rx, tx, %0000, baud)                    
      coginit(7, Pulse, @PulseStack)  
    
      asm
        dirl 7
      endasm
    
        wrpin_(%0000_0000_000_0000000000000_00_01110_0,7)
        wxpin_(0,7)
        wypin_(0,7)
    
      asm
        dirh 7
      endasm
     
    repeat
      asm
        rqpin    tmr1,7  
      endasm
    
      serial.str(string(" Tmr "))  
      serial.dec(tmr1)
      serial.str(string("     "))  
    
    PUB  Pulse
      dirb[24] :=1
    
      repeat
        outb[24] :=1
        waitcnt(cnt + 5000000)
        outb[24] :=0
        waitcnt(cnt + 5000000)
    

    pin 56 is flashing and hooked to pin 7 but still reads 0
  • ersmith wrote: »
    @CRST1 : be careful with immediate values. I see in your code some instructions like:
      asm
        dirh 7
      endasm
    
    If this is intended to work on pin 7 then you should write "dirh #7" (with a number sign). Otherwise it reads COG register 7 and then uses that value to determine the pin.

    Also, you may want to use "rdpin" instead of "rqpin". It probably doesn't matter in the accumulate example, but I think reads from the smart pin should be acknowledged in order to reset the period. You can do this either with "akpin" (if you use "rqpin") or by using "rdpin" which does a combination of read and ack.

    Thank you. That was the problem. I thought I had tried that but guess I didn't.
Sign In or Register to comment.