diyAudio

diyAudio (http://www.diyaudio.com/forums/)
-   Parts (http://www.diyaudio.com/forums/parts/)
-   -   Microcontroller Help (http://www.diyaudio.com/forums/parts/128622-microcontroller-help.html)

imix500 24th August 2008 08:22 PM

Microcontroller Help
 
Hello all, first off I've been away from microcontrollers for about 10 years. The last one I played with was the original BS1 Basic Stamp (which I still have).

Heres my application:
I need to rotate a gearmotor with a paddle wheel about 45 degrees a specified number of times several times a day.

The motor control I think I understand and think I can use simple position feedback with a microswitch or opto to tell the MC when it's gone 45 degrees. What I'm not sure of is the event timing. Do I need a MC with a real Time Clock? How difficult would it be to use an lcd along with a few buttons to set the time and desired number of motor moves?
Thanks!

space2000 24th August 2008 11:54 PM

hi,
you can used encoder to detect the angel position and for speed you have to use pwm timing so you can do it slow or fast.
normally its not dificult but if you add more function will be a bit hard. you can used c-to write program. i dont know which mcu u are using may be you can try 16f877

imix500 25th August 2008 01:57 AM

Hi space2000, I should have specified this is going into an existing machine.
The motor is a regular 6v dc "hobby" type. The paddles of the wheel attached to the gearbox are set every 45 degrees. I was thinking of using a micro switch the paddles would hit as they went by to tell the MC how many paddles have gone by.
It seems the BS1 I have might work, but I'm concerned about timing. I'm looking at intervals of about 6 hours. I could use a PAUSE command a number of times to do this, but I get the impression accuracy might suffer after a few cycles.
If I get a BS2, I can connect a RTC to it for more accurate timing.

jakobsladderz 25th August 2008 02:57 AM

If it's running off mains power then you could put an input from the ac secondary of the transformer (use an AC plugpack/wallwart) and count waves. AC power, while not perfectly accurate cycle/cycle, has a very tightly controlled average frequency (lots of clocks depend on it :)). Shouldn't need much more than a zenner and a couple of resistors to condition the signal to suit the micro.

Cheers,
Duncan

imix500 26th August 2008 02:22 AM

2 Attachment(s)
Hmm, that's a really good idea.
Like this?
Forgot to add- this is through a 6.3v transformer of course.

jakobsladderz 26th August 2008 03:31 AM

2 Attachment(s)
I've drawn up a schematic of what I was thinking...


The 1K resistor R2 is there because the voltage on the zenner gets to -0.5v (1 diode drop) relative to ground and some chips don't like negative voltages past a certain current. Adjust value to suit...

Cheers,
Duncan

imix500 27th August 2008 01:11 AM

Hi Duncan, that looks great. So my question is when the zener ceases to conduct every cycle, would the input pin be floating enough to cause random toggles? Should there be a resistor to hold the pin low during this time? Thanks!

jakobsladderz 27th August 2008 05:42 AM

Looking at the diagram I can see there might be an issue, I'd also put a 10k from what's shown as the '-' pin on the transformer (it's ac obviously but you get the picture) and ground to ensure the transformer voltage doesn't float when the diodes aren't conducting.
Most PIC micros have hysteresis on their inputs and should have no trouble but you can also de-noise the signal in software by waiting for the pin to be high (or low) for an amount of time before acknowledging the change of input state (and incrementing your 'clock' counter).

imix500 3rd September 2008 02:49 AM

Ok, so I've got the board connected with the motor and micro switch working.
I need some help with the code.
Since the BS1 can't count, I'm using a FOR...NEXT to set a number of loops controlled by the switch using the BUTTON instruction. It sort of works in that I can see the loop working but the BUTTON command is somehow resetting the FOR...NEXT each time it updates. I think its just a matter of getting things in the right order. Here's the code- Motor is on Pin 0 and the switch is on Pin 7:
Thanks!


SYMBOL btn = 0 ' FOR BUTTON

SYMBOL btnWrk = B4

SYMBOL reps = B2 ' FOR...NEXT loop counter

motor:
HIGH 0
FOR reps = 1 TO 3 ' repeat for 3 button pushes
BUTTON Btn, 7, 1, 255, btnWrk, 0, No_Press
DEBUG "button"
TOGGLE 1
NEXT


timer:
FOR reps = 1 TO 12 ' repeat with Reps = 1,2,3,etc
PAUSE 60000
NEXT
GOTO motor

No_Press:
GOTO motor


All times are GMT. The time now is 02:26 PM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio


Content Relevant URLs by vBSEO 3.3.2