PDA

View Full Version : MIBAM and 12F1822...



alesniak
- 28th August 2011, 19:14
first off greetings, been a long time lurker here, can't even remember the number of times posts from this forum has saved me, usually when I'm stuck a quick search get's me unstuck with ease... so thank you everyone.

now for the stuck part...

I've been using Darryl's awesome MIBAM with a 12F683 for some time, just
some fading rgb led's etc.. nothing fancy, everything works great...

enter the 12F1822, was hoping to eventually utilize the hardware EUSART to send rgb color data to each led, since using MIBAM pretty much rules out any software serial communication on the 683. (and not quite sure when the 12F1501 will be available with 4xPWM)

So before I go any further I wanted to just setup a simple test program to make sure things in general are working..

here's how the pic is wired up..
http://www.andylesniak.com/mibam/connection.jpg

here is my code for basic testing

'************************************************* ***************
' MIBAM TEST pic12F683 / pic12f1822 *
'************************************************* ***************

#IF __PROCESSOR__ = "12F1822"
#MSG "Compililng for 12F1822..."
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#ENDCONFIG
OSCCON = %01110000 '8mhz
TRISA = %00011000 'setup inputs/outputs
ANSELA = %00010000 'RA4 = analog
CM1CON0 = 0 'disable comarators
ADCON0 = %00001101 'Select AN3 enable ADC
ADCON1 = %11010000 'Right Justify - Fosc/16 & 8mhz
#ELSE
#if __PROCESSOR__ = "12F683"
#msg "Compiling for 12F683..."
#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
#ENDCONFIG
OSCCON = %01110001 '8mhz
TRISIO = %00011000 'setup inputs/outputs
ANSEL = %01011000 'RA4 = analog
CMCON0 = %00000111 'disable comarators
ADCON0 = %10001101 'Right Justify - Fosc/16 & 8mhz
#else
#ERROR "Only 12F1822 & 12F683 are supported!"
#endif
#ENDIF

DEFINE OSC 8 '8mhz
DEFINE ADC_BITS 10 '10 bit ADC

DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 5
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0

;____[ For 12F/16F only - Interrupt Context save locations]_________________
wsave var byte $20 SYSTEM ' location for W if in bank0
;wsave var byte $70 SYSTEM ' Alternate save location for W
' if using $70, comment out wsave1-3
' --- IF any of these next three lines cause an error ?? -------------------
' Comment them out to fix the problem ----
' -- The chip being used determines which variables are needed -------------
wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
'wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
'wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
'---DO NOT change these-----------------------------------------------------
ssave VAR BYTE BANK0 SYSTEM ' location for STATUS register
psave VAR BYTE BANK0 SYSTEM ' location for PCLATH register

;----[ MIBAM Setup ]--------------------------------------------------------
BAM_COUNT CON 3 ; How many BAM Pins are used?
INCLUDE "MIBAM.pbp" ; Mirror Image BAM module

RED VAR BYTE
GRN VAR BYTE
BLU VAR BYTE
adc_val var word 'adc value variable
adc_thresh var word 'adc trigger threshold variable

ASM
BAM_LIST macro ; Define PIN's to use for BAM
BAM_PIN (PORTA,0, BLU) ; and the associated Duty variables
BAM_PIN (PORTA,1, RED)
BAM_PIN (PORTA,2, GRN)
endm
BAM_INIT BAM_LIST ; Initialize the Pins
ENDASM

Speed CON 5 'led fade speed
adc_thresh = 300 'trigger threshold
red = 0
blu = 0
grn = 0

T1CON.0 = 0 'disable mibam
debug "Program Start..",13,10
pause 2
T1CON.0 = 1 'enable mibam

'test MIBAM turn on and fade each led
FOR red = 255 to 1 STEP -1
PAUSE Speed
NEXT red
red = 0

FOR grn = 255 to 1 STEP -1
PAUSE Speed
NEXT grn
grn = 0

