搜索
bottom↓
回复: 29

哈哈,C8051F340超频到96MHz,真是爽呀

[复制链接]

出0入300汤圆

发表于 2012-3-7 17:16:57 | 显示全部楼层 |阅读模式
24MHz外部晶振进去后用时钟乘法器倍到96MHz
明天做一下高低温试验,如成功再汇报.

//-----------------------------------------------------------------------------
// F34x_PCA0_Software_Timer_Blinky.c
//-----------------------------------------------------------------------------
// In this example, PCA Module 0 is used to generate the interrupt, and the
// port pin driving the LED is configured for push-pull mode.
//
// Pinout:
//
//   P2.2 - LED (push-pull)
//
//   all other port pins unused
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <C8051F340.h>                 // SFR declarations

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------

#define SYSCLK       96000000          // Internal oscillator frequency in Hz

#define LED_FREQUENCY 100000                // Frequency to blink LED at in Hz
#define T0_CLOCKS 240                  // Use 120 clocks per T0 Overflow

// SYSCLK cycles per interrupt
#define PCA_TIMEOUT ((SYSCLK/T0_CLOCKS)/LED_FREQUENCY/2)

sfr16 PCA0CP0 = 0xFB;                  // PCA0 Compare Register Definition

sbit LED = P2^2;                       // LED='1' means ON

//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------

void Oscillator_Init (void);
void Port_Init (void);
void PCA0_Init (void);

//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------

unsigned int NEXT_COMPARE_VALUE;       // Next edge to be sent out in HSO mode

//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------

void main (void) {

   // Disable watchdog timer
   PCA0MD = 0x00;

   Port_Init ();                       // Initialize crossbar and GPIO
   Oscillator_Init ();                 // Initialize oscillator
   PCA0_Init ();                       // Initialize PCA0

   EA = 1;                             // Globally enable interrupts

   while (1);                          // Spin here to wait for ISR
}


//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Oscillator_Init
void Oscillator_Init (void)
{
   //OSCICN = 0x83;                      // Set internal oscillator to run
                                       // at its maximum frequency

   //CLKSEL = 0x00;                      // Select the internal osc. as
                                       // the SYSCLK source

    int i = 0;
    OSCXCN    = 0x20;
    FLSCL     = 0x90;
    CLKMUL    = 0x81;
    for (i = 0; i < 20; i++);    // Wait 5us for initialization
    CLKMUL    |= 0xC0;
    while ((CLKMUL & 0x20) == 0);
    CLKSEL    = 0x23;
    OSCICN    = 0x03;
}

