Generating a stable frequency ???

OLDmarty

Senior Member
Hi All,

I'm looking to replace a bunch of old legacy timers/oscillators with (hopefully) a single picaxe.

So, my question is, what's the best way to generate 1 or several frequencies from a single picaxe chip? (if possible)

FYI:
The current (legacy) oscillators are a mix of 555 timers and some ttl logic, there are various signals such as 300hz, 10khz and 500khz which then feed into an array of logic & control.

I imagine i probably wouldn't use something like the pulsout command due to some timing/looping issues???, so i figure i might just use simple commands such as "high" and low" on the chosen output pin with suitable pauses in between to create a balanced mark-space ratio.
Naturally the clock cycles in the "hi-low" loop would also need to be factored into the timing/frequency output required.

I'm certain to get 1 pin operating correctly, but trying to get 3 or 4 pins all outputting differing freq's might be the big challenge.???

Has anyone done anything like this before?
Any pointers or snippets i can learn from would be most appreciated.

Thanx in advance,
Marty.
 

erco

Senior Member
555 and 556 timers are very stable, reliable and bulletproof, is there that much to be gained that it warrants the mod to digital ? A 558 quad timer would save space.
 
Last edited:

Dippy

Moderator
Don't forget the 'overhead' time with interpreted commands.
The higher the frequency the more you'll struggle.
And what are the accuracy/stabilty requirements?
A crystal clocked PICAXE could give a very good PWM out as it's all internal hardware and dividers.
For lower frequencies you might strike lucky with software/interrupt division if you play with the code.

But do note that because of the dividers the PWM doesn't always give you exact frequencies; it can be a mix of clock and division.
The higher the frequency then the higher the possibility of not getting a precise PWMOUT value.

I'd stick to hardware as suggested.
Perhaps, if your current system has a 555 'master' clock plus dividers you could use PWMout plus dividers?
That could certainly be better than a 555/6.
Sadly, my old PIC MultiCalc has conked out so I can't give a quick PWM answer.;(
 

geoff07

Senior Member
Assuming that you can tolerate the imperfections of Picaxe timing (command overheads etc), and assuming that the frequencies can be calculated as per below, one way would be:

- identify the highest common multiple frequency.
- define the others in terms of no of cycles of the highest freq per cycle of each freq
- generate the highest freq, and count cycles, generating the required transition per each of the other freqs based on the cycle count

so if the highest freq is 500kHz (which might be a challenge, see below) and you also want 10kHz, then toggle the 10kHz pin every 25 cycles of the highest freq

BUT, 500kHz would need a chip running very quickly, say at 32 or 64MHz as you are toggling the pin at 1MHz and then have to build in all the tests and the counting.

Once working, you could tune the numbers of cycles for each freq to allow for overheads, assuming you have access to a counter for calibration.
 

srnet

Senior Member
I'm looking to replace a bunch of old legacy timers/oscillators with (hopefully) a single picaxe.
So why ?

Whats the problem with the current setup ?

You might percieve a problem, but unless we know what that problem is, constructive advice is difficult.
 

manuka

Senior Member
OLDmarty:Yes - why the need to change? I've an "oldie but goodie" LF sig . gene here that still cuts the mustard nicely for casual work. PICAXE oscillators are temperature sensitive of course-is accuracy important ?

Guess you know about the advent of free smart phone based virtual instruments ? For impromptu AF sig. gene needs the knob twiddler friendly Pro Audio Tone Generator (PA Tone) is considered one of the best. Stan.
 

Attachments

OLDmarty

Senior Member
Thanx So far guys, appreciate it greatly.

I knew it wouldn't be so easy, and some timing loops/instruction cycles would be the issue with creating a stable-continuous chain of clock cycles at the desired frequency.

