Announcement

Collapse
No announcement yet.

Using 16 bit shiftout with 32 bit long (in a 16 bit only MCU)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • queenidog
    replied
    Yahoo it works

    I was in a rush to get outside but I just had to test this and glad I did!

    It works perfectly as required. Thank you very much. I will use this program to learn more about the programming and then be able to better write the code for my project.

    BTW, my middle name is Henry (or Henri, the French spelling).

    Thanks again for all your help.

    Leave a comment:


  • Henrik Olsson
    replied
    Hi,
    My mistake, didn't think this thru properly... This way the SHIFTOUT only executes 16 times, we need to execute 32 times...duh... Try this instead
    Code:
    x VAR BYTE
    y VAR BYTE
    ImageWord VAR WORD
    Dummy VAR WORD
    
    Dummy = 0
    
    For y = 0 to 1
        For x = 0 to 15
            lookup2 x, [$0001,$0002, $0004, $0008, $0010, $0020, $0040, $0080, $0100_
            ,$0200, $0400, $0800, $1000, $2000, $4000, $8000], ImageWord
    
            If y = 0 THEN            
                 SHIFTOUT Datapin, Clockpin,1 ,[Dummy\16,ImageWord\16]
            ELSE
                SHIFTOUT DataPin, ClockPin, 1 , [ImageWord\16, Dummy\16]
            ENDIF
            
            high OutLED   
            pauseus 5
            low outled
        
            pause 20
        NEXT
    
    NEXT
    I've checked the above with a logic analyzer and it seems to work as intended, sorry about the confusion.

    /Henrik.

    Leave a comment:


  • queenidog
    replied
    Been there, done that

    Attached is complete code. I do loop back and I strobe the latch (portb.5- OutLED). I also paused for 100mS to see the activity. At this point nothing happens and it just sits there with LED 20 lit, others off. I will probe with logic probe and run the ICD to see where it is "cacking". Meanwhile if you see something glaring in the program, let me know.

    I worked out the sequence on paper and it should work....

    I had to use "Lookup2" because the variables are 16 bit. Curiously it compiled okay with "Lookup" but when I compiled it with the ICD, it complained about an "asm error".
    Attached Files

    Leave a comment:


  • Henrik Olsson
    replied
    Hi,
    Hmm, you need to run the code continously in loop or it will just cycle thru the LEDs once and the run of into la la land. You probably also need a short delay in there to slow the process down enough to actually see it "scan".

    If your shiftregister have a latch or strobe line you'll need to pulse that as well but judging by your original post I figured you had all that going.

    /Henrik.

    Leave a comment:


  • queenidog
    replied
    okay okay it compiles

    Okay the program compiles. The variables I had declared were a little different in spelling than the ones you gave me when I just plunked them into the code. (I had clock, you had clockpin). Fixed that.

    Nothing much happens though, LED 15 stays on all the time, all the others are off and there is no scanning. I'll work on it.

    Leave a comment:


  • queenidog
    replied
    tried it...no work

    Henrik,
    I tried that little piece of code, and while I don't see anything wrong with the syntax, the program won't compile. It complains about a "bad expression" regarding the shiftout command.

    My intention to only write one bit out and scan it all across the 32 LEDS is just to test the operation of the shiftout command and the two shift registers. Once I know that it works and HOW it works, then the plan is to send out 32 bit values one after the other to make an image for a POV (persistence of vision) project.

    I've seen lots of POVs but all 8 bit or 16 bit.

    Leave a comment:


  • Henrik Olsson
    replied
    Hi,
    Since you're only shifting out 16 bits at a time you're going to get one value in each of the 16bits registers. If you only want a single LED out of the 32 on at a time then you need to shift out the looked up word either led or followed by a word of zeros.

    Here's one, untested, idea:
    Code:
    ImageWord VAR WORD
    Dummy VAR WORD
    
    Dummy = 0
    
    For x = 0 to 15
    
      LOOKUP x, [$0001,$0002, $0004, $0008, $0010, $0020, $0040, $0080, $0100_
      ,$0200, $0400, $0800, $1000, $2000, $4000, $8000], ImageWord
    
      If x < 7 THEN
         SHIFTOUT DataPin, ClockPin, 1, [ImageWord\16, Dummy\16]
      ELSE
         SHIFTOUT DataPin, ClockPin, 1, [Dummy\16, ImageWord\16]
      ENDIF
    
    NEXT
    /Henrik.

    Leave a comment:


  • Using 16 bit shiftout with 32 bit long (in a 16 bit only MCU)

    I'm using a 16F887 that doesn't support Longs, but I have to get a 32 bit number into two SDI shift registers (connected in "series" so overflow of one continues into the other). I want to have all 32 bits in the register before I send to the output (32 LEDs).

    Here is the relevant code (with test values):
    For x= 0 to 31
    lookup2 x, [$0001,$0002, $0004, $0008, $0010, $0020, $0040, $0080, $0100_
    ,$0200, $0400, $0800, $1000, $2000, $4000, $8000, $0001, $0002, $0004_
    ,$0008, $0010, $0020, $0040, $0080, $0100 ,$0200, $0400, $0800, $1000_
    ,$2000, $4000, $8000],Imagebyte
    shiftout datapin,Clock,1,[imagebyte\16]
    The values of course are 16 bit and when I run this, I get outputs simultaneously to both shift registers so I have two LEDs scanning R-L in each 16 bit register instead of ONE LED lighting up all across the the 32 bits.

    If I could use Long, I know I could make it work. I tried sending "Imagebyte" twice, tried concatenating the two words into a 32 bit Long, tried holding on to the first 16 bit value in the register until the second one came along and pushed it down the line. All to no avail. I have an idea how to do it in assembler, but...ugh...l don't want to go down that road. Any help guys? All the examples I've seen have been 16 bit jobbies or 32 bit with 18F series MCUs that support Longs.
Working...
X