Shop OBEX P1 Docs P2 Docs Learn Events
Port B first run — Parallax Forums

Port B first run

pik33pik33 Posts: 2,366
edited 2014-10-21 07:51 in Propeller 1
Edit

Added the project source here. Warning - not cleaned! As it is now.
The project was made with Quartus 13.1 for DE2-115 board.

To use: open proptest project, compile, program.
SW0 has to be ON before programming the Propeller.
The Propeller has to be programmed via RS232 connector in DE2-115. I program it by real RS232 port - I don't know if usb-rs232 dongles can work.
If you want to use a PropPlug you have to change UART_xxx pins to GPIO[yy] pins, so P30, P31 and RESn will be connected to GPIO pins used by PropPlug instead or RS232. I didn'd do this because I am still waiting for a PropPlug and cannot test this configuration
When I get a PropPlug I will make my projects compatible with both programming methods.

In Propeller Tools open the portb.spin and run. Connect a VGA monitor. You should see "Port B demo running in cog 3" text.

or

copy cog.v, prop.tdf (to top.tdf), dig.inc and dig.v to your default Propeller Quartus project and use it as before, having 145 MHz speed and portb enabled.

Please test if it compiles and works


At now I have working PortB output

It needs to make changes in some files. dig.inc, top.tdf dig.v and cog.v.
//In dig.inc line 24:
    RETURNS (cfg[7..0], pin_out[31..0], pin_dir[31..0], pin_outb[31..0], pin_dirb[31..0], cog_led[7..0]);

--------------------------------------------------
//In prop.tdf (was top.pdf in original version) added

    pinb        [31..0]    : tri;

//then

    pinb[].in        = core.pin_outb[];
    pinb[].oe        = core.pin_dirb[];
    iob[]            = pinb[].out;

--------------------------------------------------
In dig.v added:

output        [31:0]    pin_outb,        // pin state outputs
output        [31:0]    pin_dirb,        // pin direction outputs

//then in "cogs" segment

wire [7:0] [31:0]    outxb;
wire [7:0] [31:0]    dirxb;

//and when generating cogs:

                    .pinb_out    (outxb[i]),
                    .pinb_dir    (dirxb[i])

// then pin sections

assign pin_outb        = outxb[7] | outxb[6] | outxb[5] | outxb[4] | outxb[3] | outxb[2] | outxb[1] | outxb[0];
assign pin_dirb        = dirxb[7] | dirxb[6] | dirxb[5] | dirxb[4] | dirxb[3] | dirxb[2] | dirxb[1] | dirxb[0];

------------------------
// now cog.v

input           [31:0]    pinb_in,            // pins
output        [31:0]    pinb_out,
output        [31:0]    pinb_dir

//then

wire setoutb        = wio && i[dl+3:dl] == 4'h5;
wire setdirb        = wio && i[dl+3:dl] == 4'h7;

//then

always @(posedge clk_cog or negedge ena)
if (!ena)
    outb <= 32'b0;
else if (setoutb)
    outb <= alu_r;

always @(posedge clk_cog or negedge ena)
if (!ena)
    dirb <= 32'b0;
else if (setdirb)
    dirb <= alu_r;     
     
// and at the end

assign pinb_out        = (outb & dirb);
assign pinb_dir        = dirb;


Connected outb[7..0] to ledr[17..10] and run this:
CON

  _clkmode = xtal1+pll16x
  _clkfreq = 145_000_000


pub demo

dira:=$00FF_0000
outa:=0
dirb:=$0000_00FF
outb:=0
repeat
  outb[7]:=0
  outb[0]:=1
  waitcnt(cnt+clkfreq>>4)
  outb[0]:=0
  outb[1]:=1
  waitcnt(cnt+clkfreq>>4)
  outb[1]:=0
  outb[2]:=1
  waitcnt(cnt+clkfreq>>4)
  outb[2]:=0
  outb[3]:=1
  waitcnt(cnt+clkfreq>>4)
  outb[3]:=0
  outb[4]:=1
  waitcnt(cnt+clkfreq>>4)
  outb[4]:=0
  outb[5]:=1
  waitcnt(cnt+clkfreq>>4)
  outb[5]:=0
  outb[6]:=1
  waitcnt(cnt+clkfreq>>4)
  outb[6]:=0
  outb[7]:=1
  waitcnt(cnt+clkfreq>>4)   

It works

Now these are pure outputs only. I have to locate and add code to get inputs, too, and I still don't know what to do with counters etc.
Another difference is: when I connectd leds to Port A, they are on after the propeller starts. So, I had to add
dira:=$00FF_0000
outa:=0

