Jump to content

Recommended Posts

Posted

I've noticed a few posts about which I've scan-read about doing flashing LEDs via ASM, is there a way to do it using pure C?

I know there is a way to incorporate blocks of ASM into C, so I guess it can be done that way, but I'm phobic about ASM in the same way I am about poisonous spiders so I'd like to stay in the C environment.

Posted

so I've found 2 methods to do the blinking in ASM:

1) timer initialization - I place this to USER_Init (but,you can start or finish timer any time)

Code:

    movlw 31250 & 0xff

    movwf MIOS_PARAMETER1

    movlw 31250 >> 8

    movwf MIOS_PARAMETER2

    movlw 0x03

    call MIOS_TIMER_Init

timer jump to USER_Timer every 25ms from now

2) You must write this definition on the top of main.asm

(determine count of skips then blinking routine will be perform)

Code:

#define LX_CLIPS_BLINKING_SPEED 8          ; 6=quickly  8=mediumly  10=slowly

3) USER_Timer

    -----------

Code:

USER_Timer

; This is for erase speed interval...

        movf LX_BL_Clock, W

sublw LX_CLIPS_BLINKING_SPEED

        skpnz

        clrf      LX_BL_Clock

; if LX_BL_Clock = 0 go to  LX_PrePlay_BL routine...

        movlw 0x01

        subwf LX_BL_Clock, W

        skpc

rgoto LX_PrePlay_BL

rgoto LX_Timer_End

LX_PrePlay_BL

   

IFCLR LX_BL_Enable, 0, rgoto LX_Timer_End

IFSET LX_BL_Switch, 0, rgoto LX_LED_PrePlay_On

LX_LED_PrePlay_Off

; >> ------------------ LED Off ------------------

movf LX_Blinking_Button, W

call MIOS_DOUT_PinSet0

bsf     LX_BL_Switch, 0

rgoto LX_Timer_End

; << ------------------ LED Off ------------------

LX_LED_PrePlay_On

; >> ------------------ LED On ------------------

movf LX_Blinking_Button, W

call MIOS_DOUT_PinSet1

bcf     LX_BL_Switch, 0

; << ------------------ LED On ------------------

LX_Timer_End

incf LX_BL_Clock, F

return

registers

LX_BL_Switch - if bit D0 is 0/1=On/Off LED

LX_BL_Enable - if D0 is 0/1=disable/enable blinking

LX_Blinking_Button - into save number of button

and TKs method

USER_SR_Service_Prepare

LED_FLASH_Handler

      ;; increment counter

      incf      DOUT_LED_CTR, F

      ;; skip next block if LED should not flash

      IFCLR      DOUT_LED_FLASH_ENABLE, 0, rgoto LED_FLASH_Handler_Skip0

      ;; skip if DOUT counter < 128 (bit #7 not set), this leads to a

      ;; flashing frequency of 1 / (128 * update_cycle) = 1 / (128 * 1 mS) = ca. 8 Hz

      IFCLR      DOUT_LED_CTR, 7, rgoto LED_FLASH_Handler_Skip0

      ;; get value of LED at DOUT #0

      movlw      0x00

      call      MIOS_DOUT_PinGet

      ;; result in MIOS_PARAMETER1, invert it

      comf      MIOS_PARAMETER1, F

      ;; write back result to DOUT #0

      movlw      0x00

      call      MIOS_DOUT_PinSet

LED_FLASH_Handler_Skip0

      ;; thats all

      return

being completely ignorant of ASM - how do I pass either of the code sets the Pin number of the LED I want to control using the in-line ASM functionality in C?

Posted

Don't sweat bud, it's easy in C :) No need for inline ASM.

Question is... how do you want them to flash? I mean, is it just constant flashing, or flashing synced to something or a specified speed or...? Is it constantly blinking while the box is one or only when using a certain feature or your CS, etc etc...? Also, are you already using the user timer?

Regardless, the basic theory is that you need some kind of timer, which might be the user timer directly calling the LED flashing (I don't like that way in most cases) or a counter variable (can be incremented by user timer, or every 1ms in the SR_Service_*, or by incoming data, etc, and then someplace else, you read the counter and set the LED appropriately)

Posted

...and in completion to stryd's wise words, here are the relevant functions:

MIOS_DOUT_PinGet

MIOS_DOUT_PinSet

MIOS_DOUT_PinSet0

MIOS_DOUT_PinSet1

MIOS_TIMER_Init

MIOS_TIMER_ReInit

MIOS_TIMER_Start

MIOS_TIMER_Stop

USER_Timer

Best,

Michael

Posted

thanks for the help chaps....

I didn't realise there was a user timer function!!

I've spent so much time searching and reading I think I forgot to check back on the functions list on ucapps!!

I had an idea as I was trying to sleep last night to use the midi timecode info being sent as the timer, but this is much better....

Stryd - The main app is written and pretty stable (always need lots of time to flush out any bugs), this is for a phase 2 "extra functionality" phase.  Ableton only has 1 loop button oO, which means that you have to select the channel to set, or even see if a loop is on.

I'm going to flash the channel select button when a loop is on so you can see which channels are looping.

A timer flash is all I really need, but I'm now wondering about tying it to something like the midi clock so it flashes in time - but I think I'll move that to phase 3....

And then there is phase 3, which involves interfacing with Ableton using their API, python and probably MAX/MSP.

Posted

A timer flash is all I really need, but I'm now wondering about tying it to something like the midi clock so it flashes in time - but I think I'll move that to phase 3....

Seriously, it's just as easy either way. Jump to phase 3 on this one.  :)

Posted
Seriously, it's just as easy either way. Jump to phase 3 on this one. 

ARRGGHH!! no!!! scope creep! scope creep!

stryd is a scope creep, scope creep

(I think you might have finally pushed my fragile little brain over the edge)....

stryd is a scope creep, scope creep etc etc

Posted

hehe...  ;D

although I'm amused, I have to shelter stryd:

it's indeed even easier than setting up a timer (eg, I am never sure about this cryptic StartTimer(time) value :-X );

you just have to know three things!

1. the MIDI clock signal is sent 96 times per whole note (aka 48 per half, 24 per quarter and so on...)

2. the MIDI protocol number for the clock signal: 11111000 = 0xF8 = 248 = Timing clock

3. to get this one-byte MIDI message (or signal), you have to catch it on MPROC_NotifyReceivedByte(unsigned char byte) and not at the usual MPROC_NotifyReceivedEvnt(), where the three byte msg are landing

In other words, every time you receive the value "248" in MPROC_NotifyReceivedByte, you have a Tick. When you have counted 96 ticks, you have a whole Note! tadaa. Easy as that.

Of course, when you counted 48, it's half a note and when you wanna blink something, it might be useful to count to a quarter note (24), so it's on for a quarter and off for another one:

eg:

- receive tick

- increment counter

- if counter >= 24 switch LED

- reset counter

You really need just this info and one counter variable that keeps track of where you are.

Of course this will work only if you receive a MIDI-clock  ::)

Best,

Michael

Posted

oh wow AC  - thanks so much for the info, you've saved me some time researching there!

I was joking with Stryd, as I know it's the same amount of work and I was going to do it, I just like poking IT ppl about the dreaded scope creep ;)

Turns out I got even less work to do now - thanks again AC...

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...
×
×
  • Create New...