• AVR Freaks

AnsweredHot!Can i make a very fast squarewave with peripherals ?

Page: 1234 > Showing page 1 of 4
Author
Jan Audio
Super Member
  • Total Posts : 183
  • Reward points : 0
  • Joined: 2018/09/24 08:12:24
  • Location: 0
  • Status: offline
2020/11/14 08:02:39 (permalink)
0

Can i make a very fast squarewave with peripherals ?

Hi, i like to have a very fast squarewave from a pin.
What peripheral should i use ?, i like to use a 8 bit chip.
My chips have CCP, can i use that for 1 clock accuracy ?
Interrupts are to slow to set the pulse, the timer would need to be automaticly reset, how is this possible ?
 
btw : i am using this for a MN3207 BBD delay ic, so i also need the inverted version on another pin without latency.
 
thanks
post edited by Jan Audio - 2020/11/14 08:04:01
#1
Jim Nickerson
User 452
  • Total Posts : 6797
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 08:10:47 (permalink)
+4 (4)
How fast is "very fast" ?
#2
Jim Nickerson
User 452
  • Total Posts : 6797
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 08:11:58 (permalink)
0
Jan Audio
Hi, i like to have a very fast squarewave from a pin.
What peripheral should i use ?, i like to use a 8 bit chip.
My chips have CCP, can i use that for 1 clock accuracy ?
Interrupts are to slow to set the pulse, the timer would need to be automaticly reset, how is this possible ?
 
btw : i am using this for a MN3207 BBD delay ic, so i also need the inverted version on another pin without latency.
 
thanks


And what PIC do you have in mind ?
#3
RISC
Super Member
  • Total Posts : 5793
  • Reward points : 0
  • Status: online
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 08:49:49 (permalink)
+1 (1)
Hi Jan,
there are multiple ways to have 2 outputs which are inverted (CCP units) or even easier using CLC programmable logic peripherals inside the PICs. The CLC units can even be connected to timer outputs so there is no jitter or no SW dependency. Please specify exactly which frequencies you need and also duty cycle if needed.
Regards
 

For support make sure to check first here : http://microchipdeveloper.com
There are hundreds of PIC, AVR, SAM...which one do YOU use ?
#4
Jan Audio
Super Member
  • Total Posts : 183
  • Reward points : 0
  • Joined: 2018/09/24 08:12:24
  • Location: 0
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 08:56:22 (permalink)
-1 (1)
Hi, i like to have it so fast that every frame counts.
It is for a clock, so more accuracy is better.
 
Now i made it many functions for every step :

 
for( ;; )
   {
  PORTA = 0b100000;
  asm( "nop" );
  PORTA = 0b010000;
  asm( "nop" );
  }

 
And alot more functions adding more NOPs.
So i have instruction accuracy now.
 
Only i would like to modulate that value, and have no processing time so i need a peripheral.
 
*Using a 12F1572 at the moment, i also have a 16F1704.
#5
RISC
Super Member
  • Total Posts : 5793
  • Reward points : 0
  • Status: online
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 09:07:30 (permalink)
0
Jan,
Sorry you are not answering the questions so it is difficult to help you.
As I said it is possible to toggle pins WITHOUT any instruction but what is the maximum frequency you need ?
And you say you want/need to modulate. do you need a PWM (change the duty cycle) or you want to change the frequency ? from which frequency min/max and with which resolution (frequency step) ?
Regards

For support make sure to check first here : http://microchipdeveloper.com
There are hundreds of PIC, AVR, SAM...which one do YOU use ?
#6
BroadwellConsultingInc
Super Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2020/06/09 06:07:55
  • Location: 0
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 09:13:48 (permalink)
+2 (2)
You still haven't told us what your frequency needs to be or what your needs to vary the frequency of the signal are.  A quick look at the 16F1704 shows that it does have CLC.  I've not used the CLC before, but it looks to me that you can dump out FOSC on one pin and its complement on another, or HFINTOSC with a complement, or one of the PWM generators with a complement.
 
Note that the code above won't generate a 50% square wave;  The 0b100000 will be shorter than the 0b010000 as there will be time to return to the top of the loop.
#7
BroadwellConsultingInc
Super Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2020/06/09 06:07:55
  • Location: 0
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 09:21:57 (permalink)
+1 (1)
#8
Jan Audio
Super Member
  • Total Posts : 183
  • Reward points : 0
  • Joined: 2018/09/24 08:12:24
  • Location: 0
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 09:29:02 (permalink)
0
200 KHz max.
10 KHz min.
 
Only i wont go down to 10KHz.
Lets say i want every step down from 200KHz, close as possible.
#9
RISC
Super Member
  • Total Posts : 5793
  • Reward points : 0
  • Status: online
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 09:59:49 (permalink) ☄ Helpfulby muhzd 2020/11/14 10:31:14
+5 (5)
Hi,
So if I understand well, what you are looking at is a NCO (Numerically Controlled Oscillator).
Some 8 bits PICs do have this peripheral which might do what you are looking for.
I recommend this article : http://evalspace.com/microchip-nco-numerically-controlled-oscillator/
Regards
 

