Searching \ for '[PIC]: 2 oscillators in one pic ?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=oscillator
Search entire site for: '2 oscillators in one pic ?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 2 oscillators in one pic ?'
2002\03\17@153313 by Lasse Madsen

flavicon
face
Hi all

I was wondering if its possible to make 2 oscillators running in one pic at the same time ?
the PIC is a 12C50x with external 4MHz crystal and oscillators should be on 100KHz and 50Hz.

Output on any availble GPIO pin is ok ...
I personally doubt it can be done because i dont think a pic can multitask but maby im wrong (i hope so)

Best regards Lasse Madsen

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2002\03\17@173434 by Dale Botkin

flavicon
face
On Sun, 17 Mar 2002, Lasse Madsen wrote:

> I was wondering if its possible to make 2 oscillators running in one
> pic at the same time ? the PIC is a 12C50x with external 4MHz crystal
> and oscillators should be on 100KHz and 50Hz.

Tall order, you're talking about switching the output pin every 5
instruction cycles for the 100KHz output.  That's simple as long as you
don't need to do anything else!

> I personally doubt it can be done because i dont think a pic can
> multitask but maby im wrong (i hope so)

Making a PIC multitask is relatively easy if it's enough PIC for the job
and it's running fast enough.  I have several that manage to do more than
one thing at a time using interrupts, etc.

A 12C67x can run at 10MHz, which would be a lot easier to work with at 25
instructions per pin flip.  With a 4MHz part I'd use GP0 for the 100kHz
output and GP1 for the 50Hz output.  Connect GP1 to GP3/T0CKI and use that
as an input to TIMER0.  Now you can preload TIMER0 with a value of 6 and
wait for it to overflow to 0, which will tell you it's time to flip the
50Hz pin.

The big gotcha is that you're going to pretty much have to use a R-M-W
operation on the I/O port, which means you'd better be careful abou tthe
hardware.  If there is too much capacitive load on the pins you will
probably have problems trying to do this.  Maybe Scott or Dmitry or Olin
or someone will have a better idea, but this is the best I could come up
with considering my very rusty assembly skills.

This is as good as I could do without spending way too much time on it.
Untested code, YMMV, math may be wrong, etc., etc.  I'm not trying to
write it for you, just point you in the direction in which I *think* you
will be able to solve your problem.  Also, the 100kHz output will not be
completely symmetrical every 1000th cycle when the 50Hz output is flipped.

; Set up TIMER0 with a /4 prescaler and external clock, GP0 and GP1
; outputs, GP3 input, etc.  I'm not going to write all the initialization
; stuff...

start:
       bcf   GPIO,1    ;50Hz pin
       bcf   GPIO,0    ;100KHz pin
       movlw 6
       movwf TIMER0    ;Need to flip 50Hz pin every 1000 loops, so
                       ;use /4 prescaler, load with 6 and wait for
                       ;250 (hex FA) cycles of 100kHz.
       movlw 1
       nop
loop:
       xorwf GPIO,F    ;Flip 100kHz pin
       movf  TIMER0,F  ;Check TIMER0 for overflow
       btfsc STATUS,Z  ;Jump if time to flip 50Hz output
       goto  loop2
       movlw 1         ;Otherwise set up to flip 100kHz again
       xorwf GPIO,F    ;Flip the pin
       nop             ;delay two cycles
       nop
       goto  loop      ;goto takes two more cycles

loop2:
       movlw 3         ;Set up to flip both pins
       xorlw GPIO,F    ;Flip both pins (one cycle late)
       movlw 6         ;Reload TIMER0
       movwf TIMER0
       movlw 1         ;Time to flip 100kHz pin already
       xorwf GPIO,F    ;One cycle early to make up for lost time
       nop             ;Two cycle delay
       nop
       goto loop       ;Two cycle goto

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\03\17@182109 by Spehro Pefhany

picon face
At 09:29 PM 3/17/02 +0100, you wrote:
>Hi all
>
>I was wondering if its possible to make 2 oscillators running in one pic
>at the same time ?
>the PIC is a 12C50x with external 4MHz crystal and oscillators should be
>on 100KHz and 50Hz.
>
>Output on any availble GPIO pin is ok ...