//-----------------------------------------------------------------------------
// Port_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the crossbar and GPIO ports.
//
// No crossbar peripherals are used for this example.
//
// P2.2 is set to Push-Pull mode.
//
//-----------------------------------------------------------------------------
void Port_Init (void)
{
  // XBR0 = 0x00;
   //XBR1 = 0x40;                        // No peripherals routed to pins
                                       // Enable crossbar and weak pull-ups

   //P2MDOUT |= 0x04;                    // Set LED (P2.2) to push-pull
       // P0.0  -  Unassigned,  Open-Drain, Digital
    // P0.1  -  Unassigned,  Open-Drain, Digital
    // P0.2  -  Unassigned,  Open-Drain, Digital
    // P0.3  -  Unassigned,  Open-Drain, Digital
    // P0.4  -  Unassigned,  Open-Drain, Digital
    // P0.5  -  Unassigned,  Open-Drain, Digital
    // P0.6  -  Unassigned,  Open-Drain, Digital
    // P0.7  -  Skipped,     Open-Drain, Digital

    // P1.0  -  Unassigned,  Open-Drain, Digital
    // P1.1  -  Unassigned,  Open-Drain, Digital
    // P1.2  -  Unassigned,  Open-Drain, Digital
    // P1.3  -  Unassigned,  Open-Drain, Digital
    // P1.4  -  Unassigned,  Open-Drain, Digital
    // P1.5  -  Unassigned,  Open-Drain, Digital
    // P1.6  -  Unassigned,  Open-Drain, Digital
    // P1.7  -  Unassigned,  Open-Drain, Digital

    // P2.0  -  Unassigned,  Open-Drain, Digital
    // P2.1  -  Unassigned,  Open-Drain, Digital
    // P2.2  -  Unassigned,  Push-Pull,  Digital
    // P2.3  -  Unassigned,  Open-Drain, Digital
    // P2.4  -  Unassigned,  Open-Drain, Digital
    // P2.5  -  Unassigned,  Open-Drain, Digital
    // P2.6  -  Unassigned,  Open-Drain, Digital
    // P2.7  -  Unassigned,  Open-Drain, Digital

    // P3.0  -  Unassigned,  Open-Drain, Digital
    // P3.1  -  Unassigned,  Open-Drain, Digital
    // P3.2  -  Unassigned,  Open-Drain, Digital
    // P3.3  -  Unassigned,  Open-Drain, Digital
    // P3.4  -  Unassigned,  Open-Drain, Digital
    // P3.5  -  Unassigned,  Open-Drain, Digital
    // P3.6  -  Unassigned,  Open-Drain, Digital
    // P3.7  -  Unassigned,  Open-Drain, Digital

    P2MDOUT   = 0x04;
    P0SKIP    = 0x80;
    XBR1      = 0x40;
}

//-----------------------------------------------------------------------------
// PCA0_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the PCA time base to use T0 Overflows as a clock
// source.  Timer0 is also configured by this routine for 8-bit auto-reload
// mode, where T0_CLOCKS is the number of System clocks per T0 Overflow.
// The code then sets up Software Timer mode for Module 0 (CEX0 pin).
//
// On every interrupt from Module 0, software toggles the port I/O pin for the
// LED. The frequency of the LED toggling is determined by the parameter
// CEX0_FREQUENCY.
//


// Using different PCA clock sources, different T0 reload values, or a
// different processor clock will result in a different frequency for the LED
// square wave, and different maximum and minimum options.
//
//    -------------------------------------------------------------------------
//    How "Software Timer Mode" Works:
//
//       The PCA's Software Timer Mode works by generating an interrupt for the
//    associated module every time the PCA0 register increments and the new
//    16-bit PCA0 counter value matches the module's capture/compare
//    register (PCA0CPn).
//
//    By loading the PCA0CPn register with the next match value every time a
//    match happens, arbitrarily timed interrupts can be generated.
//    -------------------------------------------------------------------------
//
// When setting the capture/compare register for the next match value, the low
// byte of the PCA0CPn register (PCA0CPLn) should be written first, followed
// by the high byte (PCA0CPHn).  Writing the low byte clears the ECOMn bit,
// and writing the high byte will restore it.  This ensures that a match does
// not occur until the full 16-bit value has been written to the compare
// register.  Writing the high byte first will result in the ECOMn bit being
// set to '0' after the 16-bit write, and the next match will not occur at
// the correct time.
//
// It is best to update the capture/compare register as soon after a match
// occurs as possible so that the PCA counter will not have incremented past
// the next desired edge value. This code implements the compare register
// update in the PCA ISR upon a match interrupt.
//
//-----------------------------------------------------------------------------
void PCA0_Init (void)
{

   // Configure Timer 0 for 8-bit auto-reload mode, using SYSCLK as time base
   TMOD &= 0xF0;                       // Clear all T0 control bits
   TMOD |= 0x02;                       // 8-bit auto-reload timer
   CKCON |= 0x04;                      // T0 uses SYSCLK
   TH0 = -T0_CLOCKS;                   // Set up reload value
   TL0 = -T0_CLOCKS;                   // Set up initial value

   // Configure PCA time base; overflow interrupt disabled
   PCA0CN = 0x00;                      // Stop counter; clear all flags
   PCA0MD = 0x04;                      // Use Timer 0 as time base

   PCA0CPM0 = 0x49;                    // Module 0 = Software Timer Mode,
                                       // Enable Module 0 Interrupt flag,
                                       // Enable ECOM bit

   PCA0L = 0x00;                       // Reset PCA Counter Value to 0x0000
   PCA0H = 0x00;

   PCA0CPL0 = PCA_TIMEOUT & 0x00FF;    // Set up first match
   PCA0CPH0 = (PCA_TIMEOUT & 0xFF00) >> 8;

   // Set up the variable for the following match
   NEXT_COMPARE_VALUE = PCA0CP0 + PCA_TIMEOUT;

   EIE1 |= 0x10;                       // Enable PCA interrupts

   CR = 1;                             // Start PCA
   TR0 = 1;                            // Start Timer 0

}

