View previous topic :: View next topic |
Author |
Message |
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
PIC12F509 speed issue! |
Posted: Tue Jul 27, 2010 10:47 am |
|
|
Help! The following code should produce a 1ms width square wave on pin_b0...it doesn't it produces a 9.3ms width. It's so simple I can't see where it is incorrect. The config word is calculated correcly. The INTRC osc runs at 4MHz (according to the datasheet!).
Help Please!
Code: |
CCS PCB C Compiler, Version 4.107, 48595 27-Jul-10 17:43
Filename: c:\temp\arrow.lst
ROM used: 31 words (3%)
Largest free fragment is 512
RAM used: 3 (12%) at main() level
4 (16%) worst case
Stack: 1 locations
*
0000: MOVWF 05
0001: GOTO 016
0002: GOTO 003
.................... #include "C:\Temp\arrow.h"
.................... #include <12F509.h>
.................... //////// Standard Header file for the PIC12F509 device ////////////////
.................... #device PIC12F509
.................... #list
....................
....................
.................... #FUSES NOWDT //No Watch Dog Timer
.................... #FUSES INTRC //Internal RC Osc
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES NOMCLR //Master Clear pin enabled
.................... #use delay(clock=4000000)
*
0003: MOVF 0A,W
0004: BTFSC 03.2
0005: GOTO 014
0006: MOVLW 01
0007: MOVWF 08
0008: CLRF 07
0009: DECFSZ 07,F
000A: GOTO 009
000B: DECFSZ 08,F
000C: GOTO 008
000D: MOVLW 4A
000E: MOVWF 07
000F: DECFSZ 07,F
0010: GOTO 00F
0011: GOTO 012
0012: DECFSZ 0A,F
0013: GOTO 006
0014: BCF 03.5
0015: GOTO 020 (RETURN)
....................
....................
....................
.................... void main() {
0016: CLRF 04
.................... while(true){
.................... output_toggle(PIN_B0);
*
0019: BCF 09.0
001A: MOVF 09,W
001B: TRIS 6
001C: MOVLW 01
001D: XORWF 06,F
.................... delay_ms(1);
001E: MOVWF 0A
001F: GOTO 002
.................... }
0020: GOTO 019
.................... }
0021: SLEEP
Configuration Fuses:
Word 1: 0FEA INTRC NOWDT NOPROTECT NOMCLR
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 27, 2010 12:09 pm |
|
|
Use the Stopwatch feature of the MPLAB simulator to count the instruction
cycles in your loop. Put a breakpoint on the output_toggle() line.
Follow the instructions in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=38351
Remember to set the correct clock frequency in the Debugger Settings
menu (set it to 4 MHz).
This test will tell you if there is something wrong with the CCS delay_ms()
library code. If the loop is approximately 1 ms, then you need to look
elsewhere to find the problem.
I'm assuming that you're running this in real hardware. If you're running
it in a simulator (Proteus) then look there for the problem. |
|
|
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
|
Posted: Wed Jul 28, 2010 4:40 am |
|
|
Thanks.
After much head scratching, code looks OK. Turns out you can't use the CCS ICD to program these devices reliably! Oscal was corrupt and the fuses weren't being written correctly. Dusted off the PicKit2 programmer, and after re-calcing Oscal, programmed up and ran at full speed.
Keep well all. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 28, 2010 3:03 pm |
|
|
I think it's probably the INTRC and NOMCLR issue. ICD2 can't program
these two fuses together reliably. MPLAB gives a warning about this.
Microchip recommends using the Pickit 2 when you want to use NOMCLR
with the internal oscillator, which is what you did. |
|
|
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
|
Posted: Thu Jul 29, 2010 2:36 am |
|
|
I didn't know there was an issue, thanks one for the memory banks. You are almost certainly correct as I hold the MCLR pin to GND with 10k which I had to remove just to get the PIC running! Holding MCLR high, it ran, but very slowly.
Programming with PicKit2 and everything is perfect. |
|
|
|