FOR BLU = 255 to 1 STEP -1
PAUSE Speed
NEXT BLu
blu = 0

'------------------------ MAIN PROGRAM LOOP ------------------------
main:
gosub do_adc 'get ADC reading
pause 20

T1CON.0 = 0 'disable mibam
debug "ADC: ",dec4 adc_val,13,10
pause 2
T1CON.0 = 1 'enable mibam

if adc_val > adc_thresh then

FOR red = 255 to 1 STEP -1
PAUSE Speed
NEXT red
red = 0

FOR grn = 255 to 1 STEP -1
PAUSE Speed
NEXT grn
grn = 0

FOR BLU = 255 to 1 STEP -1
PAUSE Speed
NEXT BLu
blu = 0

endif
goto main

'----------------------------------------------------------------------

Do_Adc:
pauseus 50
ADCON0.1=1
WHILE ADCON0.1 : WEND
adc_val.highbyte = ADRESH
adc_val.lowbyte = ADRESL
return



when compiled for 12F683, everything works fine... the test program does.
1. debug output --> "Program Start..."
2. lights up and fades each led r/g/b
3. debug output ADC reading
4. waits for ADC threshold to >300 then triggers the light sequence again.

now when I first compiled for 12F1822 I was greeted with the following error

PICBASIC PRO(TM) Compiler 3.0.0.4, (c) 1998, 2011 microEngineering Labs, Inc.
All Rights Reserved.
[MESSAGE] ledtest.pbp(13): Compililng for 12F1822...
[ASM ERROR] LEDTEST.ASM (451) : Illegal opcode (_CylonMask)
[ASM WARNING] LEDTEST.ASM (451) : Found label after column 1. (rrcf)
[ASM ERROR] LEDTEST.ASM (459) : Illegal opcode (_CylonMask)
[ASM WARNING] LEDTEST.ASM (459) : Found label after column 1. (rlcf)
[ASM WARNING] LEDTEST.ASM (547) : Extraneous arguments on the line


not being one to give up so fast... started to track down what is causing the error message... discovered the following in MIBAM.bas.



;----[ makes rrf work on 18F's ]--------------------------------------------
ASM nolist
ifdef BSR
#define rrf rrcf
#define rlf rlcf
endif
list ENDASM

if I comment out the #define's the program does compile successfully however mibam begins to work correctly and then stops working. The following happens.
1. debug output --> "Program Start..."
2. lights up and fades each led r/g/b
3. debug output ADC reading
4. waits for ADC threshold to >300 *FAILS* to tigger the light sequence.

basically you can see that the loops are running due to the pause in debug output but the leds now stay off...

I am assuming that because the 12F1822 is a new part with added features such as automatic context saving etc, I need to do some changes to the MIBAM code, but I really am not sure where to start.. looking to see if anyone has tried using MIBAM on newer pics?

untill then going to go brush up on my assembly knowledge some and see what trouble I can get myself into changing things... :)

mister_e
- 28th August 2011, 21:14
OK so the new parts have BSR which were only available on 18Fs before hence why There's quite a fer IFDEF BSR in MIBAM's code. Spot them and change them accordingly. I think it should work after that. Unfortunately I don't have this spêcific PIC on hand to test drive it

mister_e
- 28th August 2011, 21:39
try the one in the attachement.

Attachment removed.
The program was completely destroyed by the modifications.

mister_e
- 28th August 2011, 22:41
Another thing... RA4 = AN3, so you need to modify your ANSELA line

alesniak
- 28th August 2011, 23:40
Thanks for the help!

so just tried the modMIBAM code, unfortunatly still getting strange results. different results but still not correct..

so now the led's do the initial test light up and fade, r/g/b and then when I
trigger the adc threshold it does work but only the first 1-3 times then the
led stops working. hmmm must be something else that needs to be modified..

I was wondering about this section of MIBAM code as well.

