50Hz inpuls input to output

Satchid

Member
Dear all,

Im in great need of help, and i know that on this forum are great knoleged people.

This is what I need:

Input is always the net-frequency (50Hz) on an "ST" or "TTL if possible" input pin on a 14m2 picaxe. I need an output frequency that is in direct calculated relation with the input pin.

example: input 50Hz and an out of 5Hz.
Or: input 50Hz and an output of 2000Hz

How can I do this with a picaxe.
My relation with programing is only once in a year, so to be able to do this, I need some help.

Thanks,

Willy
 

Satchid

Member
Ok, Its me again, I did a premilemry test in the old logicator and converted it to basic:
'BASIC converted from Logicator for PICAXE flowsheet:
'C:\Users\satchid\Documents\acin pulsout.plf
'Converted on 13/8/2014 at 15:53:09

;Symbols
{
symbol varA = b0
symbol varB = b1
symbol varC = b2
symbol varD = b3
symbol varE = b4
symbol varF = b5
symbol varG = b6
symbol varH = b7
symbol varI = b14
symbol varJ = b15
symbol varK = b16
symbol varL = b17
symbol varM = b18
symbol varN = b19
symbol varO = b20
symbol varP = b21
symbol varQ = b22
symbol varR = b23
symbol varS = b24
symbol varT = b25
symbol timer = time
}


let dirsB = %11111111


main:
setfreq m32 'set highest prequentie
inputtype %0000111100000000 'set Schmitt Trigger input at 5v)
label_4:
if pinC.1 = 1 then label_10 'Decision command
low 1
goto label_4

label_10: let varA = varA + 1 'Inc command
if varA > 10 then label_13 'Compare command
goto label_4

label_13:
let varA = 0 'Expression command
high 1
goto label_4


#no_data 'reduce download time
This time i wanted to divided the incomming frequency by 10.

After it works, i wil do it with "for next" etc to make the program leaner.

Is this valid code? Can enyboddy give me some corrections please.

Thank you,

Willy
 

hippy

Ex-Staff (retired)
It seems you are trying to count input signals and set the output high for every 10 input signals to convert the 50Hz to 5Hz. That would seem to be an appropriate algorithm but there are issues with this implementation -

You increment whenever the input is high, not when the input transitions from low to high. You need to wait until your input has returned low after each increment, before looking for the next high.
 

AllyCat

Senior Member
Hi Willy,

example: input 50Hz and an out of 5Hz.
Or: input 50Hz and an output of 2000Hz
Those two examples generally employ completely different methods of processing.

A 5 Hz output just needs simple division, but the exact code will depend on whether a "pulse" output is adequate, or if you need a symmetrical square wave.

A 2000 Hz output needs some type of frequency multiplication, which generally requires an additional oscillator. The normal method is a "Phase Locked Loop" (PLL) which uses a variable frequency oscillator (e.g. a VCO), a divider chain and a Phase Comparator which compares the output from the divider with the input (reference) frequency. In principle, that can all be emulated with software in a PICaxe, using one of the PWM oscillators. But it might need quite sophisticated code if a "precision" (i.e. totally accurate ratio) output is required.

In the days before digital electronics/processors, it would have been done by creating one or more "harmonics" of the reference frequency and that might also be possible to emulate with PICaxe software at lower frequencies (perhaps up to 1000 Hz).

However, if the input Reference frequency is both fixed and known (e.g. mains frequency), then you may be able to use a simple synchronisation (or triggering) method, for both up and down frequency-shifting.

Cheers, Alan.
 
Last edited:

Satchid

Member
@Hippy:
You increment whenever the input is high, not when the input transitions from low to high. You need to wait until your input has returned low after each increment, before looking for the next high.
Thank you Hippy, I do not understand what you mean with this sentence, could you please be so kind to clarify this?
Thanks,

@Alan
Yes, I see the point, I wil stick with lower than the master frequency for now. Ithink the second option is allso to high fetched for me.
Thank you
 

hippy

Ex-Staff (retired)
Thank you Hippy, I do not understand what you mean with this sentence, could you please be so kind to clarify this?
Probably the best thing to do is to simulate the flowchart then set the digital input for C.1 high.

Note the path the code takes; repeatedly off to the increment, then back round to check the input, and off to increment again.

So instead of increment when high you need -

Wait for high
Increment
If >= 10 Set output, clear incrementing counter
Wait for low
Repeat
 

Satchid

Member
Hippy,
I undestand wat you mean, but have been working on it since, but i am not able to archieve a result. I could not find anithing about wait for comand. only in keybord comands and in infra comands. only, i do not think that that is what you ment.
I tried then to put in a pouse of 19mseconds, to make sure there are no false repeat runs to inkrement the coulter, but it is not comming to a good result.
runs
Here the closest that i could get. The input is a rectified 5 volt 50Hz from a transformer. that works.
let dirsB = %11111111


main:
inputtype %0000111100000000
label_96:
readadc 0,b8 'read A0 into b8
if b8 >= 32 AND b8 <= 200 then label_93 'Analogue command
low 1
pause 19 'Wait command
goto label_96

label_93: let w1 = w1 + 1 'Inc command
if w1 > 2900 then label_120 'Compare command
pause 19 'Wait command
goto label_96

label_120:
let w1 = 0 'Expression command
high 2
goto label_96


#no_data 'reduce download time

Thank you,
Willy
 

hippy

Ex-Staff (retired)
By a "wait for pin to go low" I meant add a decision block for pinC.1=0 such that when the result is No, that decision block is repeated. Add that block after the Increment block.

I am not sure why you have changed from using a digital input in post #2 to an analogue input in post #7.

Added : An attachment is worth a thousand words ...
 

Attachments

Last edited:

lbenson

Senior Member
How does the 50Hz input matter to the output you are trying to produce? What is it that determines whether you output 5Hz or 2000Hz or some other cycle rate?

Is it necessary that you synchronize with some rising pulse on the input or that you stay in some way synchronized with the input? If so, how?

What is the output signal used for? Perhaps there is some other way to accomplish what you want.

How exact does your timing have to be?
 

Satchid

Member
I see now what you mean, how could i not have seen this. of course, i have no experience.



I am not sure why you have changed from using a digital input in post #2 to an analogue input in post #7.



Added : An attachment is worth a thousand words ...
My waveform out of the trafo is just one diode out of 12V and a resistor + a zener diode that is giving me not realy a decent square wave. If i later find it working on the picaxe, then i will go back to the digital input.

But, great thanks to you Hippy.
 
Top