Using condition on ADC and send using UART

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Galile
Posts: 16
Joined: 25 Apr 2009 11:00

Using condition on ADC and send using UART

#1 Post by Galile » 25 Apr 2009 11:13

Hey i have a problem well i need to put some condition or threeshold when ADC convert data soo that when the ADC is bigger than threshold the value is sent thru serial port and if it else the number of threshold is sent serialy this is the code it compile but i don't see result on serial port btw i'm using easydspic 4 woth dspic 30f4013

Code: Select all

 program ADC
dim adcRes as word
    txt    as string[6]
    txt1    as string[6]

main:
  TRISB.1  = 1  ' set pin as input - needed for ADC to work

  Uart1_Init(9600)

  while true
    adcRes = Adc_Read(1)
    if (adcRes>600) then
    WordToStr(adcRes, txt)
    Uart1_Write_Text(txt)
    Delay_ms(50)
    else
    adcRes=600
    WordToStr(adcRes, txt1)
    Uart1_Write_Text(txt1)
    end if
  wend
  end.

Skyline
Posts: 267
Joined: 10 Jan 2006 09:35

Re: Using condition on ADC and send using UART

#2 Post by Skyline » 25 Apr 2009 16:42

Hi,

Tested your program, works exactly as you wanted it to do. I added a delay statement to the "else" condition, but it shouldn't impact on the program execution.

Code: Select all

 program ADC
dim adcRes as word
    txt    as string[6]
    txt1    as string[6]

main:
  TRISB.1  = 1  ' set pin as input - needed for ADC to work

  Uart1_Init(9600)

  while true
    adcRes = Adc_Read(1)
    if (adcRes>600) then
    WordToStr(adcRes, txt)
    Uart1_Write_Text(txt)
    Delay_ms(50)
    else
    adcRes=600
    WordToStr(adcRes, txt1)
    Uart1_Write_Text(txt1)
    Delay_ms(50)
    end if
  wend
  end.
Can you describe your device flag settings under "Edit Project"? What is the clock frequency in your project setting?

Galile
Posts: 16
Joined: 25 Apr 2009 11:00

#3 Post by Galile » 26 Apr 2009 18:48

well i'm usig xt-pll*8, 10mhz clock and the program is compiled but look what i get on the terminal
Received: ëë
Received: èø
Received: èé
Received: ëë
Received: ëë
Received: èø
Received: èé
Received: ë
Received: û
Received: ë

Galile
Posts: 16
Joined: 25 Apr 2009 11:00

#4 Post by Galile » 26 Apr 2009 19:33

i used only the default setting on device flags like watchdog off and all default settings,and also i checked to baud rate stuff and it's all right

Skyline
Posts: 267
Joined: 10 Jan 2006 09:35

#5 Post by Skyline » 27 Apr 2009 01:54

Hi,

If the crystal is 10MHz and the device flag settings are default and clock is xt-pll*8, then the 4013 is running at 80MHz clock.

The "Clock" setting of "Edit Project" would need to be set to 80MHz, can you have a look at this item?

Galile
Posts: 16
Joined: 25 Apr 2009 11:00

#6 Post by Galile » 27 Apr 2009 21:04

ahh mann thx alott it workeddd and now i'll move to the next step when i face for sure alot of problems am gonna need for ur help but for now thx for this

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”