Announcement

Collapse
No announcement yet.

PIC16F1825 INTOSC and DAC MCP4725A0T Help with coding, I am lost

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PIC16F1825 INTOSC and DAC MCP4725A0T Help with coding, I am lost

    Can someone give me an idea where I'm going wrong please ?

    ' DESCRIPTION

    ' Counter firmware to measure frequency of pulses for flow meter
    ' Micro - PICAXE-14M2 to PIC16F1825
    ' INPUTS - Counter input on C.4. Counts for 100 msec
    ' INPUTS - pull up switch to set up high/low range ( not implemented)
    ' OUTPUTS - SDA/SCL to 12 bit DAC
    ' OUTPUTS - led on b.2 to indicate overrange
    ' Currently set to 3000 rpm

    DEFINE I2C_SLOW 1


    CounterIn var PORTA.4
    OverRange var PORTA.2
    CounterValue var word
    w1 var word
    CountTime var word
    w3 var word
    DACValue var word
    w4 var word
    RangeSwitch var PORTA.1
    Multiplier var word
    w12 var word

    SDA var PORTC.1
    SCL var PORTC.0
    Addr var byte



    CountTtime CON 1000

    Multiplier = 3 ' .3 cc/pulse - multipled by 10
    ' Read set up range switch read on turn on

    if PORTA.1 = 1 then
    Multiplier = 81
    else
    Multiplier = 160
    endif

    start:
    count CounterIn, CountTime, CounterValue ' count pulses in 1secs (at 4MHz)
    w4=CounterValue * Multiplier * 60 ' cc per minute

    if w4 > 4096 then ' check over range and stop at 4096
    high OverRange
    w4 = 4096
    else
    low OverRange
    endif

    DACValue = w4
    Addr = 2 '$02 = DEC 2

    I2CWRITE SDA, SCL, $A0, Addr, DacValue

    'I2CWRITE PORTC.1,PORTC.0,Control,$02,b9,b8
    goto start

  • #2
    It would help if you told us what the problem is.

    Does the PIC run?
    Does it run at the frequency you expect?
    There's no CONFIG block in your code and you don't write to OSCCON so how do you know the PIC is running on the internal oscillator?

    There's no setup code for the port pins. Both PORTA and PORTC has analog functions turned on by default which needs to be turned OFF (see datasheet, ANSELx register).

    Make sure you can blink a LED at a desired frequency using the pins you then aim to use as your I2C pins. When that works make sure you can Control that LED using the pin you aim to use as your Count input. When that works get the COUNT command working, and when THAT works start focusing on the DAC.

    Finally, the DAC is 12bits, the value it can receive is between 0 and 4095 while you're clamping at >4096.

    /Henrik.

    Comment

    Working...
    X