You just want two outputs, one at 100kHz and one at 50Hz, and the PIC does
nothing else?

This shouldn't be any problem, just write a loop that generates the 50Hz
and every 5th cycle of
that loop will be a bcf or bsf to toggle the 100kHz output (5 microseconds
per half-cycle).
Use NOP instructions to pad each segment to exactly 5usec if necessary. A
bit tedious, but straightforward.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffspamKILLspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
9/11 United we Stand

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2002\03\17@192257 by Olin Lathrop

face picon face
>>
I was wondering if its possible to make 2 oscillators running in one pic at
the same time ?
the PIC is a 12C50x with external 4MHz crystal and oscillators should be on
100KHz and 50Hz.
<<

This can be done easily.  With a 4MHz oscillator, you're instruction rate is
1MHz.  This means you need to output a complete cycle for 100KHz every 10
instructions, and a complete cycle for 50KHz every 20 instructions.  You
have 5 instructions between the closest spaced events, which is changing the
output of the 100KHz signal.  The complete program is an endless loop of 19
instructions, since the GOTO at the end takes two cycles.

This is totally untested, but here's the basic idea.  "A" is the 100KHz
signal and "B" is the 50KHz signal:

loop                    ;back here each 50KHz cycle
   movlw  <A low, B low>
   movwf  gpio
   nop
   nop
   nop
   movlw  <A high, B low>
   movwf  gpio
   nop
   nop
   nop
   movlw  <A low, B high>
   movwf  gpio
   nop
   nop
   nop
   movlw  <A high, B high>
   movwf  gpio
   nop
   goto   loop         ;this takes two cycles, so replaces two NOPs


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, EraseMEolinspam_OUTspamTakeThisOuTembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu


2002\03\17@205549 by Scott Dattalo

face
flavicon
face
On Sun, 17 Mar 2002, Dale Botkin wrote:

> On Sun, 17 Mar 2002, Lasse Madsen wrote:
>
> > I was wondering if its possible to make 2 oscillators running in one
> > pic at the same time ? the PIC is a 12C50x with external 4MHz crystal
> > and oscillators should be on 100KHz and 50Hz.
>
> Tall order, you're talking about switching the output pin every 5
> instruction cycles for the 100KHz output.  That's simple as long as you
> don't need to do anything else!

I saw Olin's post, but the original question was to generate two
frequencies simultaneously.



100000/50/2 = 2000

    movlw  low(2000/2) + 1      ;+1 because Z instead of C
    movwf  lo_50hz              ;is used to monitor roll over
    movlw  high(2000/2) + 1     ; the /2 is because two cycles
    movwf  hi_50hz              ;of the 100k wave are generated
                                through each pass in the loop
    movf   ioport,w

loop
    movwf  ioport               ;0
    iorlw  (1<<iobit_100k)      ;1
    decf   lo_50hz,f            ;2 Note that the high byte is decremented
    skpnz                       ;  when the low byte reaches zero and not
    decf   hi_50hz,f            ;4 when it rolls over to 0xff. A trick...

    movwf  ioport               ;5

    skpz                        ;6 Z will be set if 50Hz counter is at
     goto  roll_over50hz        ;7 the end.
    andlw  ~(1<<iobit_100k)     ;8

    nop                         ;9 - whew  - a free cycle!

    movwf  ioport               ;10

    iorlw  (1<<iobit_100k)      ;11
    nop
    goto   $+1

    movwf  ioport               ;15
    andlw  ~(1<<iobit_100k)     ;16

    nop                         ;17
    goto   loop                 ;18,19


roll_over50hz:

    xorlw  (1<<iobit_50hz)      ;9
    movwf  ioport               ;10

    movlw  low(2000/2) + 1      ;+1 because Z instead of C
    movwf  lo_50hz              ;is used to monitor roll over

    movf   ioport,w
    andlw  ~(1<<iobit_100k)
    movwf  ioport

    movlw  high(2000/2) + 1
    movwf  hi_50hz

    movf   ioport,w
    iorlw  (1<<iobit_100k)
    movwf  ioport
    nop
    nop
    andlw  ~(1<<iobit_100k)
    goto   loop


This is of course untested.

