The last Fourth Wish


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    New York US
    Posts
    46


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi All,
    I am still learning to keep my brain from drying and I will appreciate any tips or tricks
    to show me how to work in right way.
    In early eighty I already learned processor architecture and had learning experience
    How to write program in binary that processor understand (just BIOS).
    I did not use this knowledge in my working experience.
    Right now PIC for me is just a nail and PICBASIC PRO is just a hummer.
    So using both of them I able to put together hardware and technology.
    Doing this in easy way I am pretty sure that double core PIC has
    advantage than using single advanced and expensive PIC for multitasking program
    Especially if you are not a ghost living in microprocessor and manually turn on or off
    bits in registers.
    In my example I am not agree that to generate frequency and find minimum can be done
    by using one comparator:
    OSC 20 MHz
    NUM var WORD
    DELTA var WORD
    CMCON=%00000101 ‘ set
    DELTA = 2500
    Run:
    PORTB.0 =%00000001
    CALL WAITA
    IF CMCON=%10000101 Then Delta = DELTA -1‘ if digital more than reference
    PORTB.0 =%00000000
    CALL WAITA
    GOTO RUN
    WAITA:
    FOR NUM = 0 TO DELTA
    @ useless statement
    NEXT NUM
    OR write statements in assembler or better in binary code
    For frequency 200KHz period on is equal 2.5uSec and off 2.5uSec.
    For right heating condition needs to be in 10Hz range so 200000+10 = 200010KHz
    It is means steps on is equal 1.5nSec and off 1.5nSec.
    So variable NUM has step 1.5nSec and max value is equal 3333
    For 500KHz you can calculate more strange numbers.
    How is it possible to send SEROUT message that last 2mSec when microprocessor
    Is Working on generating frequency and time needed for one operation is 200nSec?
    My guess that your expertise ends here because using one PIC cannot do this task
    Any comments?
    Best Regards to ALL

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hardcore View Post
    How is it possible to send SEROUT message that last 2mSec when microprocessor Is Working on generating frequency and time needed for one operation is 200nSec?
    My guess that your expertise ends here because using one PIC cannot do this task
    Any comments?
    Keep guessing

    Having a 200KHz (or 500KHz) signal and sending a out a message is easily possible - just not the way you are doing it.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi hardcore,
    The key is to use the PIC's built in peripheral modules. Most "modern" PICs have at least one CCP module (Capture Compare PWM module) that, in conjunction with one of the PIC's hardware timers can be set up to generate any frequency and duty cycle you want (within limits depending on oscillator speed etc). The PBP command HWPM uses the CCP module to do this but it has it's limitations which you can get around by writing the registers manually.

    Let's see, a 16F628 running at 20Mhz....(this is untested but try it out, read the datasheet section on CPP module and TMR2 in this case)
    Code:
    DEFINE OSC 20
    TRISB.3 = 0  'Set CCP pin to output.
    
    CCP1CON = %00001100   'CCP module in PWM mode
    PR2 = 9               '~500kHz
    TMR2L = 20            '~50% duty cycle at 500kHz
    T2CON = %00000100     'TMR2 ON, prescaler 1:1
    
    Main:
    'Do whatever.
    Goto Main
    Another very common peripheral is the USART (16F628 has one) which can be used to send data out over a serial line, it is also hardware so you set it up for the baudrate you want (or let PBP so it for you) and then just write a character to it and IT will send it out - no need to bit-bang it out with SEROUT. The PBP command HSEROUT for example uses the hardware USART to send data.

    There are several other hardware periphelals bulit in to most PICs that you have to master and take advantage of. Think of it, it's only the last couple of years that the CPU's used in modern PC's have gone "multi-core" yet they've been able to get them doing quite a bit of work "in parallel" by using IT'S hardware peripherals and clever time-slicing and other multitasking tricks.

    If you REALLY think you need "multi-core" then take a look at Parallax Propeller chip, it has 8 CPUs with shared RAM and some pretty cool things can be done with it. (Never tried one myself though).

    /Henrik.

  4. #4
    Join Date
    Dec 2008
    Location
    New York US
    Posts
    46


    Did you find this post helpful? Yes | No

    Lightbulb

    Dear Henrik,
    Always when we speak about feedback than best solution is analog schematics.
    Unfortunately, especially when needs to generate frequency in SWEEP MODE.
    Start at 200KHz and go up with 10 Hz step until schematics find optimum.
    When optimum frequency is found then needs continuously adjust frequency by monitoring voltage
    on serial/parallel resonance output LC module and keep it close to zero.
    Using traditional PIC architecture does not allow to do that.
    So idea about dual core PIC with bridges between registers keeping variables is advance move in right direction.
    Few words about USART. I read all literature and could not found how assigned
    PORTB.Pin can send periodically variable values to serial LCD without involving
    CPU resources for example 4 times per Sec.
    About Propeller Chip: It is really good for gathering information, scaling data, and
    sending data to storage.For me 8 CPU is too much and will never be using in any hobby applications
    except special industrial ones.Will be better if manufacturer design
    this chip with 2-4 cores and inner bridges between registers.It will give more freedom.
    Best Regards to All

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,

    I don't know enough info about your paritcular project to tell if it is doable with a PIC or not - maby it is, maby it isn't. You asked how it was possible to send a serial message lasting 2ms and have the PIC output 200kHz PWM signal at the same time. I showed you one possible way of doing that - by using the CCP module to generate the PWM and the USART to send the serial message. That way I'd guess 99% of the CPU time is still available.

    Of course the CPU needs to be involved even when using the USART but the difference in amount of involvement compared to bitbanging a character is massive. Really, all the CPU needs to do is load the USART TX-register with the character to be sent, takes one maby two instruction cycles then it can continue doing other thing while the USART sends the character. When the USARTs transmit buffer is ready for another character it sets a flag which you can either poll or have generating an interrupt.

    To send something periodically you use another one of the PICs hardware timers setup to generate an interrupt at a certain frequency. The interrupt service routine then either does the whole thing, sending the message (usually not a good aproach) or it simply initiates the sending by loading the first character into the USART TX-register and activating the TX-interrupt so that when the first character is sent you get another interrupt so you can load the next character etc etc. When the whole message is sent the you deactivate the TX-interrupt.

    In my servo drive project I've been working on for long time the PIC counts step- and direction pulses at up to ~100kHz, reads an incremental encoder at up to 2.5MHz updating a 32bit position register, runs the PID loop at 1220Hz, drives the output bridge with a 20kHz PWM signal, sends and recieves serial messages at 115200baud AND blinks a LED - all at "the same time". It's not done magically with a single command, you have to make it happen.

    /Henrik.

  6. #6
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    As you and I have pointed out, doing multiple things at apparently the same time is easily possible - you have to make it happen.

    The main issue that the OP has is that he wants to sweep a PWM output from 200KHz to 500KHz with 10Hz resolution/steps using the PIC.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts