PDA

View Full Version : Which chip do i use?



The Master
- 26th November 2007, 09:54
Hi. I need a PIC chip that can output software PWM to 24 pins, on/off to 3 pins and have serial in/out. It needs to have at least 2 bytes of EEPROM. It needs to use an external oscillator.

Can anyone tell me which chip would best suit me or even better how do i figure it out myself? Is there a list somewhere that will allow me to select the features i want and run a search?

Jumper
- 26th November 2007, 10:36
Hi,

Most PIC:s can do what you have asked for as long as they have enough PORTs availible.

Do you plan to make a small, big or huge program ?
Are you going to make one or one millions units (is price per unit a big factor)?
What will the future look like (USB or anything more special)?

A first choice would be 16F887 since it is cheap, has a reasonable big program space, internal EE-prom, UART and is pincompatible with other pics such as 18F4620 (for later emergency upgrades using the same footprint).

The 18F series will give you more speed (40 MHz compared to 20) and much more program memory compared to 16F887.

You didn't say if the PWM is running contantly or not. Maybe the need for speed is more important than price per unit.

Just to make sure:

I am talking about the 16F887 (eight eight seven), not the 877 or 877A which are the older chips doing more or less the same thing.

/me

The Master
- 26th November 2007, 12:42
I was looking at a PIC16F874. It seemed to be alright but i wasnt sure about it.

Ive changed the 24 outputs to 16 outputs now to save money on triacs and waterproof sockets (i cant believe how much these cost!).

the PWM could be running constantly. Its to control bulbs (with fading) and it will be possible to fade some bulbs out and hold them at a certain brightness for a while.

Something i forgot to mention is interrupts. I know i need at least 1 interrupt pin. From reading a few datasheets it seems that most chips have 1 pin EG "RB0/INT" but some say you can use RB4-7 as interrupts too. Whats the difference between RB0 and RB4-7?

Im not sure how big the program will be. Im hoping pretty small. It will simply accept commands from serial then either use that data to set brightness levels for the bulbs or return a value from the EEPROM (the boxes address).

I take it and "I/O" pin is any input or output pin (excluding OSC in/out unless the OSC pins work as like RA4 aswell)

So i think i now need 23 I/O pins
(16) Software PWM outputs
(1) Serial in
(1) Serial out
(3) Multicolor LED
(1) Button
(1) Zero-crossing interrupt

23 + (2 OSC) + MCLR + VCC + VSS = 28 pins

Ive just had a quick search and found PIC16F882. Would that work?

mister_e
- 26th November 2007, 13:13
if you interface AC, PWM will be useless anyways, you'll need to use a Interrupt to detect the zero crossing and play with your output delays within your ISR.

Your main program may assign delay to your output.

Probably also doable to do everything in a tight loop.. but i tend to say it could be a killer situation.

The Master
- 26th November 2007, 13:21
Whats ISR mean?

I have an idea of how i can write this code in a few simple lines but i dont know how to use interrupts at all. I assume i have 2 interrupts. If one of them goes low then that is the zero-crossing and the code will goto the PWM area. If the second interrupt pin (serial) changes then do i run serin toget the data or wouldnt that work?

2 main things i need to know at the moment.
Which chip do i need?
How do i detect interrupts?

BTW. Im buying all my parts from http://www.rapidonline.com so it would be nice if i could get the chip from there. I dont think that last one i found is available from them.

Edit: Do the PIC codes mean anything? Like 16F = 20 pin, 18F = 40 pin etc. Or do they just increment with each new chip?

mister_e
- 26th November 2007, 13:24
ISR: Interrupt Service Routine : It's the code area used when an interrupt happen.

Begin with ON INTERRUPT and/or Darrel's Instant interrupts.

The Master
- 26th November 2007, 13:34
Ive just googled it and based on this satement "Once you try this, you may never use ON INTERRUPT again." I think i should just use Darrel's Instant Interrupts. Ill have a read and see what i can come up with. Thanx

Jumper
- 26th November 2007, 13:41
Hi,

I hope you have downloaded the pdf datasheet for the 16F882. There you can see that this PIC belongs to a family of PICs starting with the 882 and ending with the 887. There is a table showing the memory size and partnumber/number of pins for these pics.

INT0 is the only external interupt source for the 882-887 family and the rest of PORTB has interupt on change support. This means that you can set up the INT0 pin to generate an interupt when this pin goes either high or low (set in SW).
The rest of PORTB has interupt on change mening it will generate an interupt if any of these pins (that has this function activated) changes state. And then you have to figure out which pin did what and why...

There is a big table for this too under CPU special features.... interupts :-)

The microchip webpage has the price for the 882 at USD 1.20 and the 887 USD 1.84. This can be the best spent 64 cents in your entire life :-). Or you can choose a 884 (still basically the same chip for USD 1.64) since this is a 40-pin package and then keeping the options for plugging in a 18F when you run out of speed and program memory)

Probably you have forgotten a few pins in your idea that you will "remember" later and making a design using a 28-pin device and planning to use more or less all pins is hmmmmm not that smart :-) (unless you really know what you are doing like Melanie and her friends).
Maybe a LCD... some more buttons..... smoke detection..... automatic fire extinguishing.... you get the idea.... things tend to grow with time and some projects newer really finish.


But if I were you I would:

Download the datasheet for the 16F882 (same datasheet as for 883 884 886 887)
Check if they are supported by PBP (if not memorize which are for later use)
Not choose a 28 pin PIC since it will kill the future plans and leave no room for misstakes
Choose a 40-pin PIC (884 or 887 if we only look at this family) unless price and pcb size is really important)


The 884 is 20 cents cheaper then the 887 but you only get half as much program memory.

Of course these prices might be different from what you pay in the stores but it will at least give us a chance to compare apples and bananas.

