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
how make square wave?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: how make square wave?
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.
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.
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;
}
Code: Select all
trisb = 0xFE;
asm
{
Loop:
incf portb, 1
goto Loop
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: how make square wave?
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
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
Martin
- STibor
- Posts: 263
- Joined: Fri Dec 16, 2011 3:20 pm
- Has thanked: 116 times
- Been thanked: 113 times
- Contact:
Re: how make square wave?
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.
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.