For support make sure to check first here : http://microchipdeveloper.com
There are hundreds of PIC, AVR, SAM...which one do YOU use ?
#10
muhzd
Super Member
  • Total Posts : 885
  • Reward points : 0
  • Joined: 2008/05/15 10:43:19
  • Location: Malaysia
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 10:50:32 (permalink)
-1 (1)
it's technology driven now or else there is a specific case study or it's demand driven
#11
NorthGuy
Super Member
  • Total Posts : 6405
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 12:17:40 (permalink)
0
Many PICs have CLK out pins. Thisv is FCY. That is probably the fastest.
 
If you use 8-bit PICs, you can produce FOSC/2 using CLCs. <edit> I think FOSC too.
post edited by NorthGuy - 2020/11/14 12:49:40
#12
1and0
Access is Denied
  • Total Posts : 11505
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 12:52:31 (permalink)
0
PWM with PR = 0 runs at Fosc.
#13
crosland
Super Member
  • Total Posts : 2095
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Warks, UK
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 13:23:38 (permalink)
+1 (1)
muhzd
it's technology driven now or else there is a specific case study or it's demand driven

Thank you for that insightful answer to the OPs question. I clearly have a lot to learn from you.
#14
Mysil
Super Member
  • Total Posts : 3951
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 15:28:32 (permalink)
+2 (2)
Hi,
Not All 8 bit PIC have a possibility to select FOSC for 8-bit timer clock.
The usual for 10 bit PWM using CCP in PWM mode with 8 bit timer is FOSC/4. 
This give FOSC/4 resolution for PWM Period time, with Max  frequency 16 MHz on PIC18, with PR = 0;
and give 2 bit PWM duty cycle resolution.
On PIC16, max PWM frequency will be 8 MHz with PR = 0; and 2 bit duty cycle resolution.
 
For such low frequency as 100 kHz, it should be possible to change frequency in 0.625 kHz steps
99.378 kHz, 98.765 kHz, 98.159 kHz ... down to 62.745 kHz.
Then it will be nessesary to change Prescaler setting for lower period frequency.
Finer resolution in PWM frequency could be achieved by changing OSCTUNE register if internal oscillator is used.
 
Most device types have other peripherals that could be used, UART, SPI, Motor control peripherals, 
Reference Clock, NCO frequency synthesizer.
Some possible tricks may have side-effects for other peripherals.
 
Many PIC microcontrollers will have some limitation in how fast an Output Pin drive circuit will work.
This will be somewhere between 20 and 50 MHz maximum depending on device type and the peripheral used.
 
Regards,
    Mysil
 
#15
muhzd
Super Member
  • Total Posts : 885
  • Reward points : 0
  • Joined: 2008/05/15 10:43:19
  • Location: Malaysia
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 20:41:50 (permalink)
0
Perhaps can be neglated but now there are really actual merits to be selecting between writing to full pin registers and using single pin toggle purposes modules. Like different workloads by all internal shift of the processor will generate the heat.
 
Then is what has the hardware and assembler been application cerified for. The datasheet will tell for all callibration options included and for the performance, but I guess in audio applications, it's actually value-got, an interface to the natural earth environment.
#16
ric
Super Member
  • Total Posts : 28967
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/14 23:43:06 (permalink)
0
muhzd
Perhaps can be neglated but now there are really actual merits to be selecting between writing to full pin registers and using single pin toggle purposes modules. Like different workloads by all internal shift of the processor will generate the heat.
 
Then is what has the hardware and assembler been application cerified for. The datasheet will tell for all callibration options included and for the performance, but I guess in audio applications, it's actually value-got, an interface to the natural earth environment.

I guess this is the output from Google translate, as there is very little in there that makes any sense in English.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#17
muhzd
Super Member
  • Total Posts : 885
  • Reward points : 0
  • Joined: 2008/05/15 10:43:19
  • Location: Malaysia
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/15 01:02:50 (permalink)
0
I must be poetic now. Google saves the years to learn in a library. To be embedded in the Google, I hope Microchip datasheet counts. 
#18
muhzd
Super Member
  • Total Posts : 885
  • Reward points : 0
  • Joined: 2008/05/15 10:43:19
  • Location: Malaysia
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/15 01:29:03 (permalink)
0
Hi, i like to have it so fast that every frame counts.
It is for a clock, so more accuracy is better.
 
Now i made it many functions for every step :


 
for( ;; )
   {
  PORTA = 0b100000;
  asm( "nop" );
  PORTA = 0b010000;
  asm( "nop" );
  }



 
And alot more functions adding more NOPs.
So i have instruction accuracy now.
 
Only i would like to modulate that value, and have no processing time so i need a peripheral.
 
*Using a 12F1572 at the moment, i also have a 16F1704.

Parallel ports can give numbers to count.  
post edited by muhzd - 2020/11/15 01:35:17
#19
davea
Super Member
  • Total Posts : 506
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
Re: Can i make a very fast squarewave with peripherals ? 2020/11/15 01:43:12 (permalink)
#20
Page: 1234 > Showing page 1 of 4
Jump to:
© 2020 APG vNext Commercial Version 4.5