Scott

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2002\03\17@230203 by Bob Ammerman

picon face
This is nearly trivial.

WARNING: Untested code ahead! Initialization, etc not included.

The 100Khz signal can be generated by code that toggles a GPIO every 5th
instruction time. Code the 50Hz signal is then interspersed around it:

CBLOCK 0x??
   count
ENDC

OUT100K = 0            ; GPIO pin assignments
OUT50  = 1

; Each iteration of the following main_loop takes 50uSec
; and generates 5 full cycles of the 100KHz signal.
; Since the state of the 50Hz signal should change every 0.01
; second, we want to change the state of the 50Hz output each:
;        0.01Sec  /  50uSec = 200th time around the loop

   movlw    .200
   movwf    count

main_loop:
   bsf    GPIO,OUT100K        ;[1:1]
   movlw    1 << OUT50         ;[1:2] assume it is time to toggle
   movf       count,F                 ;[1:3] time to toggle?
   skpnz                                   ;[1:4] skip if not
   xorwf     GPIO,F                 ;[1:5] toggle the pin now

   bcf    GPIO,OUT100K        ;[1:6]
   movlw    .200                       ;[1:7] assume it is time to reset
count
   movf       count,F                  ;[1:8] time to reset?
   skpnz                                   ;[1:9] skip if not
   movwf    count                     ;1:10] reset count

   bsf    GPIO,OUT100K        ;[2:1]
   decf    count,F                      ;[2:2] decrement count
   nop

   bcf    GPIO,OUT100K        ;[2:6]
   goto    $+2
   goto    $+2

   bsf    GPIO,OUT100K        ;[3:1]
   goto    $+2
   goto    $+2

   bcf    GPIOI,OUT100K        ;[3:6]
   goto    $+2
   goto    $+2

   bsf    GPIO,OUT100K        ;[4:1]
   goto    $+2
   goto    $+2

   bcf    GPIOI,OUT100K        ;[4:6]
   goto    $+2
   goto    $+2

   bsf    GPIO,OUT100K        ;[5:1]
   goto    $+2
   goto    $+2

   bcf    GPIO,OUT100K       ;[5:6]
   goto    $+1                ;[5:7-8]
   goto    main_loop       ;[5:9-10]


Bob Ammerman
RAm Systems





{Original Message removed}

2002\03\17@231458 by Bob Ammerman

picon face
Olin, the OP said 100KHz and 50Hz (not KHz). However if you really want
100KHz and 50KHz, how about:

   CBLOCK 0x??
       ONE
   ENDC

   movlw    1
   movwf    ONE
loop:
   movwf    GPIO
   addwf     ONE,W
   andlw      3
   goto        loop

Bob  Ammerman
RAm Systems


{Original Message removed}

2002\03\18@001327 by Scott Dattalo

face
flavicon
face
On Sun, 17 Mar 2002, Bob Ammerman wrote:

> This is nearly trivial.
>
> WARNING: Untested code ahead! Initialization, etc not included.

:)

Looks good except the goto $+2 should be goto $+1. You better fix that
before Olin wakes up.

Scott

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\03\18@071358 by Bob Ammerman

picon face
Oops: left out one instruction. See "****" below.
Also, goto's should be "goto $+1", been working with 18C's lately...

{Original Message removed}

2002\03\18@081708 by Olin Lathrop

face picon face
> I saw Olin's post, but the original question was to generate two
> frequencies simultaneously.

I guess I wasn't clear enough, but my program produces the two desired
frequencies on two separate output pins.  That's what I understood was
desired.  One pin outputs a 100KHz square wave, the other a 50KHz square
wave, both derived from the 4MHz oscillator.  Are you saying my program
doesn't do that or that I misinterpreted the problem statement?


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, KILLspamolinKILLspamspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\03\18@081840 by Olin Lathrop

face picon face
> Olin, the OP said 100KHz and 50Hz (not KHz). However if you really want
> 100KHz and 50KHz, how about:

Oh!  I didn't catch the missing "K".  Then you use the unused cycles between
toggling the 100KHz output to manage a counter to produce the 50Hz signal.
I guess that's what you and Scott were talking about.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, RemoveMEolinTakeThisOuTspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...