ifdef BSR ; 18F
variable ReloadCount = 5
variable Latency = 6
variable ExitLatency = 4
else
variable ReloadCount = 7 ; ---- FIX THESE ----
variable Latency = 10 ; 16F
variable ExitLatency = 10
endif


I tried to change the values swapping between the 16f / 18f values as a test, but didn't seem to do anything.

mister_e
- 29th August 2011, 00:42
Again... your ANSELA line do not seems good...
change it to
ANSELA = %00001000

and get rid of the DEFINE ADC_BITS 10 line

Stil not for... replace the ADC reading by a ADC_VAL loop, see what happen.

IMHO It has to work... or I still miss a crispy detail.

mister_e
- 29th August 2011, 00:51
What happen if you Enable/Disable MIBAM within the IF/Then loop?


main:
gosub do_adc 'get ADC reading
pause 20

;T1CON.0 = 0 'disable mibam
debug "ADC: ",dec4 adc_val,13,10
pause 2
; T1CON.0 = 1 'enable mibam

if adc_val > adc_thresh then
T1CON.0 = 1 'enable mibam
FOR red = 255 to 1 STEP -1
PAUSE Speed
NEXT red
red = 0

FOR grn = 255 to 1 STEP -1
PAUSE Speed
NEXT grn
grn = 0

FOR BLU = 255 to 1 STEP -1
PAUSE Speed
NEXT BLu
blu = 0
T1CON.0 = 0 'disable mibam
endif
goto main

alesniak
- 29th August 2011, 02:12
I changed out the ANSELA line... not quite sure what is wrong with it.
(and removed the DEFINE ADC_BITS 10 line as well)

seemed correct looking at the datasheet.
http://www.andylesniak.com/mibam/ds1.jpg
I am using AN3 as my analog input which is RA4, the readings I am getting
with the debug output are correct (phototransistor reading light levels)

also tried to enable/disable MIBAM within the loop, now the led doesn't trigger at all, with the enable/disable just around the debug statment, it did work once or twice before stopping... very strange.

wondering if there is some other peripheral that needs to be disabled perhaps?
these new pics have pretty much everything multiplexed except the kitchen sink it seems.

http://www.andylesniak.com/mibam/12f1822.jpg

Darrel Taylor
- 29th August 2011, 02:51
alesniak,

I am modifying MIBAM to work with the 16F1's.
They did not exist when I wrote it.

mister-E's modifications will not work, and I've deleted the attachment above.
I don't need non-working copies of MIBAM floating around the internet, since I'm the one that people will complain to.

I should have it by tomorrow.

alesniak
- 29th August 2011, 16:58
fantastic! thank you Darrel! looking forward to it..

Darrel Taylor
- 30th August 2011, 01:58
Ok, here's the modification of MIBAM for use with 16F1's.
It also works with 14-bit cores (12F, 16F) and 18F's.

I've tested it on 16F1827, 16F1947, 16F877A and 18F4550.
Sorry, I don't have a 12F1822.

One problem I spent a lot of time trying to figure out ended up being caused by the statements ...

T1CON.0 = 0 'disable mibam
T1CON.0 = 1 'enable mibam

I really thought that would work to stop interrupts from occuring during the DEBUG statements.
But it turns out that 1 interrupt can still happen after you stop the timer.
I have yet to understand how that happens, but it does.

If you use these statements instead ...

GIE = 0 'disable mibam
GIE = 1 'enable mibam

then no further interrupts occur to disturb the DEBUG's.
They are actions of the chips themselves, not MIBAM.

MIBAM seems stable at this point, but let me know if you have any problems.

alesniak
- 30th August 2011, 17:40
fantastic! thank you again... going to give this a try this evening and report back. (day job and stuff..)

question: is it going to be possible to use the hardware uart while mibam is running? eventually would like be able to receive serial commands, rgb data
to control led color.

