1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Adding A/Ds to 12F683 in Oshonsoft

Discussion in 'Oshonsoft' started by camerart, Jan 29, 2014.

  1. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi camerart,
    No post mail today.:(
    Just ordered 6 off, 12F683 PIC's, expected mid week.

    When done, I will post two programmed PIC's to you, FOC,, send me your address by Conversation

    Eric
     
  2. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi camerart,
    This works OK, in a 12F683 I have purchased.

    The LED associated with the ADC input lights when when the Vadc > 0.3V [ 100 counts] and goes dark when less than 100 ADC counts.

    Please modify this code listing to include the extra commands/functions that are causing problems. post it and I will continue debugging.

    Eric


    Code (text):

    'Timer Test V1.0 Camerart 12.02.14

    'Uses 12f683, internal 4mHz clock

    'Define SIMULATION_WAITMS_VALUE = 1  'SIMULATION ONLY

    Define CONF_WORD = %11001111000100  '0x33c4


    Dim an0 As Word  'setting an0 as WORD length makes ADC count =1023 max
    Dim an1 As Word  'if set as BYTE length makes ADC count =255 max
    Dim t As Word  't = Ticks counter, incremented on INTERRUPT
    Dim firstpulse As Byte  'Check Byte or word
    Dim secondpulse As Byte

    Symbol rled = GP2  'LED's
    Symbol gled = GP5

    OSCCON = %01100000  'Internal 4MHz osc
    CMCON0 = %00000111  '7  'Comparators off
    WPU = 0  'Internal pull-ups = off

    OPTION_REG = %10000000  'Pull ups, TMR0, Prescaler
    INTCON = %10000000  'Timer interrupt bits
    ANSEL = %01000011  '0x03  '0-3 Selecting pins Analogue Digital 6 Fosc/4
    ADCON0 = %00000101  'A/D 0x85?



    '[in theory ALL these should start up as '0' at power ON
    'but its wise to ensure that they are!]
    PIE1 = 0  'peripheral intr disable
    INTCON.INTE = 0
    INTCON.T0IF = 0
    PIE1.TMR1IE = 0  'Disable Timer 1 Overflow Interrupt
    PIR1.TMR1IF = 0  'Clear Timer 1 Overflow Interrupt Flag

    'set I/O pin direction
    '(TRISIO = %XX001011) [ list pins in same order as binary bits]
    TRISIO.5 = 0  'PIN 5 as gled
    TRISIO.4 = 0  'PIN 4 unused
    TRISIO.3 = 1  'PIN 5 as Button input (IN ONLY)
    TRISIO.2 = 0  'PIN 5 as rled
    TRISIO.1 = 1  'PIN 6 as analog1
    TRISIO.0 = 1  'PIN 7 as analog0


    'START UP FLASH Red then Gn LED
    rled = 1
    WaitMs 1000
    rled = 0
    WaitMs 1000
    gled = 1
    WaitMs 1000
    gled = 0
    WaitMs 1000

    'preload tmr1 0.5sec count
    TMR1L = %11011100  'L + H = decimal 65536-62500=3036] = 8uSec*62500 = 0.5Sec==Count up from 3036 decimal To 65536
    TMR1H = %00001011  '='Then roll over To 0000 Count And generate an Interrupt every 0.5sec
    T1CON = %00110001  'prescale 8:1, internal clock, start tmr1
    PIE1.TMR1IE = 1  'all start up done so Enable Timer 1 Interrupt


    loop:
    Adcin 0, an0  'read ADC0 Sets first pulse
    Adcin 1, an1  'read ADC1 Sets second pulse


    If an0 >= 100 Then  'if ADC0 counter => 100 then......
    rled = 1  'ON IN SIMULATOR = OFF
    firstpulse = an0
    WaitMs an0  'this pulse duration is an0 millisec long
    firstpulse = 0
    Else
    rled = 0  'OFF IN SIMULATOR = ON
    Endif

    If an1 >= 100 Then
    gled = 1  'ON IN SIMULATOR = OFF
    secondpulse = an1
    WaitMs an1
    secondpulse = 0
    Else
    gled = 0  'OFF IN SIMULATOR = ON
    Endif


    Goto loop
    End                                            
    On Interrupt
    Save System

    'on this test the ISR is only a dummy call
    PIR1.TMR1IF = 0  'must clear tmr1 intr

    'must reload tmr1 0.5sec count
    TMR1L = %11011100  'L + H = decimal 65536-62500=3036] = 8uSec*62500 = 0.5Sec==Count up from 3036 decimal To 65536
    TMR1H = %00001011  '='Then roll over To 0000 Count And generate an Interrupt every 0.5sec

    Resume                  
     
  3. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,

    The simulation works ok.

    In circuit, when AN0 >= 100 then RLED switches on, then GLED flashes ON/OFF, and if AN0 <=100 RLED goes OFF.
    AN1 switches GLED ON/OFF correctly.

    Camerart
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE

    hi,
    Are you able to post the program code you want me to test in a PIC.?
    Eric

    EDIT:
    In the code I have posted , tested in a PIC, the two LED's do not interact at all, they work as expected,

    No flashing On and Off, just Steady when they are > 100
     
  6. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,

    I have only tried the last code that you posted.

    BUT!! since then, I tried changing the line with 'WaitMs AN0' to 'WaitMs firstpulse' to see if it changed anything. The 'Start up flashes' went back to a momentary flash instead of 1 second for each LED. I then tried your last code again and it now has the same problem.

    Could the fault be with more my programmer than the code?

    Camerart.
     
  7. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    UPDATE: I tried the original procedure of cutting your #62 code and pasting into a NEW Oshonsoft simulation then compiled it as usual, and it works as #63.
     
  8. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    To double check, I have added the TMR1 interrupt to the program I posted to you, it works OK.

    To show it working I have added a Blue LED on GP4 to see it flash On/Off at 0.5secs,,, its all working as I would expect, no interaction between the LED's.

    Could you post a photo of your layout so that I can check its OK.?

    Eric
     
  9. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,

    I've had various results, that aren't constant, while programming, also while testing.

    Here is a video of the last in circuit test:

    You will see that when it is first switched on, both LEDs go on.
    Later when I was turning the AN0 voltage up, at first the second led GLED does not go on, this is at around 1/2Volt. If I turn the pot quicker, to perhaps 1Volt, then the second GLED goes on/off.

    P.S. While on Youtube, have a look at the Spot welder test I posted. The circuit we are working on is for accurate timing of the welder.

    Camerart.
     
  10. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    Watched the vid.

    I would recommend that you have at least a 100nF and a 47uF capacitor across the 0v and +5V supply as close as possible to the PIC.

    Also any loose connections will give unpredictable results.
    E

    EDIT:

    I dont see a wire in pin #6 of the PIC.??, is it floating.??
     
    Last edited: Feb 13, 2014
  11. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    Hi E,
    I have put a 100nF and a 100uF (no 47uF) caps across power.
    PIN #6 is AO1, and I just move the wire across from AO0 for testing. I have also tried it in the circuit, that has two POTs,with the same results.

    I am now convinced that there is something wrong with the programmer. Using two PICs, and using the code from #62 and a simple flash code :
    TRISIO = %00000100
    WaitMs 1000
    GP5 = 1
    WaitMs 1000
    GP5 = 0
    WaitMs 1000
    End

    After spending an hour writing, reading and verifying, and getting incorrect results.
    Now #62 code (that programmed ok, and is shown in the video) does not work (same old, no proper start up flashes) but the flash code does work.

    Which PIC programmer do you have?

    UPDATE: I failed numerous times to get the saved #62 code to work, then I tried shutting everything down, copying #62 from the forum page again and pasted it into a NEW oshonsoft code, compiled it and it works as the vid again.

    Camerart.
     
    Last edited: Feb 13, 2014
  12. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    I use the PICStart+.

    Import the Oshonsoft hex file into MPLAB IDE, ensure that the Configuration Bits are set correctly in MPLAB

    Select the PICStart prommer in the MPLAB, Enable the Prommer then Program, wait until successful message.

    What method do you you use.?

    When I pick up your 12F683 tomorrow are they already programmed with your system.?
    E
     
  13. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    I'm not sure I can justify the expense of your programming system, but I'll keep it in mind.

    I compile and load the BAS. then open PICKIT2 and it shows in the HEX list, then program and wait for successful message.

    I'm wondering if the problem is staring me in the face!! For the 12F683, I had to make a 'piggy back' socket for the Programmer, as they are wired differently. Also the wires between programmer and chip socket is about 6 inches. I'll make a shorter neater socket, then re-try.

    The chips I posted are new, but I think one might have a 'new chip' test on it. Not sure which code though.

    Camerart.
     
  14. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi
    I will preprogram the 2 I send back to you
     
  15. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,

    That sounds good.

    This program is to help me learn a bit more about programming, as I've decided to stay with this, perhaps not quite the latest system.

    Ultimately it will be a spot welder timer. On the circuit board is 1xLED and 1xMOSFET (2xLEDs at the moment). AN0 sets the first burst of current ('say' 100MS) then AN1 sets the second burst of current (similar to first) GP3 starts the 2x bursts. Perhaps you could program 1x PIC with the existing code and 1x with the finished code once working?

    Camerart.
     
  16. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi.
    That sounds OK to me, post here your final tested code and I will test and program the 2nd PIC.
    E
     
  17. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,

    I wired a new ZIF socket, with shorter leads, but no difference:(

    I was looking at the code on #62. It in order that in Oshonsoft LINE19 'osccon' and other variables below it, are lower case and black, and haven't 'come alive' in the same way that INTCON has?

    Cheers, Camerart.
     
  18. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    I have just opened #62 code and this is an image of what I see in OS, looks OK.

    Can you post a screen image of what you see.?

    Eric
     

    Attached Files:

  19. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,179
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    In case you have a corrupted copy of the program, its here as an attachment.
    E
     

    Attached Files:

  20. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    Attached screen shot of 'copy16.bas'

    :rolleyes:Just noticed!! After checking the new ZIF socket with 8PIN and 18 PIN PICs I had left the 18 PIN by mistake. That solved it, sorry.

    Camerart
     

    Attached Files:

    Last edited: Feb 14, 2014
  21. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,315
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,

    All's well. I've changed the code to be a spot welder driver code attached:

    It's working on the bench with a LED and a motor as a load, instead of LED and welding probes. I now need to make the probes, and alter the timings to suit.

    Later once it has proved to be ok, I'll change the timings to be controlled by interrupts, instead of WAITMS.

    I think my programmer has become more reliable, since shortening the leads, and adding the ZIF, so I think you can keep the 12F683,s

    Thanks a lot for you guidance, don't go away:)

    Cheers, Camerart.
     

    Attached Files:

Share This Page