Shop OBEX P1 Docs P2 Docs Learn Events
OV7670 with Propeller and C — Parallax Forums

OV7670 with Propeller and C

Hey you all out there,

I am starting an Project with LoRa wireless and an OV7670 camera.
I have seen some projects out here, running the camera with spin, but i like C much more :)

At the moment, i think about feeding the camera's XCLK pin with an CLK generated from the Propeller.
My Problem is, how can i achieve an frequency of about at least 8MHz in C code at an pin?
I am using the Propeller ASC+.

Can somebody give me an hint?
Thanks in advice.

Greetings,
Daniel

Comments

  • Hi @d0nar, welcome to the forums!

    If you found a Spin object that satisfies your requirements, I would highly recommend throwing it through the Spin to C++ translator written by a fellow forum member called spin2cpp. There's pretty good instructions in the project's README which can be found on GitHub: https://github.com/totalspectrum/spin2cpp

    I'm guessing you're using SimpleIDE, but if you're using PropWare by chance, then PropWare will automatically run spin2cpp over the Spin file for you. See the example here.
  • d0nard0nar Posts: 3
    edited 2016-09-10 08:18
    Hi @DavidZemon, thank you :)

    That might be a solution, but doing it my own, has a bigger learn effect ;)
    Maybe i will go this way to get some hints.

    For now I am stuck with Omnia Creator and might give PropWare a chance, but only when i get it up and running with Clion, which is my preffered IDE.


    Edit:
    found that snippet for C

    DIRA |= 1<<23;
    FRQA = 12010943;
    CTRA = (0x17<<23) + 23;
    while(1) ;

    but when i alter it like this

    DIRA |= 1<<0; //Pin 0 as output
    FRQA = 268435456; //get 8MHz
    CTRA = (0x17<<0) + 0; //Pin 0 toggle at 8MHz
    while(1);

    it produces nothing on Pin 0
    so could it be, that i have to look after the physical Pin number for using this?
    Sorry for this question, never needed the low level stuff in propeller, low level was only on PIC16´s
  • You changed a bit too much (and incidentally you found an example using the same numbers everywhere...).
        DIRA |= 1<<0;            //Pin 0 as output
        FRQA = 268435456;        //get 8MHz
        CTRA = (0x17<<23) + 0;   //Pin 0 toggle at 8MHz
        while(1);
    

    The shift 23 on the CTRA assigment means to assign 0x17 to bits 31..23 of the CTRA register that controls the counter configuration (see the Propeller manual) and is not related to the pin number. The + 0 instead is ORin the pin number (bits 9..0) which is correct.

    With the correction above it should work.
  • d0nar wrote: »
    Hi @DavidZemon, thank you :)

    That might be a solution, but doing it my own, has a bigger learn effect ;)
    Maybe i will go this way to get some hints.

    Makes sense :)
    d0nar wrote: »
    For now I am stuck with Omnia Creator and might give PropWare a chance, but only when i get it up and running with Clion, which is my preffered IDE.

    That's great! I didn't know anyone was using OmniaCreator - it's a fantastic IDE. Are you on Windows, Mac or Linux?

    Edit:
    found that snippet for C

    DIRA |= 1<<23;
    FRQA = 12010943;
    CTRA = (0x17<<23) + 23;
    while(1) ;

    but when i alter it like this

    DIRA |= 1<<0; //Pin 0 as output
    FRQA = 268435456; //get 8MHz
    CTRA = (0x17<<0) + 0; //Pin 0 toggle at 8MHz
    while(1);

    it produces nothing on Pin 0
    so could it be, that i have to look after the physical Pin number for using this?
    Sorry for this question, never needed the low level stuff in propeller, low level was only on PIC16´s

    This comes out of PropWare and should work nicely for you. I tested it on my own machine and was able to hit a reliable 8 MHz with it. I imagine for other not-so-even numbers, you'd get a bit more jitter. But 8 MHz is a good choice :).
    void start_hardware_pwm (const uint32_t frequency) const {
        this->stop_hardware_pwm();
    
        const uint32_t frq = (UINT32_MAX + 1ULL) * frequency / CLKFREQ;
        const uint32_t ctr = (4 << 26) | convert(this->m_mask);
        if (Channel::A == this->m_channel) {
            FRQA = frq;
            PHSA = 0;
            CTRA = ctr;
        } else if (Channel::B == this->m_channel) {
            FRQB = frq;
            PHSB = 0;
            CTRB = ctr;
        }
    }
    

    Note that, in place of "convert(this->m_mask)" you'll just want to use "0" for your pin number. And, though PropWare's function doesn't include it, you are certainly correct to be setting the DIRA register as well.
  • macca wrote: »
    You changed a bit too much (and incidentally you found an example using the same numbers everywhere...).
        DIRA |= 1<<0;            //Pin 0 as output
        FRQA = 268435456;        //get 8MHz
        CTRA = (0x17<<23) + 0;   //Pin 0 toggle at 8MHz
        while(1);
    

    The shift 23 on the CTRA assigment means to assign 0x17 to bits 31..23 of the CTRA register that controls the counter configuration (see the Propeller manual) and is not related to the pin number. The + 0 instead is ORin the pin number (bits 9..0) which is correct.

    With the correction above it should work.

    oh okay :D
    thank you for the explanation, sadly Pin 0 (i really hope Pin 0 in code is Pin 0 on the Board) seems just to give my Oscilloscope an ~1,8 V DC Signal (tested at several frequencies)
    DavidZemon wrote: »
    d0nar wrote: »
    For now I am stuck with Omnia Creator and might give PropWare a chance, but only when i get it up and running with Clion, which is my preffered IDE.

    That's great! I didn't know anyone was using OmniaCreator - it's a fantastic IDE. Are you on Windows, Mac or Linux?

    At the moment on Windows on my gaming rig, later i will use my laptop or workstation with arch, but for now i am too lazy to install my laptop and workstation all fresh with good old german telekom 660kB/s...
    This will be done when the semester begins and then using the good w-lan ^^
    A few things on Omnia annoy me, sometimes it crashes unexpectedly, sometimes it is not able to open the port, but i like the code completion freatures :)


    DavidZemon wrote: »

    This comes out of PropWare and should work nicely for you. I tested it on my own machine and was able to hit a reliable 8 MHz with it. I imagine for other not-so-even numbers, you'd get a bit more jitter. But 8 MHz is a good choice :).
    void start_hardware_pwm (const uint32_t frequency) const {
        this->stop_hardware_pwm();
    
        const uint32_t frq = (UINT32_MAX + 1ULL) * frequency / CLKFREQ;
        const uint32_t ctr = (4 << 26) | convert(this->m_mask);
        if (Channel::A == this->m_channel) {
            FRQA = frq;
            PHSA = 0;
            CTRA = ctr;
        } else if (Channel::B == this->m_channel) {
            FRQB = frq;
            PHSB = 0;
            CTRB = ctr;
        }
    }
    

    Note that, in place of "convert(this->m_mask)" you'll just want to use "0" for your pin number. And, though PropWare's function doesn't include it, you are certainly correct to be setting the DIRA register as well.

    I altered it now to this:
    void start_hardware_pwm (const uint32_t frequency) {
        DIRA |= 1<<0;
        const uint32_t frq = (UINT32_MAX + 1ULL) * frequency / CLKFREQ;
        const uint32_t ctr = (4 << 26) | 0;
            FRQA = frq;
            PHSA = 0;
            CTRA = ctr;
    }
    

    It seems to work, at least at a few khz, but with 8MHz it seems like a sinus wave, i think maybe my oscilloscope is there at his limit :/
    but normaly the digital part should be able to record 20MHz without problems :/
    at the analouge part it normaly should also work, 20MHz vertical and 2MHz horicontal
    Have to say it is from 1986, got it just a year ago and for now i did only simple stuff with it^^


Sign In or Register to comment.