Firstly ....Shane/Joe, thank you for taking the trouble to respond (esp to a basket case of a kludger like me!)
Ok, to your points...
Shane you are right about the temp variablle needing to be set to zero...I didn't post up that bit (my program has a lot of variables going on, but I stripped it back to basics so as not to cloud the issue...but I can see it's caused probs!)
Next....I think you've nailed the issue (my head was fogged last night after realising my program wasn't counting the revs right!)...essentially, my program traps the switch being closed (sort of!), but not the corresponding open. Therefore in reality, my program could see the switch being closed, head off to do some stuff elsewhere in the program, come back to check the switch & by bad luck/timing the next magnet could be passing so it thinks the same (original) magnet is closing the switch. therefore I need to wait for the switch to close, then open, then have my program act.
Joe... re the counter/variable melarkey - remember, I'm very new to this. I've almost certainly done a tutorial somewhwere & simply applied what I learnt there to my program! (I haven't a lot of time to dedicate to being a slick programmer, so I just throw into the program the little bit that I know!). Could you be so kind as to outline the tighter code for that little increment you've honed in on as being a bit 'first lesson at PICBASIC evening class'!). BTW ...I use this magnet/switch 'count' to derive when to send a pulse to a stepper. This stepper I'm sending the pulse to, moves in synchronicity with the main motor, back & forward (the idea being to neatly feed coppoer wire on to the main turning motor). It's really cool on the odd (seemingly fluke) times I've had it working!
Shane... the magnets are actually glued around the circumference of a wooden ring (& this ring itself is glued to the fan blades!). The diameter of this ring is about 10cm (4" if you're still in imperial) which makes for a circumference of 31cm ...the magnets themselves are about 1cm wide & there are 10 of them. So the magnets take up a third of the circumference - meaning a duty cycle of 33%?
Therefore, at a maximum of 350RPM, the magnets will pass by the switch at about 58 times per second. This works out at every 17ms....because of the magnet width, this yields a duty cycle of 33% - therefore the switch will actually be closed for about 5.6ms, every 17ms
Now my head still spins at the thought of building in the debounce aspect, so
with these 'knowns' I have, which would be the best approach to ensure an accurate switch 'closing' count?
(BTW, I'm thinking now that maybe an optical pickup would be a much better solution, as this removes the debounce aspect & I can have more resolution -I will look into this, but for now I'd really like to get the cheap 'n dirty solution working!)






Bookmarks