Darrel Taylor
- 30th August 2011, 18:55
Sure, the USART will work fine with MIBAM.
Then you don't need to disable interrupts.

I don't think you can have the POT connected, since the USART will use 2 pins and the LED's use 3 pins.
There won't be an analog pin left. But since the serial data controls the LED's, you probably don't need the POT anymore.

alesniak
- 1st September 2011, 07:44
update: finally got time to test the new MIBAM with the 12F1822 and works like a charm!! good stuff.
So.... to make a more "proper" test I figured I'd whip up a little project to give a better demo, so did a quick and dirty pcb design threw in a few components, and presto a uber quick, interactive light module, (always wanted a interactive tabletop)

here's a super rough video showing it all in action...


http://www.youtube.com/watch?v=G5fSrWt3ZKw

I'm going to take a few days to clean up the code/pcb gerbers and post them
here if anyone wants to build a fun blinky toy... :)

Darrel Taylor
- 1st September 2011, 14:34
Ooooo, very cool!
That's the neatest use of MIBAM I've seen so far.

Thanks for the video. I think my counter top needs a makeover. (if I wasn't renting)

Bruce
- 1st September 2011, 16:53
Yup. Very cool. Are you using the LEDs to sense changes, then flipping them to outputs, or using sensors?

alesniak
- 1st September 2011, 19:22
the circuit is just a phototransistor and a resistor for the detector, I added a IR led next to it as well so it works in the dark. I sample the ADC every few ms and calculate the difference from previous/last sample, to get a delta value, and just trigger some flahsy lights if the delta exceeds the threshold value, which controls how sensitive the trigger is.

I now have 1 pin left to do something with (I used it for debug output to see what my adc output was, thinking of using it to trigger adjacent modules perhaps, to create a cascading effect perhaps)

funny didn't intend to build this earlier, but it's kinda fun, so I'll just keep going with it and see what I can get this tiny pic to do..

and the 12f1822 is dirt cheap so perhaps I'll build a few dozen at least and
see how it goes.

Ioannis
- 5th September 2011, 09:49
Am I the only one that cannot see the video?

Ioannis

mister_e
- 5th September 2011, 16:53
Doies it start or it says it's blocked due to copyright plah plah? Works here though (Firefox)

Ioannis
- 5th September 2011, 21:13
Hmm, curious. Now I am at home with a Vista/IE9 and it works OK.

By the way very nice project alesniak.

On my office XP-IE8 it was pure white. No youtube window no message. Nothing.

Ioannis

mister_e
- 5th September 2011, 21:52
I would try to re-install flashplayer and see what happen. Never messed that much with IE though...FireFox FTW :D

alesniak
- 6th September 2011, 05:13
hmm, must be a IE thing, I use firefox or chrome and the video seem to work fine.

so sorry for the delay, I decided to make a about a hundred modules to build a
interactive light table, so took me a few days to get the layout finished before I sent off a test pcb run, here's the pbp code if anyone is interested, feel free to make it better, cooler, etc.... I'm going to wait to post the pcb gerber files, I placed an order that should be here next few days, just to check that everything works as planned then I'll post the pcb files.. (don't really like posting stuff that I'm not 100% sure is working, untill I have the boards in hand)


'************************************************* ***************
' MIBAM TEST pic12F683 / pic12f1822 *
'************************************************* ***************

#IF __PROCESSOR__ = "12F1822"
#MSG "Compililng for 12F1822..."
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#ENDCONFIG
OSCCON = %01110000 '8mhz
TRISA = %00011000 'setup inputs/outputs
'ANSELA = %00010000 'RA4 = analog
ANSELA = %00001000
CM1CON0 = 0 'disable comarators
ADCON0 = %00001101 'Select AN3 enable ADC
ADCON1 = %11010000 'Right Justify - Fosc/16 & 8mhz
BTN var PORTA.3
#ELSE
#if __PROCESSOR__ = "12F683"
#msg "Compiling for 12F683..."
#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
#ENDCONFIG
OSCCON = %01110001 '8mhz
TRISIO = %00011000 'setup inputs/outputs
ANSEL = %01011000 'RA4 = analog
CMCON0 = %00000111 'disable comarators
ADCON0 = %10001101 'Right Justify - Fosc/16 & 8mhz
wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
;wsave VAR BYTE $70 SYSTEM ' alternate save location for W
' if using $70, comment wsave1-3

' --- IF any of these three lines cause an error ?? ------------------------
' Comment them out to fix the problem ----
' -- Which variables are needed, depends on the Chip you are using --
;wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
;wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
;wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
ssave VAR BYTE BANK0 SYSTEM ' location for STATUS register
psave VAR BYTE BANK0 SYSTEM ' location for PCLATH register
' --------------------------------------------------------------------------
disable debug
;---------------------------------------------------------------------------
BTN var GPIO.3
#else
#ERROR "Only 12F1822 & 12F683 are supported!"
#endif
#ENDIF

DEFINE OSC 8 '8mhz

DEFINE DEBUG_REG PORTA 'serial output to get ADC levels
DEFINE DEBUG_BIT 5
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0

BAM_COUNT CON 3 ; How many BAM Pins are used?
INCLUDE "MIBAM.pbp" ; Mirror Image BAM module

RED VAR BYTE
GRN VAR BYTE
BLU VAR BYTE

adc_val var word 'adc value variable
adc_last var word 'previous adc value
adc_thresh var word 'adc trigger threshold variable
adc_delta var word 'change in adc/value
Mode var byte 'currently selected effect mode
x var byte 'just a byte

ASM
BAM_LIST macro ; Define PIN's to use for BAM
BAM_PIN (PORTA,0, BLU) ; and the associated Duty variables
BAM_PIN (PORTA,1, RED)
BAM_PIN (PORTA,2, GRN)
endm
BAM_INIT BAM_LIST ; Initialize the Pins
ENDASM

Speed CON 5 'led fade speed
adc_thresh = 20 'trigger threshold (adjust to change sensitivity)
red = 0
blu = 0
grn = 0
MODE = 0


'------------------------ MAIN PROGRAM LOOP ------------------------
main:

if btn = 0 then 'check mode button
mode = mode + 1
pause 400
if btn = 0 then 'check to see if press/hold mode button (reset)
pause 2000 'reset if modules get out of sync on modes.
GIE = 1 'press mode button > 2.5 sec
for x = 1 to 5
red = 50
pause 40
red = 0
pause 40
next x
GIE = 0
red = 0
mode = 0
endif
if mode > 4 then
mode = 0
endif
endif


pause 30
gosub do_adc 'get ADC reading
gosub get_delta 'calculate delta since last reading
'debug "ADC: ", dec4 adc_Val, "--> ",dec4 adc_last," D: ", dec3 adc_delta,13,10

if adc_delta > adc_thresh then 'trigger effect if threshold exceded
GIE = 1
select case mode
case 0
gosub fadeR

case 1
gosub fadeG

case 2
gosub fadeB

case 3
gosub sparkle

case 4
gosub flash

end select

GIE = 0
pause 30
gosub do_adc
gosub get_delta
endif

goto main

'------------------------- SUBROUTINES ---------------------------------------

Do_Adc: 'sample ADC pin
adc_last = adc_val
pauseus 50
ADCON0.1=1
WHILE ADCON0.1 : WEND
adc_val.highbyte = ADRESH
adc_val.lowbyte = ADRESL
return

Get_Delta:
if adc_last = adc_val then
adc_delta = 0
return
else
if adc_last > adc_val then
adc_delta = adc_last - adc_val
else
adc_delta = adc_val - adc_last
endif
endif
return


'------------------- EFFECTS SECTION ------------------------

fadeB:
FOR BLU = 255 to 1 STEP -1
PAUSE Speed
NEXT BLu
blu = 0
return

fadeG:
FOR grn = 255 to 1 STEP -1
PAUSE Speed
NEXT grn
grn = 0
return

fadeR:
FOR red = 255 to 1 STEP -1
PAUSE Speed
NEXT red
red = 0
return


sparkle:
for x = 255 to 1 step -10
red = x
BLU = x
pause 30
red = 0
BLU = 0
pause 30
next x
return

flash:
red = 255
grn = 255
blu = 255
pause 30
red = 0
grn = 0
blu = 0
pause 30
return




I've tested the code on both 12F683 and 12F1822, works great, don't forget to grab the latest version of MIBAM in this thread above! thanks again Darrel!.

I'll post more pictures and video once I get the modules... stay tuned..

alesniak
- 16th September 2011, 07:56
took a little while (day job gets in the way!) but here's what I ended up with..
still have to finish my table assembly but the building blocks are nearly done
I have hand assembled about 120 modules, they still need some wiring but
all work like my original video above.

front and back of the module, each is 1"x1" square
http://www.andylesniak.com/iactled/iactled_pic1.jpg

a small pile of assembled modules, smt assembly really goes quickly, using a toaster to reflow the pcb's. only wish I had a pick & place machine.
http://www.andylesniak.com/iactled/iactled_pic3.jpg

cnc'd some frosted acrylic to make individual tiles, which will become the tabletop..
http://www.andylesniak.com/iactled/iactled_pic2.jpg

alesniak
- 16th September 2011, 07:57
here's a modified schematic, this doesn't reflect the pcb's in the pictures above
it's been changed a little adding a diode for reverse polarity protection, and removing a few pins from the design which didn't work as I expected.

http://www.andylesniak.com/iactled/iactled_sch.jpg



that's it for now, I plan on posting a full buildlog once it's all done, I will post a link when it's done most likely a few weeks... :)

Ioannis
- 16th September 2011, 08:05
I wonder where can I get the solder paste for SMD. Can you post a link please?

Very nice pcb and project in general. 5* for the whole!

Ioannis

mackrackit
- 16th September 2011, 13:59
http://search.digikey.com/scripts/DkSearch/dksus.dll?Cat=1310838&chp=0&FV=fff40014,fffc013b

(http://search.digikey.com/scripts/DkSearch/dksus.dll?Cat=1310838&chp=0&FV=fff40014,fffc013b) For small amounts

Heckler
- 16th September 2011, 15:30
WOW! Alesniak, thats awesom.

Any possibility that others could order PCB's from the same source you used and not have to re-submit the pcb design?

good work

alesniak
- 17th September 2011, 06:45
here's the solder paste >>LINK (http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=KE1507-ND)<< I've used for a while... think I've had one tube for about 2 years... keep it in a fridge seems to work well..

also use laser cut mylar pcb stencils to apply the paste, makes it really easy, and quick when you have 100+ pcb's....

As for the pcb design, I didn't post the one I ran above since I wanted to change the design a bit, originally I was thinking of using my
remaining pin, pin 5, to send a delayed pulse out to trigger adjacent modules, didn't really think it through, since if I had a dedicated input pin
it would of worked, but being out of pins I ended up using the same pin I had the phototransistor input on, in doing so, when you chain a row
of modules together when you trigger a module every other one instantly triggers instead of the delayed wave effect I was looking to get..

I only did a run of 1x 155" sq panel from goldenphoenix, so I've used up all my modules, but I plan on doing a bigger batch since I've had people
interested, I'll post some more details once I have my next design ready, it's going to be much much better (I hope) , with some cool effects that
have adjacent modules sending out triggers to each other, making a fluid like effect possible...

that said if anyone wants the files I used to get the above pcb's made send me a PM and I'll gladly send'em over to ya....





(http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=KE1507-ND)