Jump to content

Too many Questions (#2)


vedge
 Share

Recommended Posts

Ok this one is a tad bit harder :)

I followed the MIDIBOX SID code to generate a fake clock from the PWM unit.

The current SID's main.asm code generates a 1 Mhz clock out of a 10 Mhz Fosc.

I want to do 3.5 Mhz out of a 10 Mhz Fosc (yes i could live with 4.0 or 3.3333).

Now i know that the resolution might be too crapy to be usefull. after scratching my head for a while

i think i managed to get the clock running at 2 Mhz, but the PIC manual is either very poorly writen, or i

just dont get it (again).

the basic calculations are something like this;

    unsigned char pr2  = 0x09; // PWM period

    unsigned int  fosc = 10000000; // Oscillator frequency

    unsigned char tmr2 = 1;    // TMR2 prescaler

   

    unsigned int duty_cycle =19; // PWM duty cycle

   

    double pwm_period; // PWM period

    double pwm_freq; // PWM frequency

    double duty_cycle_t; // PWM dutcy cycle time

    double duty_cycle_f; // PWM dutcy cycle frequency

    float  resulation_bits; // PWM resolation bits

   

    // Necessary calculations

    pwm_period = (pr2 + 1) * 4 * (1.0 / fosc) * tmr2;

    pwm_freq = 1.0 / pwm_period;

    duty_cycle_t = duty_cycle * (1.0 / fosc) * tmr2;

    duty_cycle_f = 1.0 / duty_cycle_t;

    resulation_bits = log10 ((double)fosc / pwm_freq) / log10 (2.0);

calulating pwm_freq from this code (and the settings given by TK in main.asm of SID gives 250000.00000000 and not 1 Mhz ...

But theres a  1:10 "postscaler" setup in T2CON as well...  im confused.

In theory, using 10 Mhz Fosc, we could derive a 5 Mhz clock with 50/50 duty cycle  right 1,0,1,0,(...),1,0,1?

(theres prolly overhead and other factors i dont know about)

Heres my current code:

PR2      = 0x04;  //was 0x09

T2CON  = 0x24;

CCP1CON = 0x0f; //11xx = PWM mode

CCPR1L  = 0x04;

This seems to run at 2 MHz now (im not exactly sure, i can only trust the +1 octave change i get in the outputs of the sound chip i use)

(sorry if this seems unclear, ive been programming all day at work, and i try to make this HW synth work at home in the evenings, where the

brain is not 100% working .... yeah maybe i should try and relax instead)

More later.... if you dont mind,

Link to comment
Share on other sites

(sorry if this seems unclear, ive been programming all day at work, and i try to make this HW synth work at home in the evenings, where the brain is not 100% working .... yeah maybe i should try and relax instead)

I know that feeling only too well!

I've found that building my m-box has been a lot like coding - you know sometimes you'll be having a nightmare with a bit of code after a long day, you go home sleep and in the morning you do it in a few minutes.

Good luck with the box, don't work too hard ;)

Link to comment
Share on other sites

Is that FOsc or TOsc?

Ive no clue what the difference is. the 10 Mhz crystal in the typical core... is that a Fosc or a Tosc?

how should I know, you tell me :)

Note: The Timer2 postscalers (see Section 13.0 “Timer2 Moduleâ€) are not used in the determination of the PWM frequency.

Now spill the beans! ;)

TK should spill the beans! not me. i dont know why/.whats the use of the external postcaler. its to drive different "servo" something,

the word 'servo"  only appear ONCE in the whole pdf. And its in that occasion... MBOX Moter Fader?

Link to comment
Share on other sites

Whew, I used to know this one.  It's been a while though, and I no longer have the 18Fxx2 datasheet memorized.

Just going off the top of my head here, isn't there a 4:1 PLL or something inside the PIC that turns that 10 MHz crystal into a 40 MHz signal internally?  The instructions actually take 4 cycles each - but that's at 40 MHz - so on the outside it looks like you're getting 10 MIPS at 10 MHz.  IIRC the 16F877 ran at the external oscillator frequency, so 20 MHz only gave you 5 MIPS.

That would explain why the calculation you used was only giving you 250k instead of 1M.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...