In the end it all comes down to what can be found in your local hardware store or what can be salvaged from previous projects.

A start is always a good start!



/me

The Master
- 26th November 2007, 13:52
Hmm. Ill start off with interrupts. IVe been reading this incredibly long thread (http://www.picbasic.co.uk/forum/showthread.php?t=3251) and i think im starting to understand how it works but i do have a question about it. In one of the posts he says "And, all of this is happening behind the scenes of your normal PBP program." Does that mean for me that i can have serin wait for data (with no timeout) *AND* still have the PWM stuff running at the same time? (Meaning i only need 1 interrupt pin)

I understand how the other interrupt pins work now. Bit annoying but maybe i dont need them anyway.

I do always look at the datasheets for chips but i dont completely understand them.

If i have forgotten any pins then its bad anyway. I can do breadboard testing but once i make this thing it has to work first time. Space is an issue. Im trying to cram so much into such a small box.

How do i tell if it supports PBP?

The Master
- 26th November 2007, 16:43
Right. Ive just connected a PIC up and checked that its working. Now im trying out the hello world (http://darreltaylor.com/DT_INTS-14/hello.html) example. Ive pasted the code in from that page exactly but i get 3 errors when i try to compile

ERROR: Variable wsave3 position request 416 beyond RAM_END 79.
ERROR: Variable wsave2 position request 288 beyond RAM_END 79.
ERROR: Variable wsave1 position request 160 beyond RAM_END 79.

I dont understand what they mean or how to fix them. Im testing on a PIC16F84A. I have set the chip correctly in PBP this time :P and ive downloaded the 14 bit version of the interrupt code (for 12F-16F)

The Master
- 26th November 2007, 16:52
Ive just loaded the bas file up and theres some comments saying i can comment out the lines that are causing a problem. Ive done that and now theres another error.

Error PBPIC14.LIB 1141 : [255] undefined symbol 'int_entry'

The Master
- 26th November 2007, 17:41
Aha! Ive just read a whole thread of people having digs at each other but in the end i found out that its because i havnt got MPASM turned on. Ive enabled it and got the program to compile. It did give me 2 warnings though.

Warning[211] c:\picbas~1\pwmtes~1.asm 227 : Extraneous arguments on the line.
Warning[211] c:\picbas~1\pwmtes~1.asm 227 : Expected (ENDIF)

I assume that 211 is the error code and 227 is the line. If that is correct then this error is on line 169 of the origional "DT_INTS-14" file. The line says "End If". I think this is because .bas files open with VB and for some reason it added the space in. The origional file doesnt have the space. So, ive copied the origional file back out of the zip, commented out those 3 lines again and now its giving me another error :(

Error[113] c:\picbasic\pbppic14.lib 1141 : Symbol not previously defined (INT_ENTRY)

Ive tried deleting all the files generated for DT_INTS-14 (like the asm file etc). Ive hit compile again and yet another error.

Error[113] c:\picbas~1\pwmtes~1.asm 115 :Symbol not previously defined (PIR1)

Now im stuck. Does anyone have any suggestions?

mackrackit
- 26th November 2007, 19:06
Maybe you should try and learn regular interrupts before going for the big guns Darrel gave us.

You said that you do not understand interrupts. Search the forum for Olympic Timer or real time clock. Paul B has a good example too. Once you work through these you should have a good understanding of the behind the PBP and using an interrupt pin is not much different.
The above mentioned threads:
http://www.picbasic.co.uk/forum/showthread.php?t=632&highlight=olympic+timer

http://www.picbasic.co.uk/forum/showthread.php?t=2129

The Master
- 26th November 2007, 19:26
Ok. Ill have a read through them. I thought the thing Darrel made was to make interrupts easier.

Can someone give me a bit of info on the pins used please. I can read those threads tomoz but i need to get the PCB designed ASAP. Do i need the zero-crossing diodes going to RB0/INT and the serial input go to just another normal I/O pin?

Is there a chip suited to this circuit? I see what Jumper was saying about having a 40 pin chip but space is tight and i wont need to expand on this project. If i have missed anything then ill find it when im designing the PCB.

If the worst happens and i cant learn interrupts fast enough then i can still use the circuit without PWM but the hardware has to be right. I can reprogram the chip but i cant remake the PCB

The Master
- 26th November 2007, 20:49
Heh. Ive decided to use a PIC16F877A, I already have a few of them laying around so i can run some tests without buying new parts. I would like to use a chip which has the right amount of ports for the job but i dont know how to find one properly. Ive used these chips before though (just not with PWM). Does anyone have any comments about it? Is it a good/bad choice? Anything i have to be carefull of when using it?

I had a thread the other day because i couldnt use one of these chips but i found the breadboard i was using and i had connected the resonator to the wrong pins! haha. Tested today and it is running a test pattern fine :D

tenaja
- 26th November 2007, 21:02
Ok. Ill have a read through them. I thought the thing Darrel made was to make interrupts easier.
Actually, what he made was to make interrupts more "real-time." It doesn't make PBP interrupts themselves easier, it makes "hardware" interrupts easier.

An interrupt is a hardware bit in the PIC (there are typically quite a few) that is set when a certain condition occurs. (Here are a few examples: when an a/d conversion is done; when a timer overflows; when a certain i/o pin changes state, when serial data arrives.) When one of these bits gets set, the code stops executing at its current position, and temporarily goes to the assigned interrupt code.

Now here's the part that describes why Darrel's code is helpful:

A "software" interrupt is BASIC-speak for checking the interrupt flags after each basic command. If a flag is set, then the code essentially gosubs to the interrupt code. This is the standard way to do interrupts within PBP. It's not a true interrups, but this is a "safe" way to do it, because none of the temporary hidden system variables are overwritten during an interrupt. (These system variables are used within the compiler commands, and are invisible to you unless you look at the compiled code.) This is an easy way to do it if you don't need 100% perfect timing.

A "hardware" interrupt is also BASIC-speak for a "real" interrupt. Instead of checking the flags, it relies on the hardware to do the interrupt if you have the Global or Peripheral Interrupts Enabled. That is, if you set the flags properly, then within a clock cycle or two, the code jumps to the interrupt handler. This is nice because the timing is instant, accurate, and precise. However, if you are in the middle of a BASIC command (or math operator), and you also use that command within your interrupt, then when it returns to where it was previously, the values could be corrupt. This is why Darrell put together his code routines... so it can save the hidden system variables, go through the interrupt, restore the system variables and return without losing any information in the process.

I'm sure this will help you understand a lot more. Basically, if you need precision--such as audio pwm--then you want to use the hardware interrupts. If you are doing something where the timing is much more casual--such as charging a battery--then you might as well use the s/w interrupts; they are easier to implement.

The Master
- 26th November 2007, 21:22
Hmm. Im making lights dim. I would say the timing is pretty important on that and the hardware interrupt looks like it would work best.

What i want is serin2 to wait to serial data forever (or until it gets some data).

If RB0/INT goes low then i want to run a sub.

Does what you said mean that the data coming in from serin2 could be currupted?

Im not really sure what to do now. Ive been reading through those 2 links but they arnt making much sense to me and i cant relate them to what im doing

tenaja
- 26th November 2007, 21:30
Hmm. Im making lights dim. I would say the timing is pretty important on that and the hardware interrupt looks like it would work best.

What i want is serin2 to wait to serial data forever (or until it gets some data).

If RB0/INT goes low then i want to run a sub.

Does what you said mean that the data coming in from serin2 could be currupted?

Im not really sure what to do now. Ive been reading through those 2 links but they arnt making much sense to me and i cant relate them to what im doing
You can't use serin2 and hardware interrupts at the same time. The serin2 command is a software loop watching for the pin to toggle. If you interrupt out of that, then you lose bits or bytes. If you must watch RB0, then you also must use the hardware usart with a hserin command.

If you are using RB0 as an interrupt, then you could use a loop to watch for the uart buffer to be full. Using the usart gives you the advantage of a 1.9 byte buffer. I say 1.9 because you get one full byte, plus however long it takes to receive another byte and move it there before its overwritten.

You really should get a development board and play with the serial inputs and the interrupts to see how it works. If you don't do that, then you'll be depending on the board to write your code.

The Master
- 26th November 2007, 21:38
I dont want anyone to write all my code for me but a few examples would be nice.

So, I cant use serin2 like i normally would. The rest of that bit is a bit confusing. Are you saying that i should have a main loop that keeps an eye on serial data coming in and when it reaches a certain length then deal with it however i would if it had just come from serin2? Then in the background i should have RB0 interrupt the code and run the PWM sequence?

Im sorry im not getting it. There must be a few ppl sat at home shouting at their PCs "I cant believe he still doesnt understand!!!" lol. I have a feeling that eventually something will click and suddenly it will all seem really simple

mackrackit
- 26th November 2007, 22:32
"regular" interrupts will see the event happen be it an internal timer or change on a pin. Then it waits until the program is finished doing what ever then goes to the interrupt routine. This is the timing issue spoke of. That is where the clock programs come in for an explanation, there is only so much time between interrupt events.

If the program is in the middle of a serial command and an interrupt flag is set, the interrupt will not run until the serial routine is finished.

Here is a recent thread where an interrupt is being worked out.
http://www.picbasic.co.uk/forum/showthread.php?t=7490

mister_e
- 26th November 2007, 23:03
When dealing with interrupts and critical stuff... you don't want to use anything else than a REAL USART. Select a PIC with a EUSART/USART, use it and forget SERIN/SERIN2/DEBUG.

Darrel Taylor
- 27th November 2007, 04:52
I knew my ears were burning for some reason today. :)


Hi. I need a PIC chip that can output software PWM to 24 pins, on/off to 3 pins and have serial in/out.
Don't want much, Do you? :eek:

Let's see, you want 24 software PWM's, plus + ...
Maybe we can just make it a moot point by determining your PWM resolution requirement.

1. What frequency PWM do you need?
2. What resolution? 4, 8, 10 bit ?

The reason I ask can be found here ...
http://darreltaylor.com/DT_INTS-14/SPWM.html
In particular, read how many Interrupts/Instructions per second it takes to accomplish software PWM.

I would guess that the reason you had problems with Instant Interrupts previously Today, is because you were using a 16F84A.
Kind of like running windows on an original IBM PC. (you might get it working, but it'll suck)

Switch to at least the 16F877, but I'll bet you're going to need an 18F.

.

Darrel Taylor
- 27th November 2007, 06:02
Oh, and if that makes it sound impossible to you?

Here's something else to ponder.
It's just that, Nobody's written it yet. :(

http://www.picbasic.co.uk/forum/showthread.php?p=45597

.

The Master
- 27th November 2007, 06:12
Darrel. I changed the design yesterday. I only need 16 PWM pins now. Someone made some circuits for me years ago that do exactly what im trying to do now and they work perfect. They only used smaller chips i think PIC16F84's. The person who made them lost the origional code in a format and i hardly ever see him online now. I guess he wasnt using your code though. Ive swapped to a PIC16F877A now. I hope that will do better.

Im not sure about the frequency/resolution. I want a brightness control that is 0-100%. Here in the UK we have 50Hz which means 100 zero-crossings per second so i think for 100 brightness levels i should split each half cycle into 100. That should mean for a brightness level of 50% i wait 5ms before turning the output on. Im not sure how this would work though because 1% would be 100ns but isnt that faster than the chip can handle?
Im sure im going about this bit the wrong way too.

I checked the datasheet for PIC16F877A and it says it has USART So that should be ok.

mackrackit. Its all becoming clear now. Im about to read through that thread now but i think i understand how it should work.

Random thought. I can upload the .HEX file from one of the chips i have already doing this kind of thing with 8 PWM outputs. I dont know if anyone can do anything with it. Maby decompile to assembly?

The Master
- 27th November 2007, 06:53
Just read through that thread and the PDF in it. I only understood some of it through. Im using triacs so i cant use bi-phase angle modulation. Phase angle modulation is what i was thinking of. Turn an output on at a set point durin the half cycle and let the triac turn itself off at the next zero-crossing. I dont think the drawbacks of that method will affect me because im not using LEDs. I got completely lost at BAM.

The idea i had would work like this



interruptpoint: 'This is where it goes on interrupt from the zero-crossing pin RB0
if brightness(0)=100 then
high porta.0
endif
if brightness(1)=100 then
high porta.1
endif
.........
pause (100th of a cycle)
if brightness(0)=99 then
high porta.0
endif
......
'by now it should be right at the end of the half cycle
'set the pins to low so the triacs dont all come back on in the next half cycle
low porta.0
low porta.1
resume

Obviously i wouldnt type out hundreds of if statements, i would use a loop instead but thats what i was thinking of. It looks a little slow though :(

I know ive got to learn serial now without using serin2.
Which interrupt method do i need? (or which one should i start learning?)

Darrel Taylor
- 27th November 2007, 06:59
Should I also guess that the serial is comming in at 250kbaud?
There are 512 frames, at ~40hz.
A.K.A. ... DMX

.

The Master
- 27th November 2007, 07:01
I was going to use 9600n. Thats what everything else uses including the origional boxes my mate made

EDIT: The plan wasnt to use these as DMX lights but how hard would that be? IVe got a DMX controller and i think its faster than anything ive done using the serial port (My DMX box is USB>DMX)

The Master
- 27th November 2007, 07:19
Hehe. Ive had a quick google of DMX in PBP and it sent me to this thread (http://www.picbasic.co.uk/forum/showthread.php?t=61). BTW, the person who made my origional boxes is electronicsuk (Matt).

After reading that thread im not sure about DMX. I looked at assembler once then quickly made a break for the exit

Darrel Taylor
- 27th November 2007, 07:20
... The plan wasnt to use these as DMX lights but how hard would that be?

Very!

Got paid to do it once.
Came up with 1 18F as the front end receiving the DMX.
And any number of slaves (8 per PIC).
Up to 512 channels total. (lots of slaves, kinky)

Unfortunately, it was for LED's (high powered one's, but still LED's)
It'll be harder for A/C dimmers.

.

The Master
- 27th November 2007, 07:43
DMX is out then! I dont want this to be any harder than it already is.

Ive just been reading some of Matt's threads. I can see a few references to the boxes he made for me. Just to add, those boxes are still working perfect after something like 3 or 4 years. Nice job!

Anyways. I cant seem to find much in those threads about the bits im stuck on. There is 1 thing that can be learned from them tho. Dont rivet triacs to anything! I had to replace one once without getting to the solder side of the PCB.

This thread (http://www.picbasic.co.uk/forum/showthread.php?t=7) or more specificly the last post is quite interesting. Can someone tell me if the following is correct.
There is a receive flag. Possibly whatever PBP uses as a boolean value. When serial data arrives at the chip this flag is set to true.

RCREG returns the first byte from the serial buffer and removes it from the buffer. If this causes the buffer to be empty (that was the last byte) then the RX flag is set to false.

I take it this uses the hardware UART thing to add data to a buffer (with no code)

The Master
- 27th November 2007, 08:29
Ive just found another thread (http://www.picbasic.co.uk/forum/archive/index.php/t-2452.html) with sample code of using UART and interrupts. It looks simple enough so im gonna test it out when i get back home (stupid work, ruining my day :P)

The Master
- 27th November 2007, 09:37
Ive had a go at writing some code. This is just for the serial part. The idea is that if the chip gets chr(255) then it sets the next 16 bytes to the brightness levels (Later to be used to control the triacs).



datapos var byte
newbyte var byte
brightness var byte [15]

trisc=%11111111
spbrg=129
rcsta=%10010000

datapos=16

loop:
if pir1.5=1 then
newbyte=rcreg
if newbyte=255 then
datapos=0
else
if datapos!=16 then
brightness(datapos)=newbyte
datapos=datapos+1
endif
endif
endif
goto loop


I do have a few questions about it though. Can this only be used on a pin labeled RX? For this chip the pin labeled RX is RC7.

An example i have says "RCSTA = %10010000 ' Enable serial port and continuous receive". What are we setting here? Are we telling it which pin is being used or is it just a standard value that means "on"?

Is my code any good or should i scrap it and start again? :P

The Master
- 27th November 2007, 17:18
Ive just tried out Darrel's code again now im on this new chip and it compiled first time without me having to edit anything :D I used it to monitor the falling edge and i connected 2 diodes up. I did a quick test...



ToggleLED1:
pause 5
high PORTd.7
pause 1
low PORTd.7


And the bulb lights up at half brightness :D WOO! Im just having a read through "Multiple Software PWM". Then ill have to figure out how to add serial to it but it looks like i can use his code for that too

The Master
- 27th November 2007, 17:43
Ive written some test code using DT's example



INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

resolution var byte
x var byte

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT_INT ; enable external (INT) interrupts

Main:
for resolution=0 to 100
pause 1
next
for resolution=100 to 0 step -1
pause 1
next
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
for x=100 to 1 step -1
if resolution=x then
high portd.7
endif
pauseus 150
next
low portd.7
@ INT_RETURN


It works perfectly except the bulb fades out half way then pauses slightly then fades out completely. It also fades as its coming back in. Does anyone know why that is and how to fix it?

The Master
- 28th November 2007, 06:06
I think ive been looking at this the wrong way round. Ive had the multimeter on one of the boxes Matt made (8 triacs are riveted to the side so i cant see under the PCB). From what i can see the interrupt pin isnt connected at all. I think he has a main loop which just waits for a certain pin to go low (for the zero-crossing) then executes the bit to control how bright everything is. As for the serial input i think that is where the interrupt comes in. Either that or there is no interrupt at all and he checks that in the main loop too. Now its starting to sound simple :D

For now im gonna use the same chips Matt used and see if i can make his circuit work on a breadboard. Then i can copy the hex code to the new chips. That gives me 8 outputs so ill need 2 chips per circuit but they are cheaper than 1 big one.

1 thing i find weird about his circuit is that MCLR doesnt appear to be connected to anything :S

Jumper
- 28th November 2007, 10:43
Hi,

Reverse engineering is not my favorite game so do not expect any more help from me again.

Need any more help? Ask Matt!

/me

The Master
- 28th November 2007, 11:20
I would ask Matt but hes never online anymore. Hes always busy.

From what ive learned in this thread and looking at the top of his PCB i think i can see how and why he has connected certain things up. Im gonna get hold of a 16MHz resonator and borrow one of the chips from the boxes. If i can get one of the origional chips to work then i could simply copy the code but i have an idea of how he programmed it too so i can also experiment with that.

Whats wrong with reverse engineering anyway? I tend to learn best by seeing a finished product then looking at all the bits in it to see how it works. It also leads to me question why it has been done in such a way. Like why does Matt appear to have used a method that nobody has mentioned here?

mackrackit
- 28th November 2007, 18:25
Like why does Matt appear to have used a method that nobody has mentioned here?

You would have to ask him. There are many ways to do the same thing. Is one better than the other, who knows. This thread was not started about why some one did a project a certain way. It was about which chip would work. Then it went on to interrupts.

As far as reverse engineering.

Using it to lean is one thing but to duplicate a product is on the verge of stealing.
If the product is open source that is something else.
Want to build a device that works like one made by someone else, fine. Use your own ideas and you will get help on how to make them work. Want it to be exactly like the one made by another, buy one from them.

The Master
- 28th November 2007, 20:47
I dont want it to be exactly the same. Thats why im putting so much effort into learning this. Im doing loads of tests on Matts box now and theres a few things i still dont get but im getting there. Just about to try some code out (stuff i invented myself). But im gonna put it on one of the boxes Matt made. I know the box works perfect so i can test my code better. Once i get my code working then it will help me understand the circuit better.

I dont want to "copy" Matts design. I want to figure out how he did it then do it in my own way

mackrackit
- 28th November 2007, 21:04
OK

Some chips have an internal MCLR , I like these for ICSP.

Let us know how you code works out and where you need help from there.

The Master
- 28th November 2007, 21:23
Im stuck already. You knew it wouldnt be long :P

Im using a 16MHz oscillator. In my code i have put "define osc 16". The rest of the code simply turns an LED on an off a few times to show the chip is working.

What im getting is a quick flash when it powers up and when it powers down.

I think this might be to do with the fuse settings. What should the following be set to?

WDT
PWRTE
BODEN
LVP
MCLRE (i assume E means external so Matt had this disabled)
Oscillator
Code Protect (i know this should be disabled)

for Oscillator i have the following options to choose from
ERCLK
ERIO
IRCCLK
IRCIO
EXTCLK
LP
XT
HS

The other options are enabled/disabled.

BTW. Do you want me to start new threads for any questions about this or stick to this one? Its all the same project

Edit: Im using a PIC16F627 (http://ww1.microchip.com/downloads/en/DeviceDoc/40300C.pdf)

mackrackit
- 28th November 2007, 21:45
MCLRE is just the name.
For internal (Not used for reset but the pins other functions) the fuse should be
_MCLRE_OFF

HS for the OSC

The Master
- 28th November 2007, 22:02
Woo it works :D Its a bit fast though. i put 100ms pauses in and it flashes a lot faster than when i use a 4MHz resonator. I know 16MHz is 4 times faster but i thought the point of declaring that was so "pause 100" would still take 100ms and not 25. Maby ive got something else wrong. I was reading about timers in the datasheet. I didnt understand any of it but part of it could mean the chip runs 4 times faster than the resonator you use.

It doesnt matter anyway. If i want 100ms then i just type 400. The point is the LED flashes. Tomoz ill get onto the real code but its 10:00 now so i should be getting to bed. Up at 4:30AM for work :(

Anyways. Thanx for that. I would have been lost trying to figure it out myself

mackrackit
- 28th November 2007, 22:07
Where are you setting the fuses? In the *.inc file or in the code.

A programmer never sleeps. When things get fuzzy is when some of the best work is done:D

The Master
- 28th November 2007, 22:15
Im setting the fuses in the programmer software right after loading the file. How do you do it in PBP? Its annoying having to keep setting them.

Also, Serial doesnt appear to be working. This is probs to do with the same problem but how do i figure out what value to give to spbrg? I found this page (http://www.piclist.com/techref/microchip/spbrgcalc.asp) but im not sure what it all means. I entered 16 and it gives me a table. How do i know what BRGH is set to?

Edit: Just downloaded a calculator from Mister_e's website. It makes more sense but its still not working. I think ill go sleep on it ;)

The Master
- 28th November 2007, 22:36
Solved the oscillator problem.

"DEFINE osc 16" doesnt work
"DEFINE OSC 16" does work

Serial still not working but i have a feeling thats something simple.

Ive tried 2 things from Mister-e's calculator


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 9600 Baud @ 16MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically



RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 25 ' 9600 Baud @ 16MHz, 0.16%


I have also added this code


loop:
if pir1.5=1 then
newbyte=rcreg
high portb.0
pause 100
low portb.0
endif
goto loop


when any serial data comes in that should make the LED flash but its not doing. I think this might be to do with the circuit itself (currently thinking outside of the box. Using breadboard instead). Ill try and solve that tomoz. For now though i really am going to bed :P Ill let you know how it goes tomoz

mister_e
- 29th November 2007, 13:56
if you don't use any HSERIN/HSEROUT you use the second methode, unless you use the DEFINE method.

this one work here


@ __CONFIG _HS_OSC & _LVP_OFF
DEFINE OSC 20

PORTB=0
TRISB = %00000010
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 129 ' 9600 Baud @ 20MHz, 0.16%

PIE1.5 = 1 ' Enable USART interrupt


start:
if PIR1.5 = 1 THEN ' RCIF FULL?
PORTB.0=1
PAUSE 200
PORTB.0=0
WHILE PIR1.5
TXREG=RCREG ' send it back to the pc
' utill USART buffer is empty
wend

if RCSTA.1=1 THEN ' ANY Overrun?
RCSTA.4=0 ' YES clear it
RCSTA.4=1 '
ENDIF

endif

goto start

just change DEFINE OSC, TXSTA and SPBRG to suite your requirement. Make sure you have a RS232 inverter (MAX232 or else) between your PC and your PIC.

And YES the DEFINE's have to be in capital letter, unless it will never work.

The Master
- 29th November 2007, 16:19
Thanx for the code. Just a few questions on it. "@ __CONFIG _HS_OSC & _LVP_OFF" causes an error.

Why do i need an "RS232 inverter"? Serial works fine through serin2. I think Matt did use one because theres some extra stuff on the serial input but i wasnt sure what it was for. It appears to be an optoisolator and a diode

The Master
- 29th November 2007, 17:53
Im finally getting somewhere with it. Ive got it to recognise when serial data is being sent and ive got it to fade the bulb out using the sync with the zero crossing. There is still a problem that remains. The serial data that comes in is being currupted. I have a feeling this is to do with that RS232 inverter you mentioned.

Ive seen examples on the net saying serin2 can use inverted and non-inverted serial. Can i use non-inverted here too? At the moment i have a 100K resistor from VSS to RX and a 330ohm resistor from the serial port to RX. That is how i normally do it and it works with serin2.

I used your code example to echo the input back to the PC. I sent it numbers from 1 to 100 but it replied with completely diff numbers. They appear to be random but they arnt because if i send the same value twice i get the same value back twice.

I think im so close now. PWM is working and i can program the chip to make the lights fade out :D Its just sorting this last serial problem out and hopefully i can start work on the real program

mister_e
- 29th November 2007, 19:20
The PIC USART use TRUE mode, and there's no way to use INVERTED mode for that PIC, hence why you need a max232 or transistor or else inverter.... also why you have strange results on your PC when you echo the data.


st a few questions on it. "@ __CONFIG _HS_OSC & _LVP_OFF" causes an error.


You must use MPASM to use this line, or change it to PM requirement. Even if you're using MPASM, it may return an error (overwriting previous address plah plah).

Have a look at the following for more info about Configuration Fuses.

Presetting Configuration Fuses (PIC Defines) into your Program

http://www.picbasic.co.uk/forum/showthread.php?t=543

The Master
- 29th November 2007, 19:28
Yes. That overwrite thing was the error i got. I have got MPASM turned on. I thought it didnt like it.

What is the cheapest option for the 232 inverter? Ive had a look for max232 in rapid and they range from a few pence to a few pounds but i dont completely understand which type i need. I have a single serial input that must go to 2 PIC chips.

Matt used a MOC8102 but rapid dont sell those. Once i know what i need for this im gonna order the parts straight away. Im sure everything else is sorted. Just the serial to go.

Ive connected a wire from Matts box into the pic so i can use his circuit for the serial while im testing so i can get on and program the chip. I do have a small question about the program. Its still fading in upto about 40% then 40-60% are all the same brightness and 60-100% work as expected. Do i just alter the timings to compensate?

The Master
- 29th November 2007, 21:18
Wow. This thing runs so fast :D I managed to send commands from the PC so fast that i almost managed PWM (it was flickery tho cos the PC isnt sync'd)

Ive got a good idea of the code that im gonna write now so ill sort that tomoz. I just need to know about the serial inverter now and i can get the parts ordered and finish designing the PCB

The Master
- 30th November 2007, 06:24
I found a diagram (http://www.best-microcontroller-projects.com/image-files/pic-serial-port-490.png) on the net. Ive modified it to how i think it should be for my circuit. (See attachment).

Is that diagram correct?
Which chip do i use? :P (back to that question) I think its one of the chips on this page (http://www.rapidonline.com/productinfo.aspx?tier1=Electronic+Components&tier2=Integrated+Circuits&tier3=Line+Drivers+%26+Receivers&tier4=RS232+Line+driver%2freceivers&moduleno=67368). Im not completely sure but the one that looks right to me is the "MAX232CPE+ CMOS DUAL RS232TRANS/RCV RC" Order code: 82-0148.
And for the caps, will this one (http://www.rapidonline.com/productinfo.aspx?kw=11-0855&tier1=Electronic+Components&tier2=Capacitors&tier3=Radial+Electrolytic&tier4=Microminiature+85%26deg%3bC+electrolytic++ca pacitors&moduleno=62531) do? The diagram says 1u 16V and that one is 50V but i dont think that matters

The Master
- 30th November 2007, 10:14
I have ordered a MAX232CPE RS-232 Transmitter/Receiver (http://www.maplin.co.uk/Search.aspx?criteria=MAX232CPE%20RS-232%20Transmitter/Receiver&source=15&SD=Y) from Maplin. (Its free so why not).

I will hold onto my main order a little longer though incase you say i need something else.

mister_e
- 30th November 2007, 14:16
MAX232 is what you need, you could still use a simple transistor/mosfet as inverter. for short distance that's good enough. Here's one of the various transistor solution available over the net
http://www.piclist.com/techref/io/serial/ttl2rs232.htm

The ICSP diagram might work or not depending of your programmer, Microchip have an ICSP guide
http://ww1.microchip.com/downloads/en/DeviceDoc/30277d.pdf

there's also the usual Melabs schematic bellow:
http://www.melabs.com/images/icsp1.gif
http://www.melabs.com/support/icsp.htm

The Master
- 30th November 2007, 16:27
I dont need ICSP. Im hoping i wont need to reprogram anything once there up and running. I do plan to use it in the future though and my programmer board does have a socket for it

That thing i found in Maplin, is it not right? Its a MAX232 but i dunno what CPE means

mister_e
- 30th November 2007, 22:46
MAX232CPE, CSE,CWE, C/D WHATEVER, it's all good. Just open the datasheet and it's state what the letters mean...
http://pdfserv.maxim-ic.com/en/ds/1798.pdf

from one one brand to another, the letters meaning might change.

The Master
- 30th November 2007, 22:54
I have been looking at the datasheet but i couldnt find where it said anything about those letters. 2 of those are on the way so ill go and order the rest of my components and finish the PCB design off.

Thanx so much for all your help. I might need a little help with the code but i think i know what im doing. Just a few issues i should be able to figure out.

Edit: Found it. I didnt see the one right infront of me at the top but the one with the actual information in that i need is right at the bottom (like it says at the top. I didnt see that bit). I dont like PDF files. They load slow and take ages to scroll and ive only just found out they have a search function

mister_e
- 30th November 2007, 23:04
EDIT: :D ok!

The Master
- 30th November 2007, 23:08
I guess you were typing that while i was editing my previous message. I was looking for it so hard that i didnt see it. The lack of a search function didnt help either but ive found how to work that now.

I do have trouble understanding some datasheets. This one was a bit obvious but a lot of things arnt. Not to me anyway. They should have shown us how to read them as school

Edit: HAHA

mister_e
- 30th November 2007, 23:54
mmm yeah, that's really annoying, at school they only teach you how to read. But they never go further : how to read recipe, datasheet, instruction manual, etc etc. Teachers really need to go back to school themself prior to teach :rolleyes:

pst.. i'm dj as well.

The Master
- 1st December 2007, 00:28
Yeah. Ive heard. Dont you play house or trance or something? I started with that then moved to hardcore. I dont mix much now tho cos ive started gettin into Jpop. I should get my decks out around x-mas and have a bit of a mix

mister_e
- 1st December 2007, 00:37
at the nightclub i work, i play almost everything (70's to now), but my real speciality when i do some 'after-hour' party or 'rave events (if we can still use that name)' is more hard/Happy/electro/afrikan house, tribal, techno, even GOA style is still good enough :D I stoped to play trance awhile back.. just because there's too much people out-there playing it

You know... the real stuff... No Rihanna, no commercial stuff and of course... NO F*** hip-hop bullsh*t

Anyways, if you plan to go on this side of the world, let me know, that would be cool to have a jam together :D

Regular gear:
DJM-600 (planning to move on DJM-800 soon)
EFX-500
3X CDJ-1000 MK3
3X SL-1200 MK2
and recently Serato Scratch live .. just to add some pleasure to work...

The Master
- 1st December 2007, 01:16
I would like to mix in clubs but its hard gettin that first gig. Ive played at a few small raves and 1 small nightclub but nothing has come of it. I practiced for about 2 hours a day for well over a year till i could mix quite well. Now i hardly mix at all. I do play gabber sometimes aswell. Ive got a gabber set on www.happyhardcore.com called White Noise. I really should mix another set for them.

And my equipment:-
Behringer DJX600 mixer
2 X Technics SL1200 GLD Gold decks
A double crappy CD player that only half works (I dont care. I never play CDs)
2 X 400W Carlsbro speakers
2 X 600W Carlsbro bass speakers

Edit: I need a new mixer. I can get a bit overexcited with the faders and some dont work now

Ive got a disco too. I dont do proper mixing for that, i just let a PC play the music. I used to use CDs but i had so many problems with scratched discs and dodgy lasers so i moved to a PC. It also allows me to make sure everything is working fine. The lighting PC crashed once because of a slight programming error. Woops. Im working on some new lights at the moment. IVe got the PCBs done and programmed but i might modify them to support fading now i know how.

Ill upload some pics if i can find them :P

mister_e
- 1st December 2007, 01:28
Serato Scratch Live works pretty well 'till now... I heard of another software ... but i just don't remind it's name. I NEVER trust ANY PC-Based stuff for live performance... EVEN i don't trust ANY CDs... why i always carry my vinyls...

23 years of DJ experience... and i have 34 :eek:

New Mixer... i only suggest Pioneer ones.. they're really nice and tough... a bit expensive but they never ever fail. When a fader fail 50-80$ is all you need to replace one and it's good for few years of hard work... be sure... they really have hard times with me :D so 1 year with me.. is about ten with others :D

The Master
- 1st December 2007, 01:29
Here we go. The last 4 were what my mate took and they look a bit blury. I had some better ones but i cant find them anywhere. Pic 1 is in my room, Pic 2 is a wallpaper my mate made for me and the rest are from my 18th birthday. Ill see if i can locate any newer pics. That was 2 years ago, theres almost twice as many lights now

http://www.spooktech.org/BLG/PicAlbum.php?ID=1&Page=&AlbumID=1&APage=1

The Master
- 1st December 2007, 01:30
Serato Scratch Live works pretty well 'till now... I heard of another software ... but i just don't remind it's name. I NEVER trust ANY PC-Based stuff for live performance... EVEN i don't trust ANY CDs... why i always carry my vinyls...

23 years of DJ experience... and i have 34 :eek:

I use winamp for discos. I never use anything but vinyl for proper mixin tho. Not even CDs.

34 vinyls? I was collecting for about 2 years and i have over 500. I dont sell mine tho :P

mister_e
- 1st December 2007, 01:38
nah.. i'm 34 years old...and i have exactly 47,481 vinyls(33 rpm + 45 rpm) of all style + few thousand original CDs.

NO WAY i will sell them... too much 'souvenirs' in that.

PS: nice pictures.. the last one looks like a Pioneer CDJ-100 cd... i still have a pair of it here... but no longer use it. The dual CD 'looks like' a Stanton one.. not sure of it. I already worked with one 1 night.. and at the end of the night... i throw it away with a baseball bat.. pure c r a p !

SORRY ALL FORUM MEMBER... we are really out of topic ;)

The Master
- 1st December 2007, 01:51
Wow. I should start collecting again :P Trouble is that i got all the tunes i really wanted. Now im spending upto 25,000 yen a time on Jpop. I like the vinyls i have though. Most ppl will carry on buying the new tunes so ill be playin diff stuff to everyone else.

I cant sell my vinyls. So many are worth loads. I got one for £5 thats now worth at least £50. I got a vinyl from Scott Brown for £6. They pressed the wrong track on the other side and realised after making 500 of them so thats rare. Ive got tonnes of white labels too. I used to buy all the new stuff as it came out. I do have 3 vinyls that i should sell. 2 i accidentally got twice and one i thought was a good track but it was a rubbish one with the same name :( The rest im keepin tho :D

I was after some dubplates from Wonter. He said he could get good quality ones but i never got them :( They were good tracks too

Im not sure what mixer i was looking at. Probs pioneer. It was almost identical to my current one but black and it has better FX

Anyways. Ill chat tomoz if you want. Its almost 2:00AM here now and ive been up since 4:30AM. Half my brain is shutting down cos its too tired and the other half got fried while i was messing with my circuit. Speaking of which i have ordered the rest of the parts now. Was only about £150. Each box costs £30 but then theres the wire and other expensive rubbish. Gotta modify 10 sets of fairy lights tomoz. Im gonna make them into 1 double length 5 chanel set

Edit: The twin CD thing is the one thats broken. Its prosound. The other CD players are what UFO brought with him

mackrackit
- 1st December 2007, 01:59
SORRY ALL FORUM MEMBER... we are really out of topic

I am finding it very interesting!

Reminds me of how I got started in electronics, building audio amps.

mister_e
- 1st December 2007, 02:01
prosound... mmm, never saw that brand over here... i thought it was that one (stanton S-550)
http://www.instrumentpro.com/image.php?src=/Merchant2/graphics/00000001/s550.gif&PHPSESSID=0616e16f5eeb96b365f4c5d30cdee39a

but... yeah looking closer, it doesn't look the same...

nomad
- 1st December 2007, 08:20
i find it all interesting too. pulled out my voice of buddha goa cd.

The Master
- 1st December 2007, 10:39
LOL. I suppose its not too bad because it is in the off topic forum anyway.

I had to pack my decks away because i didnt have enough room what with new disco lights and a pinball machine etc. Ive got 1 whole table covered in components now from the x-mas circuit. I love electronics but i hate tidying up.

My mate DJ Robbie D should be coming back from spain for a few weeks soon so ill have to get my stuff out again and arrange a party.

BTW. Those CD players are very similar. They do almost exactly the same thing but mine are the cheap ones. The backlights have already blown so i replaced them with LEDs now one side wont load CDs and the display on the other side goes weird so i cant use either. I thought about buying new ones but i dont need them really. Any CDs i get i just rip to media center.

Do you make any of your own tunes or do you just play them? I had a few tries but it takes so long to get it right

Edit: Might have to get back to you about those audio amps. Im gonna need one for the next pinball machine i make

The Master
- 1st December 2007, 18:53
I have a small question about the MAX232 chip. In that diagram i posted 2 of the caps appear to be the wrong way round. The ones to +V and -V. Is that right?

mister_e
- 1st December 2007, 23:49
they're really goes like bellow
http://www.mecanique.co.uk/code-studio/loader/reset-circuit.gif

for your CD, don't worry, usually you just need to change the laser pick-up. I'll bet on those regular KSS-213C which can be found in many Denon, Numark ones... one of my supplier have a deal 'till january.. 10 CAN$ each :eek:

Yes i do my own remix/mashup and do my own creation with ACID 6 and tons of VST's. Recently bought a Novation Remote 37 SL MIDI controller... that's a really nice one... the automap feature is really a must for time saving. Pretty nice controller with lots of control, faders and encoder.

One day i may share some ... still thinking....

Talking about buddha... not close yet, but i already used that VST in few of my Lo-Fi and Tribal tunes...
http://www.kvraudio.com/get/226.html

have a look at YouTube, some already post their stuff using it... really nice VST and fun to watch. Sounds is clear/neat and crispy... can't believe it's free!

The Master
- 2nd December 2007, 00:13
Right. Looking at that diagram the caps appear to be correct but now im wondering about those chips. They are dual chips so can i use a single chip to give a single serial input to 2 PIC chips like in the diagram i uploaded before?

tenaja
- 2nd December 2007, 22:23
For modern-day RS232, I use the FTDI chips. The new 232R accepts the PIC outputs at whatever voltage it's running, regardless of the polarity it's running at (you don't need voltage inverters or level shifters, be it software uart or hardware). It takes very few components to get it to the PC, and, best of all, it's a USB chip so it'll work with any modern PC.

The Master
- 2nd December 2007, 22:28
That sounds good. I am looking to move to USB eventually. The only problem i have is that each device would require a USB port. I was thinking about a distribution box though. Something that connects by USB to the PC but uses serial to connect to the lights