//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// PCA0_ISR
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This is the ISR for the PCA.  It handles the case when a match occurs on
// channel 0, and updates the PCA0CPn compare register with the value held in
// the global variable "NEXT_COMPARE_VALUE".
//
//-----------------------------------------------------------------------------
void PCA0_ISR (void) interrupt 11
{
   if (CCF0)                           // If Module 0 caused the interrupt
   {
      CCF0 = 0;                        // Clear module 0 interrupt flag.

      PCA0CPL0 = (NEXT_COMPARE_VALUE & 0x00FF);
      PCA0CPH0 = (NEXT_COMPARE_VALUE & 0xFF00)>>8;

      LED = ~LED;                      // Invert the LED pin

      // Set up the variable for the following edge
      NEXT_COMPARE_VALUE = PCA0CP0 + PCA_TIMEOUT;
   }
   else                                // Interrupt was caused by other bits.
   {
      PCA0CN &= ~0x86;                 // Clear other interrupt flags for PCA
   }
}


//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入30汤圆

发表于 2012-3-7 17:44:57 | 显示全部楼层
这个嘛,个人玩玩还不错,但要用到产品中,我不知道几个人敢哪,产品可靠性怎么保证。

出0入0汤圆

发表于 2012-3-7 19:01:14 | 显示全部楼层
为什么要超频?

出0入0汤圆

发表于 2012-3-8 23:01:31 | 显示全部楼层
似乎最高可到120MHz吧


(原文件名:120m.JPG)

出0入0汤圆

发表于 2012-3-8 23:14:17 | 显示全部楼层
疯狂的51

出0入300汤圆

 楼主| 发表于 2012-3-9 00:13:09 | 显示全部楼层
哈哈,真相来了,步进电机瞬间加速到1800转/分钟(每转2000脉冲),加减速时间都控制在120ms,快赶上伺服了.
放在桌上不抖动,很平稳.
如果MCU没速度的话,复杂的加减速不可能实现

今天视频传不上来,明天择机上传.

点击此处下载 ourdev_725083WKYI2P.rar(文件大小:1.66M) (原文件名:dianji.rar)

出0入0汤圆

发表于 2012-3-9 09:01:27 | 显示全部楼层
你要是敢在产品中这么干,你真牛逼。我都是将加减速做到CPLD/FPGA中.

出0入0汤圆

发表于 2012-3-9 09:27:47 | 显示全部楼层
关心楼主步进电机加减速的实现原理。呵呵呵。

出0入0汤圆

发表于 2012-3-9 10:37:34 | 显示全部楼层
mark

出0入300汤圆

 楼主| 发表于 2012-3-9 11:26:34 | 显示全部楼层
回复【6楼】semonpic
你要是敢在产品中这么干,你真牛逼。我都是将加减速做到cpld/fpga中.
-----------------------------------------------------------------------

