My solar tracker code/circuit problems

Discussion in 'The Projects Forum' started by poxkix, Nov 30, 2011.

  1. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    My problem:
    When the actual circuit is powered on, it works fine. I can rotate the motor clockwise/counter then after a few instances the circuit freezes and also the display at the lcd. Is there something wrong with my code and circuit?

    Another problem, the motor will only stop if the ldr is in dark mode, other than that the motor will just continue until either of the ldr has the higher value then it will rotate that way.

    Another, the motor moves from east to west. How can I make the motor move back to east?

    For the circuit please see attached file. Purpose of the circuit is just for connection references.

    Code ( (Unknown Language)):
    1. [B]char strWest[10];
    2. char strEast[10];
    3. int west;
    4. int east;
    5.  
    6. void main() {
    7.   ADCON1 = 0x80;
    8.   TRISA = 0xFF;
    9.   TRISB = 0x00;
    10.   TRISC = 0x00;
    11.  
    12.   Lcd_Init(&PORTB);
    13.   Lcd_Cmd(Lcd_CLEAR);
    14.   Lcd_Cmd(Lcd_CURSOR_OFF);
    15.  
    16.   do {
    17.              west = Adc_Read(0);
    18.              east = Adc_Read(1);
    19.              IntToStr(west,strWest);
    20.              IntToStr(east,strEast);
    21.              Lcd_Out(1,1,"WEST:");
    22.              Lcd_Out(1, 6, strWest);
    23.              Lcd_Out(2,1,"EAST:");
    24.              Lcd_Out(2,6,strEast);
    25.              
    26.              if(west > east) {
    27.                           PORTC.F0 = 1;
    28.                           PORTC.F1 = 0;
    29.              }else if(east > west) {
    30.                           PORTC.F0 = 0;
    31.                           PORTC.F1 = 1;
    32.              }else if(west == east){
    33.                           PORTC.F0 = 0;
    34.                           PORTC.F1 = 0;
    35.              }
    36.   }while(1);
    37. }[/B]
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Do you have a 10k pull-up resistor on MCLR?

    Do you have the WDT and reset off?

    I don't see your PICs' power pins, but you need to have a bypass capacitor (0.1uF/100nF) across them. It's a good idea to have a larger electrolytic cap in the close vicinity, too.

    You may be picking up noise from the operation of the motor, particularly if the wires for the LDRs run in parallel to the motor wiring.

    Showing how your board is laid out would be a help.
     
  3. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    Oh sorry, I didn't include the 10k pull-up. In my circuit I have.

    What do you mean?
    Do you have the WDT and reset off?

    I have attached the images of my circuit. I hope it is enough. I have a bad camera
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,355
    No, the camera is not bad. Take photos in bright sunlight and position the camera about 2 feet away. Brace the camera on something solid or use a tripod.
     
  5. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    Thanks for that. Do you know what is the problem with the posts above?
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,355
    Do you mean problems with the poor photography or problems with the poor electronics?
     
  7. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    uhm yah you can say that. About the circuit
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,355
    OK, here goes.

    1. Try and keep your wires short and tidy. Do not make the wires longer than needed.

    2. Follow SgtWookies instructions. Remember, he's an EXPERT.
    Connect 10K at pin 1 to VCC.
    I don't see any 0.1uF and 10uF capacitors on your board.

    3. Put 0.1uF across the motor.
     
  9. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Can you post the code for your readADC functions?

    Instead of the string of if/else, I'd suggest using a switch/case with a default for "something odd happened" to display on LCD.

    While debugging, put the raw ADC values on the other side of the screen so you can narrow down exactly what makes it stop updating.

    Do you have a bypass cap between Vss and Vdd? Spurious noise with long wires will cause a processor to hang once in a while.

    If you can narrow it down to "if I do this, it does that", you need to look at your code where an assumption was made related to that, and un-assume it.

    To move the motor in both directions, you need to power it via H-Bridge.
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You should have it on there.

    Here, have a look at this tutorial:
    http://www.gooligum.com.au/tutorials/midrange/PIC_Mid_C_5.pdf
    It covers midrange PIC options for Assembler and HI-TECH C that comes with MPLAB.

    I forgot to mention the brown-out detection; this also could be causing problems.
    Actually, the best lighting you can get is outdoors on an overcast day; the lighting is very even with no harsh shadows. Bright sun or using a flash causes very "contrasty" photos, where the details can't be picked out.

    You need to be far enough away from the items you are taking photos of in order for your camera lens to be properly focused. If you have the options, set the camera to have a higher F-stop with a longer exposure time; and rest the camera on something or use a tripod when taking the photos.
     
  11. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    Yes, I have 10k pull-up on MCLR.
    About WDT, I have to research about that. Especially the only language I'm familiar with is using MikroC.

    Powers pins, meaning the VDD? So I'll connect the positive side of the CAP to the VDD pin and the other to the ground right?

    Okay, I will rewire my circuit to shorten the wires. I just did it that way since it is still on prototype.
    Yes, I have already 10k on pin 1

    The code I posted is the only one I have or are you looking for a specific code?
    Switch/case, I can't get the right algorithm in using that code. Can you give me a sample? I find it more easier if it was if/else.
    What the lcd is displaying is the raw ADC values, I converted it to string since the lcd won't display integers. Or so I might think

    I checked the tutorial I find it a bit baffling since I'm only familiar with MikroC
    Okay, I'll search about that brown-out detection, so I should turn that off too?
     
  12. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    I also made a circuit of H - bridge but I cannot get it to work. My motor power source should be 24v. The H - bridge I made only works for 12v.
    Wanna see it?
     
  13. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Ok, add to the end of your if/then, after all the other tests:

    else
    {
    LCDOut(1,1,"Something went Wrong");
    }

    Yes, please show diagram for H-Bridge

    You may be running into the same problem with ADC Values as another member is in This Thread.

    Make east and west unsigned int instead of int, not sure if it will help, but it will be more clear as to what can be stored in them if a glitch occurs.
     
  14. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    Okay, I'll rewrite my code add this one. Thanks.

    I think the ADC values for me has no problems. The value being read from the ldr is being displayed on the LCD though the circuit/lcd freezes. I can't test the circuit right now because I need to buy the cap needed.

    Attachment for the H- Bridge I made
     
  15. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,355
    You guys have given me an idea... and a challenge.

    (This is not a hijack... but the mods could start a new thread if they wish.)

    There is a 10,000 Year Clock now on display at the Science Museum in London, England.

    http://longnow.org/

    The idea of The Long Now Foundation is the brainchild of Danny Hills, inventor extraordinaire and contributor at the Whole Earth Catalog.

    The principle behind the Long Now Clock is to design and build a clock that will last for a very very long time, using readily available materials, self powered and self correcting. It corrects its time by taking information from the sun.

    Now, for the past year I have been wanting to build this but I was going to relax the rules. I was going to use solar powered MCU, LCD display and a sun tracker to do the resetting. I still want to do this.

    I extend this challenge to members of AAC.
     
  16. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Can't we all just chip in for a Really HUGE UPS for WWVB?


    To OP: I'll wait to have somebody else look over your H-Bridge, does it function?
     
  17. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,355
    That's strange. A thread on solar tracking just disappeared. Where did it go? I though I posted the 10,000 Year Clock in that thread. Did I get moved?
     
  18. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Scroll up about 2 posts?
     
  19. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    It function if it is supplied for 12v, if I adjust the supply to 24v it will not work. I need a 24v supply.

    By the way, the logics are used to replace the MCU.
     
  20. poxkix

    Thread Starter Member

    Nov 28, 2011
    42
    0
    Sorry for this double post but I have to, it is already 3am here and I need to finish this solar tracker:(

    I revised the code, the revised code's purpose was suppose the make the motor turn for a certain amount of time only but for a millionth time I just can't do it. Please help the noob.

    The 64 there is a value coming from the potentiometer input in the adc channel 0.

    Code ( (Unknown Language)):
    1. char strWest[10];
    2. char strEast[10];
    3. int west;
    4. int east;
    5. int cnt;
    6.  
    7. void main() {
    8.   ADCON1 = 0x80;
    9.   TRISA = 0xFF;
    10.   TRISB = 0x00;
    11.   TRISC = 0x00;
    12.  
    13.   Lcd_Init(&PORTB);
    14.   Lcd_Cmd(Lcd_CLEAR);
    15.   Lcd_Cmd(Lcd_CURSOR_OFF);
    16.  
    17.   do {
    18.              west = Adc_Read(0);
    19.              east = Adc_Read(1);
    20.              IntToStr(west,strWest);
    21.              IntToStr(east,strEast);
    22.              Lcd_Out(1,1,"WEST:");
    23.              Lcd_Out(1, 6, strWest);
    24.              Lcd_Out(2,1,"EAST:");
    25.              Lcd_Out(2,6,strEast);
    26.  
    27.              if(west == 64 && east < west) {
    28.                      for(cnt=0;cnt<=5;cnt++) {
    29.                         delay_ms(1000);
    30.                         PORTC.F0 = 1;
    31.                         PORTC.F1 = 0;
    32.                      }
    33.                           PORTC.F0 = 0;
    34.                           PORTC.F1 = 0;
    35.              }else if(east > west) {
    36.                           PORTC.F0 = 0;
    37.                           PORTC.F1 = 1;
    38.              }else if(west == east){
    39.                           PORTC.F0 = 0;
    40.                           PORTC.F1 = 0;
    41.              }
    42.   }while(1);
    43. }
     
Loading...