Page 1 of 1
how make square wave?
Posted: Thu Sep 04, 2014 1:54 pm
by hertz89
hi
i have pic 16f627a with 4 MHZ internal ....what is the best way to make square wave(0v..5v) with the maximum frequency? i am now working with this :
loop...> (output B0 = 1...>output B0=0) . without delay.
what is the output frequency will be with that?
any other idea to make very high speed frequency with pic16f627a only?
thanks
Re: how make square wave?
Posted: Thu Sep 04, 2014 3:26 pm
by Benj
Hello,
Hard to pinpoint the rate exactly without referring to the generated assembler file but here is an approx guestimate.
4MHz clock = 1Mhz instruction rate
Output icon may take 3-4 instruction cycles
While icon may take a couple of instruction cycles.
So your probably looking at something like 10 instructions so maybe an output frequency of around 100KHz.
You could probably make a slightly tighter loop using a C code icon to forego all of the Flowcode I/O data direction switching etc this might get up to 300Khz or more.
Code: Select all
trisb = 0xFE;
while(1)
{
portb = 0;
portb = 1;
}
Using assembler in a C icon would be the ultimate way of getting the very fastest possible speed. My count is 3 cycles so approx 333.333KHz.
Code: Select all
trisb = 0xFE;
asm
{
Loop:
incf portb, 1
goto Loop
}
Re: how make square wave?
Posted: Thu Sep 04, 2014 3:35 pm
by medelec35
At 4MHz the best way i can think of is use PWM component (output from CCP1 = RB3)
If you set the Period Overflow & prescaler to 1 which should produce 500KHz waveform.
Using component macros:
Enable PWM.
SetDutyCycle10Bit to a duty of 4:
In theory a duty of 4 should produce 100 duty cycle, but on my hardware (16F883 runnning on 4MHz internal osc as not got a 16F627A) I had a duty of 50.2% @ 500KHz
The difference is probably down to the PWM frequency being pushed to the very maximum limit.
Martin
Re: how make square wave?
Posted: Thu Sep 04, 2014 5:17 pm
by hertz89
thanks all....you helped me alot
Re: how make square wave?
Posted: Thu Sep 11, 2014 5:00 am
by STibor
Hi,
If you need to square wave:16F627A internal 4MHz clock.
Configuration settings:
oscillator: CLKOUT INTOSC
and other standard setting.
The CLKOUT output (RA6), Internal oscillator / 4 = 1MHz.This frequency can not be changed.