我就是用在产品里的,不过是超到60MHz(指标是48MHz).96MHz的超频是做极限试验,这很有必要.
cpld那点资源只能给编码器反馈提供支持,还有键盘,显示,其他扩展io,电子齿轮比.别的就没法干了,所以还要MCU强一点好用.
我是绝对不会用fpga的,这不是明摆着做完叫人家随便抄吗.

出0入0汤圆

发表于 2012-3-9 12:34:03 | 显示全部楼层
记号,silicon lab c8051f over clock

出0入0汤圆

发表于 2012-3-9 12:48:54 | 显示全部楼层
醉酒狂飙。

出0入0汤圆

发表于 2012-4-2 17:10:05 | 显示全部楼层
超频mcu也有飚车的感觉么?

出0入0汤圆

发表于 2012-4-2 17:15:10 | 显示全部楼层
这个、、、下次看、、、先做个记号、、、呵呵、、

出0入4汤圆

发表于 2012-4-2 17:21:52 | 显示全部楼层
不错,如果稳定,我也试试。

出0入0汤圆

发表于 2012-4-2 20:23:02 | 显示全部楼层
有点意思,overclock影响器件寿命吗

出0入0汤圆

发表于 2012-4-2 20:32:36 | 显示全部楼层
做到产品上面似乎有点疯狂吧

出0入0汤圆

发表于 2012-4-2 20:34:06 | 显示全部楼层
超频mcu有点意思
估计爽快的感觉不会太长久

出0入0汤圆

发表于 2012-4-2 20:34:37 | 显示全部楼层
不考虑产品寿命?

出0入0汤圆

发表于 2012-4-3 18:44:39 | 显示全部楼层
ibmx311 发表于 2012-3-9 00:13
哈哈,真相来了,步进电机瞬间加速到1800转/分钟(每转2000脉冲),加减速时间都控制在120ms,快赶上伺服了.
放在 ...

下来学习步进电机的加减算法,谢谢分享!

出0入0汤圆

发表于 2012-4-9 12:46:33 | 显示全部楼层
这个要顶,MCU超频一倍的事情你都敢做,厉害!
不过如果能用F320超频,就更爽了
F340跑48M,在读Flash的时候都用了缓存技术,F320是直接读Flash的
F320能超了,就更爽了

出0入0汤圆

发表于 2012-4-9 13:00:50 | 显示全部楼层
牛~~~~~~

出0入0汤圆

发表于 2012-4-9 13:48:53 | 显示全部楼层
这个还是不要的好吧,选个性能更好的MCU

出0入0汤圆

发表于 2012-4-9 23:59:18 | 显示全部楼层
xiaobenyi 发表于 2012-4-9 12:46
这个要顶,MCU超频一倍的事情你都敢做,厉害!
不过如果能用F320超频,就更爽了
F340跑48M,在读Flash的时候都用 ...

你有F320试过没有?

俺木有,只能羡慕下了,

出0入0汤圆

发表于 2012-4-10 08:42:14 | 显示全部楼层
jetli 发表于 2012-4-9 23:59
你有F320试过没有?

俺木有,只能羡慕下了,

没想过,呵呵,从没实施过MCU超频的事情,除了AVR做的USB,8M超到12M,大家做的都很稳定

出0入0汤圆

发表于 2012-5-3 21:47:51 | 显示全部楼层
哈哈,听起来很诱人啊,我在proteus里面把AT89S51的晶振改到了36MHZ也可以用,不过没在实际中搞过!期待,楼主的新发现!

出0入0汤圆

发表于 2012-5-4 00:04:58 | 显示全部楼层
这个也能超频啊
楼主厉害
做产品我都是降频使用的

出0入0汤圆

发表于 2014-1-4 16:07:41 | 显示全部楼层
年人这也能超!

出0入0汤圆

发表于 2014-2-26 10:13:55 | 显示全部楼层
mark~~~~~~~~

出0入0汤圆

发表于 2014-2-27 00:25:52 | 显示全部楼层
直接上酷睿,何必超频?
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-26 03:42

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表