to make leds LEDR[7..0] which are are connected to P16..P23 in my project dark. LEDR[17..10], which I connected to Port B [7..0] are dark when the Propeller starts.
Maybe it has something to do with inputs still not connected.
«1

Comments

  • ozpropdevozpropdev Posts: 2,792
    edited 2014-08-12 05:37
    Thanks pik33!
    I've been stuck with 4 errors in Quartus and your post alerted me to the dig.inc file.
    I changed that and quartus compiled my nano code first try!
    I'm back in business - P1 on nano with 64 I/O!
    Programming now..... :)
  • Cluso99Cluso99 Posts: 18,069
    edited 2014-08-12 05:42
    pik33, Fantastic news !!! Congratulations.
  • pik33pik33 Posts: 2,366
    edited 2014-08-12 05:57
    inb works now. I have now the port B as simple bidirectional port without "whistles" (counters and video)

    Added:
    // in prop.tdf
    
        core.pin_inb[]    = iob[];  
    
    
    //in dig.inc
    
    FUNCTION dig (nres, clk_cog, clk_pll, pin_in[31..0], pin_inb[31..0])  //dig.inc
    
    //in dig.v
                .pinb_in    (pin_inb),  
    
    
    // in cog.v
    
    input           [31:0]    pinb_in,            // pins -
    
                        : i[sh:sl] == 9'h1F3    ? pinb_in     
    

    This needs to be tested and cleaned now :)
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-12 06:19
    pik33 wrote: »
    inb works now. I have now the port B as simple bidirectional port without "whistles" (counters and video)

    Added:
    // in prop.tdf
    
        core.pin_inb[]    = iob[];  
    
    
    //in dig.inc
    
    FUNCTION dig (nres, clk_cog, clk_pll, pin_in[31..0], pin_inb[31..0])  //dig.inc
    
    //in dig.v
                .pinb_in    (pin_inb),  
    
    
    // in cog.v
    
    input           [31:0]    pinb_in,            // pins -
    
                        : i[sh:sl] == 9'h1F3    ? pinb_in     
    

    This needs to be tested and cleaned now :)

    Just got back in front of it all, don't know where you get the time but I'm compiling with those changes now, thanks!
  • Heater.Heater. Posts: 21,230
    edited 2014-08-12 06:35
    Hey, that is cool pik33.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-12 06:42
    Seem to have a few errors, I'm sure I've got those statements in the right places so I also added this to top.tdf (I guess that's your Prop.tdf)
    subdesign top 
    ( 
        clock_50        : input;        -- clock input 
     
        inp_resn        : input;        -- reset pin 
         
        io        [31..0]    : bidir;        -- i/o pins 
     
        iob        [31..0] : bidir;        -- i/o B pins 
     
        ledg    [7..0]    : output;        -- cog leds 
    )
    
    But these are the errors:
    Error (287084): Symbolic name "pin_inb" is used but not defined as a group
    Error (287097): Left of Boolean equation cannot contain text "pin_inb"
    Error (287114): Groups cannot be assigned to nodes
    Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 3 errors, 1 warning
    Error: Peak virtual memory: 725 megabytes
    Error: Processing ended: Tue Aug 12 23:42:03 2014
    Error: Elapsed time: 00:00:01
    Error: Total CPU time (on all processors): 00:00:01
    Error (293001): Quartus II Full Compilation was unsuccessful. 5 errors, 1 warning

    Please bear with me, I'm trying to sort this out myself but my Verilog skills are still only a few hours old :)


    EDIT: found the earlier post but also included in cog.v prior to always section
    reg [31:0] outb;
    reg [31:0] dirb;

    That right?
  • rjo__rjo__ Posts: 2,114
    edited 2014-08-12 06:46
    For many of us, you work is starting to look like a rosetta stone. Thanks.

    Does the last line of your last post

    : i[sh:sl] == 9'h1F3 ? pinb_in

    belong in cog.v under //source
    as part of wire[31:0] sx...?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-12 06:50
    rjo__ wrote: »
    For many of us, you work is starting to look like a rosetta stone. Thanks.

    Does the last line of your last post

    : i[sh:sl] == 9'h1F3 ? pinb_in

    belong in cog.v under //source
    as part of wire[31:0] sx...?

    I think pik has given himself a well deserved vodka break...this is where I put it:
    wire [31:0] sx        = i[im]                    ? {23'b0, i[sh:sl]} 
                        : i[sh:sl] == 9'h1F0    ? {16'b0, ptr[27:14], 2'b0} 
                        : i[sh:sl] == 9'h1F1    ? cnt 
                        : i[sh:sl] == 9'h1F2    ? pin_in 
                        : i[sh:sl] == 9'h1F3    ? pinb_in            // PINB                      
                        : i[sh:sl] == 9'h1FC    ? phsa[31:0] 
                        : i[sh:sl] == 9'h1FD    ? phsb[31:0] 
                                                : sy; 
    
  • Kerry SKerry S Posts: 163
    edited 2014-08-12 07:07
    This is just amazing work pik!

    Thank you for getting this rolling. This alone makes a huge leap forward for the P1V. Hopefully with my ZERO Verilog skills I can figure out how to implement this on my BEMicro CV when it gets here.
  • rjo__rjo__ Posts: 2,114
    edited 2014-08-12 07:10
    Thanks Peter, that's what I thought. But at my level, better to ask first.

    One of the problems with the block approach is that you need the sources. Obviously, that won't be available for the P2.

    I was wondering if anything like the block implantation is possible for .jic type files... or if they (.jic) could be modified somehow to expose just enough to allow a block-like implementation.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-12 07:18
    rjo__ wrote: »
    Thanks Peter, that's what I thought. But at my level, better to ask first.

    One of the problems with the block approach is that you need the sources. Obviously, that won't be available for the P2.

    I was wondering if anything like the block implantation is possible for .jic type files... or if they (.jic) could be modified somehow to expose just enough to allow a block-like implementation.

    Not sure, I'm too wet behind the ears yet, but I'm sure I've picked up another typo too:
    // in prop.tdf      core.pin_inb[]    = iob[];   
    Instead:
        -- port B 
         
        core.pin_in[]    = iob[];   -- must be core.pin_in[] not inb[] ????
     
        pinb[].in        = core.pin_out[]; 
        pinb[].oe        = core.pin_dir[]; 
         
        iob[]            = pin[].out; 
    
  • rjo__rjo__ Posts: 2,114
    edited 2014-08-12 07:48
    I'm not sure that is a typo. I'm dry lab on this at the moment, so I haven't tried to do the modifications.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-12 07:56
    rjo__ wrote: »
    I'm not sure that is a typo. I'm dry lab on this at the moment, so I haven't tried to do the modifications.

    I did get it to compile but I'm making some other changes and I will post the zip when it looks good.
  • rjo__rjo__ Posts: 2,114
    edited 2014-08-12 08:02
    Thank you:)
  • pik33pik33 Posts: 2,366
    edited 2014-08-12 08:23
    I haven't quartus open now, but it has to be core.pin.inb[]. I added inb to dig.v and forget to put this here - i had to close my system and I was in hurry. I will continue this tomorrow - after some cleaning, I will put the complete code here.

    input        [31:0]    pin_inb,
    
    
    I needed working PortB to add a sound chip. Maybe tomorrow the DE115 will give some sound. I hope the SD card will be easy, simply connecting P0..P4 to SD slot on DE2-115
  • Bill HenningBill Henning Posts: 6,445
    edited 2014-08-12 08:30
    pik33,

    Great work. Looking forward to it!

    FedEx tracking says my BE MICRO CV's will be delivered today by 5pm... I should download the latest Quartus Web Edition.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-12 08:32
    pik33 wrote: »
    I haven't quartus open now, but it has to be core.pin.inb[]. I added inb to dig.v and forget to put this here - i had to close my system and I was in hurry. I will continue this tomorrow - after some cleaning, I will put the complete code here.

    input        [31:0]    pin_inb,
    
    
    I needed working PortB to add a sound chip. Maybe tomorrow the DE115 will give some sound. I hope the SD card will be easy, simply connecting P0..P4 to SD slot on DE2-115

    Yes, I had found that after I fixed dig.inc as there was a typo as now I see the relationship. I need to sleep although I have learned a lot just patching this, so that's good.
  • ozpropdevozpropdev Posts: 2,792
    edited 2014-08-12 08:57
    Nano is now running with 64IO + 100MHz...now to add PortC on the 26pin connector and some more counters.... this is fun! :):lol:
  • pik33pik33 Posts: 2,366
    edited 2014-08-12 09:16
    And why 100 MHz only? Try this and check if it run.. in top.tdf:
                            clk0_multiply_by = 28,
                            clk0_divide_by = 5);
    

    28 will give 140 MHz on the Propeller... 30 will be 150.. etc... In my experiments this is still the wall. I got it running @ 155 MHz but then there was errors (bad colors displayed on the monitor). Still have to learn the timing tool to know how to apply the patch proposed by Chip - he thinks the cog can run then over 200 MHz.

    PortC will not be easy. We can of course give it an addresses like 1ED..1EF but then there is no PortC in Spin and we will have lost compatibility.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-12 09:39
    Don't you just hate that, I was updating dig.inc from the original project code whereas I was compiling from a new project and I just couldn't understand why it wasn't making a difference.
    Good grief Charlie Brown.....of all the dunderhead mistakes we make late at night.
    Now it's compiling nicely, still takes just under 10 mins though.
  • Bill HenningBill Henning Posts: 6,445
    edited 2014-08-12 09:58
    I wish!

    I have some urgent work to finish - I am sneaking peeks at the forum while working on other stuff - but hopefully I can download the latest Quartus to this box today, and compile tonight :)

    Compile times should be pretty good on this box, but I may have to upgrade the memory (8 core / 4Ghz, but only 8GB of ram) and switch to an SSD.
    User Name wrote: »
    Maybe if you start right this minute it will have completed by the time FedEx arrives. ;)
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-12 10:41
    After those couple of dumb mistakes and making sure I converted and used the correct file I programmed the DE0 and loaded with Tachyon and sure enough it runs fast at 140MHz. Just using it to check the hardware and I must have made a mistake somewhere as the OUTB register isn't being written. I will check out the source in the meantime but where are the PORTB pins assigned to physical I/O pins on the DE0?
    -1 DIRB COG!  ok
    -1 OUTB COG!  ok
    .SPRS 
    01F0: PAR  = $0000_16E8   00_0000_0000_0000_0001_0110_1110_1000
    01F1: CNT  = $C5C0_CD5E   00_0101_1100_0000_1100_1101_0101_1110
    01F2: INA  = $FFFF_FFFE   11_1111_1111_1111_1111_1111_1111_1110
    01F3: INB  = $0200_012D   00_0010_0000_0000_0000_0001_0010_1101
    01F4: OUTA = $7000_0000   11_0000_0000_0000_0000_0000_0000_0000
    01F5: OUTB = $0000_012D   00_0000_0000_0000_0000_0001_0010_1101
    01F6: DIRA = $4000_0000   00_0000_0000_0000_0000_0000_0000_0000
    01F7: DIRB = $FFFF_FFFF   11_1111_1111_1111_1111_1111_1111_1111
    01F8: CTRA = $0000_0000   00_0000_0000_0000_0000_0000_0000_0000
    01F9: CTRB = $0000_0000   00_0000_0000_0000_0000_0000_0000_0000
    01FA: FRQA = $0000_0000   00_0000_0000_0000_0000_0000_0000_0000
    01FB: FRQB = $0000_0000   00_0000_0000_0000_0000_0000_0000_0000
    01FC: PHSA = $0000_0000   00_0000_0000_0000_0000_0000_0000_0000
    01FD: PHSB = $0000_0000   00_0000_0000_0000_0000_0000_0000_0000
    01FE: VCFG = $0000_0000   00_0000_0000_0000_0000_0000_0000_0000
    01FF: VSCL = $0001_3880   00_0000_0000_0001_0011_1000_1000_0000 ok
    


    EDIT: I don't see where we can assign these pins to the physical pins, it seems IOB[0] ended up here:
    iob[0]                       : L2        : bidir  : 3.3-V LVCMOS      :         : 2         : N
    
    Which seems to be the SDRAM row address strobe??


    But I have 32-channel 8-bit PWM running at 13.45kHz, nice. Being table based I can drop the resolution and increase the frequency too.
  • pik33pik33 Posts: 2,366
    edited 2014-08-12 11:21
    It is not connected to anything. You can connect it to something by editing top.pin or maybe top.qsf - not 100% sure, because I didn'd do this, or by converting top.tdf to a block and then graphically connect portb to what you want (I connected 8 lower bits of it to LEDR17..LEDR10 and then tested with Spin)

    The Quartus connected it where it wants to, into random places changing from compilation to compilation, until you connect it to your desired pins
  • Willy EkerslykeWilly Ekerslyke Posts: 29
    edited 2014-08-12 12:43
    EDIT: I don't see where we can assign these pins to the physical pins, it seems IOB[0] ended up here:
    iob[0]                       : L2        : bidir  : 3.3-V LVCMOS      :         : 2         : N
    
    Which seems to be the SDRAM row address strobe??
    .

    Peter, in Quartus go to the Assignment menu then choose Pin Planner. You should see the I/Os listed - just enter the appropriate pin designations into the Location column of the grid
  • jmgjmg Posts: 15,173
    edited 2014-08-12 16:07
    pik33 wrote: »
    Now these are pure outputs only. I have to locate and add code to get inputs, too, and I still don't know what to do with counters etc.
    ....
    inb works now. I have now the port B as simple bidirectional port without "whistles" (counters and video)

    Good progress.
    Counter mapping to 64io should be possible using spare bits waiting in CTRx.

    It's probably a good idea to split Video into a conditional, for those smaller FPGAs it may save significant logic to not include that.

    The next logical thing to overlay on Counters and the other Spare Bits in CTRx, would be ADDING SERIAL support.
    (but this needs to NOT break any counter operation)

    Some ideas on this :
    It could use the Counter PIN-Map MUX to save Logic, but means you have Counters OR Serial, and counters can be useful to generate some strobe signals.
    It may be one Serial and One counter is enough ?

    The MSB could flag a write to SER config, (allows 31b of Serial Config) and READ would need to merge selected CTR and SER bits.
    Probably not much code Reads CTRx now ?

    The simplest serial design would be ADC_SPI_RX.
    That generates a CLK (can be continuous, under some CLK-DIV) and a CS
    (of some user-set width, typically repeats 16 Clks).
    More complex (dual, fast) ADCs need a SEL pin, eg toggling every 16c.
    Perhaps that can be done with CTR ?
    When enabled, SERx would make READ of a counter register Serial read (PHSx?)

    Those low-logic-cost additions, would allow fast ADC support with invisible background streaming, to to 40/48+MHz.
  • roglohrogloh Posts: 5,791
    edited 2014-08-12 21:21
    Good stuff pik33. It will be great to have a portB on a prop. We need to figure out a way to get WAITPEQ and WAITPNE going too. I think Chip had planned a scheme that used the Carry bit to decide which port (INA or INB) to use with these instructions, but this wasn't implemented on the original device. Might be good to have WC flag indicate that new behavior, and not modify the flag, or alternatively use WC when port B is desired (and not actually use or modify C). The latter approach may be more desirable so as to not have to clobber your C flag when you want to use WAITPEQ/WAITPNE instructions on port B.

    Update:
    If we go with my suggested latter approach we can always still use the C flag to select between A/B ports if dynamic port selection is required using this code to emulate the original behaviour (at the expense of one added instruction cycle/space).
    if_nc WAITPEQ xx,yy    ' C=0 so use port A
    if_c  WAITPEQ xx,yy wc ' C=1 so use port B 
    
    ' OR just 
    
    WAITPEQ xx,yy    ' forces port A
    
    WAITPEQ xx,yy wc ' forces port B
    
  • pik33pik33 Posts: 2,366
    edited 2014-08-12 21:23
    We have serial output ,the video circuit. We don't have serial input. Maybe some messing with video circuit can do this.
  • roglohrogloh Posts: 5,791
    edited 2014-08-12 23:15
    pik33 wrote: »
    We have serial output ,the video circuit. We don't have serial input. Maybe some messing with video circuit can do this.

    Yes it would be great to get the long discussed reverse WAITVID for serial data using "WAITVID d,s WZ" for example. Maybe it could automatically use the counter(s) to assign the data/clock pins and clock rate on the nominated pins associated with the counter(s). Two counters in a COG gives you clock rate, and up to 4 defined pins (perfect for four pin SPI). I noticed there is a spare top bit of the CTRA/CTRB register which could be useful here to extend the counter mode for potential serial transfers and reverse WAITVID (same goes for VCFG by the way). A bidirectional transfer would then be possible, with the D argument receiving input data and S argument used for writing output data, and the instruction blocking until completion (like video based WAITVID already does today). Different WC/WZ combinations could also possibly be used to choose to not block and just poll. Lots of design possibilities there. I'm sure plenty of people will want this capability.
  • pik33pik33 Posts: 2,366
    edited 2014-08-12 23:40
    Sources added to the first post. Warning - not cleaned!
  • pik33pik33 Posts: 2,366
    edited 2014-08-13 00:05
    Now some idea about PortC implementing without using 1Ex addresses...

    Having separate inb and outb is simpy wasting an address space We can write to the register to set the output and read the same address to get the input. We have 6 registers: ina,outa,dira, inb,outb,dirb. Let them be inouta, inoutb, inoutc, dira, dirb, dirc.

    This of course breaks compatiblility.
Sign In or Register to comment.