Jump to content

MIOS loop


DriftZ
 Share

Recommended Posts

My little MIOS project encountered its next obstacle.

The type of display (2-1/2 digit, multiplexed) that I want to use poses a problem, it seems that I need to switch the input very rapidly to get all numbers correct because some of the digit's components share input lines.

It's a bit hard to explain, but I'll try with an (fictious)example.

I need to send 10001000 to the SR to get the upper half of number '2' lit.

I need to send 00010001 to the SR to get the lower half of number '2' lit.

If I would send 10011001 to the SR I wouldget a full '2' but also some other stuff lit by 10001001 or other combinations.

So the solution would be to switch between the first 2 bytes very quickly.

Now in MIOS I cannot find the way to do this kind of loop. I can send the values to the SR, but only the last byte (& so only the lower half of the number) would be on the display. IOW, it does not 'loop'

It looks now somewhat like this:

USER_SR_Service_Prepare

     movlw b'01100001'

     movwf      MIOS_PARAMETER1

     movlw 0

     call      MIOS_DOUT_SRSet

     movlw b'10001110'

     movwf      MIOS_PARAMETER1

     movlw 0

     call      MIOS_DOUT_SRSet

     return

I tried it also to put it in the USER_SR_Service_Finish & other blocks, but it also didn't work.

Is there a good solution to this ?

Thanks & greetz !

DriftZ

Link to comment
Share on other sites

The solution is to alternate the patterns on every call of USER_SR_Service_Prepare, so that on the first cycle the upper half, and on the second cycle the lower half will be displayed. It's the same method which is used to multiplex the digits (thats the purpose of the counter...), your eyes won't regognize the fast changes.

You could use a register named LEDDIGITS_PATTERN_CTR, increment this counter on every cycle (don't take care for overruns) - when bit #0 is set, write the first pattern to the SR, when bit #0 is cleared, write the second pattern.

Best Regards, Thorsten.

Link to comment
Share on other sites

Hi TK, thanks for answering again,

The solution is to alternate the patterns on every call of USER_SR_Service_Prepare

I made a construction with BTFSC & INCF but still I get the same results.

I don't call USER_SR_Service_Prepare from anywhere myself, so is it only called once ? (& it is not looping ?)

Then I still would have my original problem, not ?

USER_SR_Service_Prepare

     BTFSC LEDDIGITS_PATTERN_CTR , 0

     call ShowUpper ;; (upper half of digit)

     call ShowLower ;; (lower half of digit)

     incf LEDDIGITS_PATTERN_CTR

     return

ShowUpper

     movlw b'01111001'

     movwf      MIOS_PARAMETER1

     movlw 0

     call      MIOS_DOUT_SRSet

     return

ShowLower

     movlw b'01001111'

     movwf      MIOS_PARAMETER1

     movlw 0

     call      MIOS_DOUT_SRSet

     return

best regards

Link to comment
Share on other sites

Hi DriftZ,

I don't call USER_SR_Service_Prepare from anywhere myself, so is it only called once ? (& it is not looping ?)

Just read the comment above the function:

;; --------------------------------------------------------------------------
;;  This function is called by MIOS before the shift register are loaded
And shift registers are loaded with the frequency specified by MIOS_SRIO_UpdateFrqSet (you should find this function call in your *_init.inc file - normaly every mS The problem with your code is, that ShowLower is called regardless of LEDDIGITS_PATTERN_CTR, 0
  BTFSC LEDDIGITS_PATTERN_CTR , 0
  call ShowUpper ;; (upper half of digit)
  call ShowLower ;; (lower half of digit) 
  incf LEDDIGITS_PATTERN_CTR
"btfsc" means: skip next instruction if clear - this means that ShowUpper will be skipped on every second cycle, but ShowLower will be called every time. Improved version:
  btfsc LEDDIGITS_PATTERN_CTR, 0
  call ShowUpper ;; (upper half of digit)
  btfss LEDDIGITS_PATTERN_CTR, 0
  call ShowLower ;; (lower half of digit) 
  incf LEDDIGITS_PATTERN_CTR, F
or better readable and understandable:
   IFSET LEDDIGITS_PATTERN_CTR, 0, call ShowUpper
   IFCLR LEDDIGITS_PATTERN_CTR, 0, call ShowLower
   incf LEDDIGITS_PATTERN_CTR, F

(IFSET and IFCLR are some macros defined by myself (TK style, see macros.inc), they are using btfsc and btfss)

Best Regards, Thorsten.

Link to comment
Share on other sites

  • 7 months later...

Heya DriftZ,

I hope I'm not being too rude in asking this of you, but I was hoping that maybe you might be able to post the code for this to the midibox portal perhaps, or maybe some other place?

If you'd rather keep your clever tricks a secret, that is understandable though, so no pressure!  :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...