Huh, that's funny, I copy pasted that from MCS on my computer, and it works splendidly with MCLRE_ON, I can reset MCLRE on the programmer using the little check box and that works too.<br>
Glad Dave got you going !
Huh, that's funny, I copy pasted that from MCS on my computer, and it works splendidly with MCLRE_ON, I can reset MCLRE on the programmer using the little check box and that works too.<br>
Glad Dave got you going !
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Just got hit with the next 'gotcha'!
I was trying to get an LED to light up when the button on my low pin count was pressed - just spent ages trying to figure out why the LED wouldn't light. A check with my voltmeter revealed no matter code I tried, RA3 was always held low, a bit of Googling revealed this...
http://www.microchip.com/forums/tm.aspx?m=270347
F: Pushbutton doesn't work with Low Pin Count (LPC) or 28-Pin Demo Boards
The pushbutton cannot be used on these demo boards when debugging or programming and powering them from the MPLAB IDE. The pushbutton switch is connected to the input pin that is shared with the nMCLR/VPP pin. When Debugging, this pin must be used as nMCLR and cannot be used as an input pin. When programming and leaving the PICkit 2 connected to the Demo Board to power it, the MPLAB IDE always maintains a valid output state on a programmer's nMCLR/VPP pin which prevents the switch from changing the signal value. Use the PICkit 2 Programmer software to allow the switch to be used.
It seems I now have to assemble, & then fire up PICKit 2 to wrtie the hex to the PIC (button works as it should then).
Mindboggling for a beginner like me, ie that there should be so many 'enviromental' hurdles to get over, when all I want is to learn the most simple of code!
Last edited by HankMcSpank; - 15th March 2009 at 10:03.
I will suggest you pick up a cheap bread board or two and a hand full of LEDs, resistors, caps etc. The demo boards are nice I guess, but you can not do a whole lot with them other than what they were designed to do.
As far as the coil winding project goes. A switch on a cam or some other part will work. Every revolution the switch is "bumped" from low to high. Every time the switch is bumped a variable is incremented.
If it is not running real fast interrupts will not be needed.
That is the basics. Add a serial or LCD to display the value. AddCode:LOOP: IF SWITCH = 1 THEN WRAP = WRAP + 1 GOTO LOOP
IF WRAP = X THEN GOTO STOP ???
Let us know...
Dave
Always wear safety glasses while programming.
Whilst I was sold on the concept of the ease of use of the Microchip low pin count board, (esp to get me some simple quick & dirty IO) I'm now very rapidly seeing the shortcomings!
As it goes I have, breadboard & plenty of components...I'll be using all that in earnest, once I've nailed the basics here (no pun intended).
Re the coil winder. I'm using an old DC cooling fan with a drill chuck hot glued to its centre ( http://img25.imageshack.us/img25/2717/workshopjd8.jpg - ugly but fulfills a need!)....this drill chuck will hold the 'solenoid core' while to copper wire is wound onto it. On this fan will be 7 or so magnets, each in turn closing a magnetic reed switch as the motor turns (I'd imagine the maximum speed the fan will be turning at for this project will be about 200RPM I've made a simple PWM circuit to control the speed of the fan).
Where the PIC comes into the equation, is that it will count the pulses from the fan motor. For every 'X' pulses it receives from fan motor's reed switch, the PIC will send one short pulse onwards to a UCN5804 stepper motor IC. It's essentially a pulse counter/divider ...for ever x pulses received, output one pulse.
The UCN5804 feeds a small stepper motor - on its shaft is a bit of threaded nylon rod - it's over this threaded rod that the copper wire feeds onto the solenoid core (this youtube video illustrates what I'm trying to achieve well - (from about 27 seconds in).
The whole point of this is to have my wire neatly wound onto the solenoid. Since I know the diameter of the copper wire (0.15mm), & I know the pitch of the nylon rod's thread feeding the wire (1mm), it's just a fairly simple calculation. therefore for every turn of the main DC fan, I need the stepper motor threaded rod traverse the wire 0.15mm. It's a 7.5deg stepper, therefore each step of the 1mm pitch threaded rod will traverse the copper wire 0.0208mm, therefore to move the wire 0.15mm, some 7.2 steps needed are to the stepper for every turn of the main fan (since there's no such thing as 0.2 of a pulse I'll be rounding it down to 7!)
To nail this project I need to...
1. Sort out all the idiosyncracies of getting my PIC programming enviroment set up for the PIC16F690 - check! (thanks to here!)
2. Lean how to set a PIC output pin high - check!
3. Learn how to check a PIC input pin (to see if a switch has closed) - check!
4. Learn how to setup a few 'count' variables, get them incrementing (& check 'em)....acting whenever the counts have been met - still to do!
5. Learn how to output a pulse - still to do.
I'll also need to figure out some form of debounce (I may end up using a monostable chip to do this)
Thanks for your suggestion on how to approach this...I'll have a play with your lines to see if I can get the switch on my low pin count board to act as the reed switch & one of the LEDs as the stepper chip feed....ie after 7 presses of the board's button, make an LED turn on.
Last edited by HankMcSpank; - 15th March 2009 at 13:51.
do the debounce in software. (short pause) or if it's off to do something else once triggered, you may not even need debounce..
you can search for debounce examples from here http://www.picbasic.co.uk/forum/showthread.php?t=4751
Ok, a bit more reading .... it seems the button command will be perfect for needs.
My initial problem is that it only acts on PORTB pins (& the Pickit 2 board has its switch wired to RA3). therefore I've rigged up a pull up resistor onto pin RB7 & a small switch which goes to ground (therefore puts 0V onto RB7 when this new switch pressed). However RB7 is being held low all the time.
I'm figuring this must be something to do with the .inc file again (I've rechecked my wiring - it's fine ...10k resistor between RB7 & the 5V rail....and a normally open switch going from RB7 to ground). I chose RB7 for my new switch as it seemed to have the least happening! On the datasheet it's listed as RB7/TX/CK ...how can I be sure it's being used as an input pin only (& not being overridden by one ithe pins other purposes)
Does anyone have any ideas why my RB7 might be permanently low.
Here's the small bit of code I'm using...
@MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON
@MyConfig = MyConfig & _MCLRE_OFF & _BOR_OFF
@ __config MyConfig
DEFINE OSC 4
ANSEL=0 ' all digital
ANSELH=0 ' analog module disabled
CM1CON0=0 ' dunno what this line does!
CM2CON0=0 ' nor this one!
TRISA=%11111111 ; set all Port A pins as inputs
TRISB=%11111111 ; set all Port B pins as inputs
TRISC=%00000000 ; set all Port C pins as outputs
B0 VAR BYTE ;creates a variable as needed for the button command below
B0 = 0 ; give it a value of zero (as per the command's reference)
LED1 var PortC.0 ' ; assign a more usable name to the first LED port
start:
LOW LED1 ; turn the first LED off
BUTTON 7, 0, 255, 0, B0, 1, Loop ; monitor the switch on RB7 for 0V,
;if this condition is net, then go to next
next:
high LED1 ; turn the first LED on
PAUSE 1000 ; wait one second
goto start ;start over
End
Last edited by HankMcSpank; - 16th March 2009 at 00:39.
BUTTON 7, 0, 255, 0, B0, 1, Loop
???????
Try
BUTTON PORTB.7, 0, 255, 0, B0, 1, Loop
Or better yet
OOPS!!!!!!Code:IF PORTB.7 = 0 THEN GOTO NEXT
That will not work...NEXT is a reserved word. Will have to think of something else to call that label.. FRED??
Dave
Always wear safety glasses while programming.
Bookmarks