The aim to upgrade came from a request to re-design some control boards for a friends factory, however 1/2 the gear (too expensive to replace) is running some ancient legacy technologies.
The clock frequencies i mentioned need to be maintained for the older equipment that MUST stay in place for now, while some of the other (partially redundant) controllers/equipmetn can be changed at a moments notice.
There's some bridging between the 2 technologies in the factory, and those clock signals co-exist across both old & new gear.

Most of the gear being removed hold the clock-gen circuits, and the existing gear wont work without them, so my aim was to simply build new clock-gens.
So, in an effort to try and wipeout a load of old boards and 1/2 redundant boards, and replace everything with modern/minimal tech i aimed to try and generate those clocks from a picaxe....

I realise 3 signals in one picaxe might be a problem with the inherent delays/loops being used. At this stage i'd settle to use 3x "08M's" to individually generate the 3 desired clock signals.


The clocks required aren't really sychronous to anything, nor are they deeply accurate, so a 10khz clock that stumbles and drops a cycle now & then might not be such an issue.
I think the downstream cpu's just need to see a constant heartbeat/reference to ensure operation.


Yes, i could build a modern/cleaner version of 555/556/558 but i'd like to try and move away from old-tech and stay in the future..

At this point i could equally just do it all in FPGA, although a bit overkill for such a small application....I guess part of the aim was to see if a picaxe could at least "do it", even if just 1 constant frequency.



I often find projects that require some form of fixed clock source, so this problem won't go away, and i'd really like to make a picaxe solution.


Thanx again for suggestions so far.
Marty.
 

Goeytex

Senior Member
I don't have a 28X2, But a 20X2 operating at 4MHz is pretty much dead on with PWM at 500Khz.

Here's what I got for the three frequencies mentioned using a 20X2 @ 4Mhz. Measurements were done using Saleae Logic with a 24mhz sample rate.

Code:
500Khz:  
     pwmout C.5, 1, 4
     Mark 1us : Space 1us
     Actual:  500KHz

10KHz:
     pwmout C.5, 99, 200
     Mark = 50us  or 49.9583 us
     Space =50us or 49.9583 us
     Actual 10.00KHz - 10.00417KHz  ( very slight Jitter)
 
300Hz:    
       pwmout pwmdiv16, C.5, 207, 417
       Mark   =   1667.0417us   to   1669.583 us        
       Space =   1658.8750us   to   1659.1250us
       Actual =   300.5974 Hz to 300.6469 Hz   (Very slight Jitter)
It may be relevant to note that even though some Picaxe chips have 4 PWMs, as far as I can recall, there can only be three unique frequencies. Since PWM runs in the background, it would be easy enough to do the 300Hz frequency using a loop with high/Low & pause/pauseus

Also, to reduce jitter, the disablebod and disconnect commands were placed at the beginning of the code

I don't get the discouraging advise here. Seems fine to me unless ultra precise accuracy is needed. And it would be a good learning experience.

Further experimentation shows that to get an "accurate" 300Hz in a high/low loop, the Picaxe needs to run at 32 Mhz.

Here's the sample code for 299.89 Hz using a 20X2. Values will be different for M2 Picaxe

Code:
#picaxe 20X2
#no_Table
setfreq m32

[COLOR="#008000"]'// These reduce jitter on Pwm[/COLOR]
disablebod    
disconnect      [COLOR="#008000"] '// Will need to "hard reset" to Program the Picaxe  [/COLOR]

pwmout C.5, 15, 32   [COLOR="#008000"] '// 500Khz[/COLOR]
 
'// 300Hz loop
do                       
   
   toggle c.1      [COLOR="#008000"] '// Use toggle to have a balanced mark/space[/COLOR]
   pauseus 584
   
loop
 
Last edited:

Circuit

Senior Member
I don't get the discouraging advise here. Seems fine to me unless ultra precise accuracy is needed. And it would be a good learning experience.
[/code]
Goeytex, how wonderful to see your ever positive, encouraging and constructive advice back on the forum. I do hope that this indicates a positive upturn in your health.
Once again I have tucked away a note in OneNote from your advice; this time it is a reminder to reduce the jitter on PWM by disabling brownout and disconnecting.
Best regards always.
 

