News:

Let's find out together what makes a PIC Tick!

Main Menu

Trouble porting to PIC12F1572

Started by rick.curl, Nov 25, 2022, 10:17 PM

Previous topic - Next topic

rick.curl

I wrote a simple piece of code for a local Makers group that does nothing but blink three LED's to visually send the letters RMM in morse code. This is used to make a little badge that students assemble in a soldering class. I originally used a PIC 12F675, but they are in short supply so I wanted to port the code to a PIC12F1572. When I run the new code, the LEDs just stay on and do not blink. To make sure the chip was running I added this: Testloop:
lata.0 = 1
delayms 100
lata.0 = 0
delayms 100
goto Testloop
When I do this, the LED on port A.0 blinks, so I know the pic is running.
My suspicion is that there's something about "Dim OutPin as Pin" that is not working correctly on the PIC1572. 
Here's the original code for the 12F675 that works:
    Device  12F675

    Xtal 4
    Reminders off
   Config INTRC_OSC_NOCLKOUT, WDT_OFF , PWRTE_ON , BODEN_ON, MCLRE_OFF
    Reminders On

    CMCON = %00000111  'comparator off
    VRCON = %00000111  'voltage reference disabled
    TRISIO = %11000000
    ANSEL = 0           'all pins digital

'** Declare constants **
    symbol Dit = 100    'DIT time (milliseconds) THIS SETS THE SPEED
    Symbol Dah = dit * 3  'DAH time
    Symbol Space = dit * 7 'pause between words

'** Declare aliases **
   Dim OutPin as pin

   GPIO = 0   'set all pins to zero
   DelayMS 1000 'wait a bit before starting

Mainloop:
'R
    OutPin = GPio.0
    gosub ditsub
    gosub dahsub
    gosub ditsub

'M
    outpin = gpio.1
    gosub dahsub
    gosub dahsub

'M
    outpin = gpio.2
    gosub dahsub
    gosub dahsub
    delayms space
    goto mainloop

'** Subroutines**
DitSub:
high outpin
delayms dit
low outpin
delayms dah
return

DahSub:
high outpin
delayms dah
low outpin
delayms dah
return
...and here's the code for the 12F1572 that does NOT work:
    Device  12F1572
    Xtal 4
    Reminders off

'-------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, BOREN_ON, CLKOUTEN_OFF
Config2 WRT_OFF, PLLEN_OFF, STVREN_OFF, BORV_HI, LPBOREN_OFF, LVP_OFF

'**** End of Fuse Configurator Settings ****
'-------------------------------------------------------------------------------
     Reminders On

  osccon = %01101010  '4Mhz internal osc

    lata = %11000000
     trisa = 0            'all pins output
     ANSELa = 0           'all pins digital
     declare all_digital = true

'** Declare constants **
    symbol Dit = 100    'DIT time (milliseconds) THIS SETS THE SPEED
    Symbol Dah = dit * 3  'DAH time
    Symbol Space = dit * 7 'pause between words

'** Declare aliases **
   Dim OutPin as pin

   lata = 0   'set all pins to zero
   DelayMS 1000 'wait a bit before starting

Mainloop:
'R
    OutPin = lata.0
    gosub ditsub
    gosub dahsub
    gosub ditsub

'M
    outpin = lata.1
    gosub dahsub
    gosub dahsub

'M
    outpin = LATa.2
    gosub dahsub
    gosub dahsub
    delayms space
    goto mainloop

'** Subroutines**
DitSub:
high outpin
delayms dit
low outpin
delayms dah
return

Can anyone help me spot the problem?

Thanks!

-Rick

midali

Try with this config :

Device = 12F1572
       Config1 FOSC_INTOSC ,WDTE_OFF,PWRTE_ON,MCLRE_OFF ,CP_OFF,BOREN_OFF,CLKOUTEN_OFF
       Config2 WRT_OFF ,PLLEN_OFF ,STVREN_OFF,BORV_LO,LPBOREN_OFF ,LVP_OFF
       
OSCCON = %01101010
Declare Xtal = 4

rick.curl

Hi Midali-
I tried changing the config fuses as you suggested, but it did not make a difference.

I don't think the problem is with the config fuses, because when I add the "testloop" code I can blink an LED.

Thanks for the suggestion, though.

-Rick

rick.curl

I rewrote the code and removed all instances of "Dim OutPin as pin" and it's working fine now.
Here's my working code:
    Device  12F1572
    declare Xtal 4
    Reminders off

'-------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, BOREN_ON, CLKOUTEN_OFF
Config2 WRT_OFF, PLLEN_OFF, STVREN_OFF, BORV_HI, LPBOREN_OFF, LVP_OFF

'**** End of Fuse Configurator Settings ****
'-------------------------------------------------------------------------------
     Reminders On

  osccon = %01101010  '4Mhz internal osc

    lata = %11000000
     trisa = 0            'all pins output
     ANSELa = 0           'all pins digital
     declare all_digital = true

'** Declare constants **
    symbol Dit = 100    'DIT time (milliseconds) THIS SETS THE SPEED
    Symbol Dah = dit * 3  'DAH time
    Symbol Space = dit * 7 'pause between words

   lata = 0   'set all pins to zero
   DelayMS 1000 'wait a bit before starting

Mainloop:

'R -LED 0
  high lata.0 'dit
  delayms dit
  low lata.0
  delayms dah

  high lata.0  'dah
  delayms dah
  low lata.0
  delayms dah

  high lata.0 'dit
  delayms dit
  low lata.0
  delayms dah

'M - LED1
  high lata.1  'dah
  delayms dah
  low lata.1
  delayms dah

  high lata.1  'dah
  delayms dah
  low lata.1
  delayms dah

'M - LED2
  high lata.2  'dah
  delayms dah
  low lata.2
  delayms dah

  high lata.2  'dah
  delayms dah
  low lata.2
  delayms dah

  goto mainloop

...so it appears that the problem is with "Dim OutpIn as pin" but only on the 12F1572.

-Rick

HAL

Hi Rick

The first post of the 12f1572 code looks like it is missing the "dah" subroutine.
The copy and paste may have missed the end of the program.

The second post of the 12f1572 code compiles fine on my W7 laptop.

Best regards
Hal

rick.curl

Quote from: HAL on Nov 27, 2022, 02:40 AMHi Rick

The first post of the 12f1572 code looks like it is missing the "dah" subroutine.
The copy and paste may have missed the end of the program.

The second post of the 12f1572 code compiles fine on my W7 laptop.

Best regards
Hal
Yep- I failed to copy the "dah" subroutine.
The code always compiles without error- It just doesn't work.

I am convinced that the problem is with the "dim OutPin as pin" statement, but only on the PIC12F1572. I'll try to narrow it down to a small snippet of code and will post it as an anomaly.
-Rick

HAL

Hi Rick
 I should give up posting while watching football.
 I completely missed the point... 
 But TEXAS A and M won!  It's been a tough year for them and us fans..
 Just received some 12F1572 uC's after nearly a year and will be looking out
 for the issue with "dim OutPin as pin" statement. 
Thanks and dahdahdididit dididitdahdah...
HAL