Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:44 11 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MSB to LSB conversion ?

Author Message
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 01:11pm 25 Jun 2014
Copy link to clipboard 
Print this post

ColorMaximite 4.5

I've bought some of these
They work well (as far as a signal out)
BUT !
Now I see they want LSB first as opposed to MSB first as MMBasic SPI puts out .
Any simple way to convert ? Or am I missing (hopefully :) ) some setting ?
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6220
Posted: 02:24pm 25 Jun 2014
Copy link to clipboard 
Print this post

Would this help

main:
INPUT x
PRINT bitreverse(x, 16)
GOTO main

FUNCTION bitreverse(num, k)
' reverse bit order
' num = integer to reverse
' k = number of bits (8 or 16)
LOCAL n
FOR n = 1 TO k
IF (num AND 2^(n-1)) > 0 THEN
bitreverse =bitreverse+ 2^(k-n)
ENDIF
NEXT n
END FUNCTION


It works for 8 or 16 bit numbers (or anything that MMBasic handles as integers)
If you have it set to 8 bits and enter a number greater than 255, the result will be strange.

Jim

VK7JH
MMedit
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 04:20pm 25 Jun 2014
Copy link to clipboard 
Print this post

Ya Mon
Too much beer right now to tell for sure,
but that should do it !
Beautifull
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 01:27pm 26 Jun 2014
Copy link to clipboard 
Print this post

Thank You TassyJim ! I owe you a beer down by the billybong :)

clk=83886 ' pwm to clk in on synth
inp=11000 ' SPI to control on synth
SetPin 5,2 ' rx for SPI (not used)
For p=1 To 3: SetPin p,8: Next p
Pin(1)=1 ' data latch

playnote:
If KeyDown=0 Then GoTo playnote
If KeyDown=128 Then clk=clk*1.001
If KeyDown=129 Then clk=clk/1.001
If KeyDown=130 Then inp=inp/1.001
If KeyDown=131 Then inp=inp*1.001

PWM clk,50,50
Pin(1)=0
A= SPI( 5,3,2,bitrev(inp),L,3,16 )
Pin(1)=1
Cls
Print " clk =";clk
Print " inp =";inp
Print " bitrev =";bitrev(inp)
Print " freq =";(inp*clk)/(2^23)
GoTo playnote
End

Function bitrev(inp)
For n=1 To 16
If (inp And 2^(n-1)) > 0 Then
bitrev = bitrev + 2^(16-n)
EndIf
Next n
End Function

 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025