srnet

Senior Member
Yes, i could build a modern/cleaner version of 555/556/558 but i'd like to try and move away from old-tech and stay in the future.
Is there a problem with the old 555 system that it needs improving ?

I would be surprised if a micro based system would more reliable (than the 555 approach) although it would be more modern.
 

Goeytex

Senior Member
I found a 14M2 so I wrote and tested a little program to demonstrate how to have it generate 4 separate clock signals
The code below should be self -explanatory.

Code:
#PICAXE 14M2
#NO_DATA
#COM 4
SetFreq M32

INIT:

      Disconnect
      Disablebod
      
      [COLOR="#008000"]'pwmout B.2, 1, 4                '// 4Mhz [/COLOR]                             
      [COLOR="#008000"]'pwmout B.2, 3, 7                '// 2MHz  [/COLOR]
      pwmout B.2, 15, 32              [COLOR="#008000"] '// 500KHz [/COLOR]
      pwmout B.4, 210, 421            [COLOR="#008000"] '// 38KHz [/COLOR] 
      pwmout pwmdiv4, C.2, 199, 400   [COLOR="#008000"] '// 10KHz[/COLOR]

MAIN:

      do
            toggle c.0       [COLOR="#008000"] '// 300Hz[/COLOR]
            pauseus 1125
     loop
 

erco

Senior Member
Goeytex to the rescue! A pleasure having you back and watching you work.

FB OM, 73s
 

OLDmarty

Senior Member
Thanx to you Goeytex for the positive & inspiring solution(s) to my enquiry.

Yes, there are far too many nay-sayers (on any forum) these days who have great skills in condemming a post rather than providing some help.
Surely we're all here to learn & share, but the bagging isn't welcomed ANYWHERE!

Human nature i guess?
 

techElder

Well-known member
Wait a minute, OLDmarty. You got some good advice from both sides of the issue. Don't be so quick to condemn good advice. No one in previous posts was anything but sincere in getting information from you and supplying reliable information to you. Even you said, "I knew it wouldn't be so easy ...."

There's not a single post above that could be considered "condemming a post." We get a lot of requests from folks that seem to want to run the whole of the NASA space program with a PICAXE. You received good advice and can take from that what you will.
 

srnet

Senior Member
Indeed so.

One of the problems with posting on public forums is that you might get advice you don't agree with.

Fair enough, but either argue your point or just ignore it.

Denigrating those that gave opinions you just dont agree with as 'nay-sayers' is not appropriate.

You might also want to ponder on why, on a forum where posters are very likley PICAXE enthusiasts, some advice was to consider tried and tested analogue methods for fullfilling the requirement.
 

Goeytex

Senior Member
Hmm,

The original question was:
"...what's the best way to generate 1 or several frequencies from a single picaxe chip? "
Some responders completely ignored the actual question while offering advise to keep the analog stuff, or question the reason for the change. While I know that everyone's intention was to be helpful, I think it can be frustrating for posters when the question is ignored and unsolicited advise is offered instead.

My brother, (the MIT guy) used to do this to me all the time. Ask a clearly stated specific question, and he would begin a dissertation all around the question but never really answer it. It got to the point where I would say "thanks" and simply walk out of a meeting about 2 minutes into the dissertation and leave him talking to the white board. Then I would go ask someone else who would actually listen to the question and answer it directly if possible.

I understand the OP's frustration. He was looking for an answer to a specific question. There was no issue with two sides, only a relatively simple question.

On the other hand, I do not think anyone was condemning the post, just maybe a bit too much dancing around the actual question with well intended advise.
 

OLDmarty

Senior Member
I appreciate advice when it's positive and relative to the direction i aim to head in....

