vedge Posted November 17, 2006 Report Share Posted November 17, 2006 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 ijust 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 thebrain is not 100% working .... yeah maybe i should try and relax instead)More later.... if you dont mind, Quote Link to comment Share on other sites More sharing options...
DavidBanner Posted November 17, 2006 Report Share Posted November 17, 2006 (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 ;) Quote Link to comment Share on other sites More sharing options...
stryd_one Posted November 17, 2006 Report Share Posted November 17, 2006 hints: Is that FOsc or TOsc? There's an internal clock multiplier.Note: The Timer2 postscalers (see Section 13.0 “Timer2 Moduleâ€) are not used in the determination of the PWM frequency.Now spill the beans! ;) Quote Link to comment Share on other sites More sharing options...
vedge Posted November 17, 2006 Author Report Share Posted November 17, 2006 Good luck with the box, don't work too hard ;)Only one or two hours before going to sleep ... aint that a good idea :) Quote Link to comment Share on other sites More sharing options...
vedge Posted November 17, 2006 Author Report Share Posted November 17, 2006 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? Quote Link to comment Share on other sites More sharing options...
AndrewMartens Posted November 17, 2006 Report Share Posted November 17, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.