However, When the advice is "why?" or "why not stick with the old gear?" i tend to see those remarks as negative & redundant....
We may as well all drop the picaxe and go back to 555's and logic gates.

I don't see how any advice about staying in the past with legacy gear is helpful when my question about the picaxe/timing was the issue at hand.
I did not ask "should i stay with the old gear", i asked for a possible solution to move forward with modern picaxe solution.

The point of my initial posts was to (hopefully) achieve a move forward by removing some old legacy gear from a factory that still required some signals left in place...
The current boards are almost 3 feet long and 1 foot tall, absolutely ancient & FULL of redundant TTL & analog signalling, thats all been removed and replaced with a modern controller, however the 3 clock signals were the last tether that needed to be resolved.

I thought it could be a really simple picaxe solution, but as i said "it might not be easy" and i was prepared to run 3 independent picaxes if need be.
Based on my previous pic/picaxe experiences with loops and ACCURATE timing, i know there's quite a can'o'worms in getting it right, if at all.

I know 555's are stable & solid, they have/had their place, but why would i want to re-instate them plus their external components when 1 (or 3) naked picaxes would be a streamlined solution.


I will do as some have suggested, and will ignore comments i don't deem worthy to my question(s) ;-)
 

Dippy

Moderator
May I offer a partial explanantion which is not meant to start any form of argument.

We poor old souls on here often see a question which sets out a requirement but we don't have any background.
Why is background needed? Well, sometimes, someone may just want to use a PICAXE just for the sake of it.
That's fair enough in many cases but sometimes a hardware solution may be simpler... and more reliable.

Also, people may like to know the application in order to gently suggest some concerns, caveats or better ways to do the task.
The Old Hacks here don't know anything about you or your application.

Your post#8 put some helpful meat on the bone, followed by Goeytex's suggested solutions.

Answering questions like "why?" shouldn't be too problematic surely?
But if it seems tedious then a stiff upper lip is the best course and, as you say, ignore comments you don't deem worthy.
The questioning was simply to help the responders, as many here a little pushed for time and may have been able to supply a quick response.
 

manuka

Senior Member
I will do as some have suggested, and will ignore comments i don't deem worthy to my question(s) ;-)
Phew-just as well I didn't mention ******* approaches.

I echo Dippy's thoughts. Only at posts #8 & 19 did you mention factory installations & massive board sizes. For all we knew this need was just for your hobby workbench, with your OLDMarty title implying someone from another e-era. You still don't seem to have responded to freq. stability anyway - PICAXEs are prone to temperature drift.

PLEASE consider that "lite" posters eternally frustrate helpers,who may then ask for more detail (or offer blue sky alternatives) to better envisage the problem. Hence put your 555 upgrade query in the context of someone posting "my VW Beetle is still working reliably but it's time for a Nissan Leaf hybrid car"...

Stan. ( 40+ years an educator & long exposed to - & frustrated by- "it's not working-fix it" style queries...)
 

OLDmarty

Senior Member
Yes, i can understand your need for more info, but in my case the extra info doesnt really affect my original question, offering more info doesn't help.

I tend to do post lite and ONLY post the immediate point(s) of enquiry to get to the point of what i need help with.
The initial question asked for a multi-frequency task and if it could be done or not, thats all.
I do not write essays full of padding & garbage that can only confuse the reader as to what i actually want.

I NEVER feel a need to present the WHY as the bigger picture story isn't really relative to my goal.

While my post 8 explained the overhaul of factory equipment, it has absolutely no affect on the responses i was seeking, it's much like me telling you the location of the factory, or it's colour, all completely irrelevant which is why i keep it lite and to the point.
My use for such a project could have been for factory equipment, a nasa space-station, or controlling the hadron collider.....in either case it's all irrelevant to my question just asking if & how the function could be implemented in the picaxe.

I think too many people just ask for more info for the sake of asking for more info.

Marty (more experience than many others, but i dont need to signature-stamp it to prove myself) ;)
 
Top